populate_db: Include some initial data for custom profile fields.

This is currently only for manual testing; creating these would break
the existing custom profile test suite.
This commit is contained in:
Tim Abbott
2018-03-11 17:51:07 -07:00
parent 02b8453367
commit 56b1239ad5

View File

@@ -12,12 +12,13 @@ from django.utils.timezone import now as timezone_now
from django.utils.timezone import timedelta as timezone_timedelta
from zerver.lib.actions import STREAM_ASSIGNMENT_COLORS, \
do_change_is_admin, do_send_messages
do_change_is_admin, do_send_messages, do_update_user_custom_profile_data, \
try_add_realm_custom_profile_field
from zerver.lib.bulk_create import bulk_create_streams, bulk_create_users
from zerver.lib.generate_test_data import create_test_data
from zerver.lib.upload import upload_backend
from zerver.lib.user_groups import create_user_group
from zerver.models import DefaultStream, Message, Realm, RealmAuditLog, \
from zerver.models import CustomProfileField, DefaultStream, Message, Realm, RealmAuditLog, \
RealmDomain, RealmEmoji, Recipient, Service, Stream, Subscription, \
UserMessage, UserPresence, UserProfile, clear_database, \
email_to_username, get_client, get_huddle, get_realm, get_stream, \
@@ -243,6 +244,28 @@ class Command(BaseCommand):
Subscription.objects.bulk_create(subscriptions_to_add)
RealmAuditLog.objects.bulk_create(all_subscription_logs)
if not options['test_suite']:
# Create custom profile field data
phone_number = try_add_realm_custom_profile_field(zulip_realm, "Phone number",
CustomProfileField.SHORT_TEXT)
biography = try_add_realm_custom_profile_field(zulip_realm, "Biography",
CustomProfileField.LONG_TEXT)
favorite_integer = try_add_realm_custom_profile_field(zulip_realm, "Favorite integer",
CustomProfileField.INTEGER)
# Fill in values for Iago and Hamlet
hamlet = get_user("hamlet@zulip.com", zulip_realm)
do_update_user_custom_profile_data(iago, [
{"id": phone_number.id, "value": "+1-234-567-8901"},
{"id": biography.id, "value": "Betrayer of Othello."},
{"id": favorite_integer.id, "value": 17},
])
do_update_user_custom_profile_data(hamlet, [
{"id": phone_number.id, "value": "+0-11-23-456-7890"},
{"id": biography.id, "value": "Prince of Denmark, and other things!"},
{"id": favorite_integer.id, "value": 12},
])
else:
zulip_realm = get_realm("zulip")
recipient_streams = [klass.type_id for klass in