Add a new community realm to our test databases.

The realm with string_id of "simple" just has three users
named alice, bob, and cindy for now.  It is useful for testing
scenarios where realms don't have special zulip.com exception
handling.
This commit is contained in:
Steve Howell 2017-01-26 15:06:55 -08:00 committed by showell
parent bcdd326b65
commit 4be2d6577d
5 changed files with 49 additions and 5 deletions

View File

@ -143,10 +143,16 @@ autofocus('#id_username');
{% for user_email in direct_admins %}
<p><input type="submit" name="direct_email" class="btn-direct btn-admin" value="{{ user_email }}" /></p>
{% endfor %}
<p>({{ _('Normal users') }})</p>
{% for user_email in direct_users %}
<p><input type="submit" name="direct_email" class="btn-direct btn-user" value="{{ user_email }}" /></p>
{% endfor %}
<p>({{ _('Community users') }})</p>
{% for user_email in community_users %}
<p><input type="submit" name="direct_email" class="btn-direct btn-user" value="{{ user_email }}" /></p>
{% endfor %}
</div>
</div>
</form>

View File

@ -895,9 +895,10 @@ class UserSignUpTest(ZulipTestCase):
realm.invite_required = False
realm.save()
realm = get_realm('mit')
do_deactivate_realm(realm)
realm.save()
for string_id in ('simple', 'mit'):
realm = get_realm(string_id)
do_deactivate_realm(realm)
realm.save()
result = self.client_post('/register/', {'email': email})

View File

@ -2296,6 +2296,9 @@ class TestMissedMessages(ZulipTestCase):
class TestOpenRealms(ZulipTestCase):
def test_open_realm_logic(self):
# type: () -> None
realm = get_realm('simple')
do_deactivate_realm(realm)
mit_realm = get_realm("mit")
self.assertEqual(get_unique_open_realm(), None)
mit_realm.restricted_to_domain = False

View File

@ -340,7 +340,12 @@ def login_page(request, **kwargs):
users_query = UserProfile.objects.select_related().filter(is_bot=False, is_active=True)
users = users_query.order_by('email')[0:MAX_DEV_BACKEND_USERS]
extra_context['direct_admins'] = [u.email for u in users if u.is_realm_admin]
extra_context['direct_users'] = [u.email for u in users if not u.is_realm_admin]
extra_context['direct_users'] = [
u.email for u in users
if not u.is_realm_admin and u.realm.string_id == 'zulip']
extra_context['community_users'] = [
u.email for u in users
if u.realm.string_id == 'simple']
template_response = django_login_page(
request, authentication_form=OurAuthenticationForm,
extra_context=extra_context, **kwargs)

View File

@ -35,7 +35,6 @@ def create_users(realm, name_list, bot_type=None):
tos_version = settings.TOS_VERSION if bot_type is None else None
bulk_create_users(realm, user_set, bot_type=bot_type, tos_version=tos_version)
class Command(BaseCommand):
help = "Populate a test database"
@ -243,6 +242,8 @@ class Command(BaseCommand):
]
create_users(zulip_realm, zulip_webhook_bots, bot_type=UserProfile.INCOMING_WEBHOOK_BOT)
create_simple_community_realm()
if not options["test_suite"]:
# Initialize the email gateway bot as an API Super User
email_gateway_bot = UserProfile.objects.get(email__iexact=settings.EMAIL_GATEWAY_BOT)
@ -396,3 +397,31 @@ def send_messages(data):
recipients[num_messages] = (message_type, message.recipient.id, saved_data)
num_messages += 1
return tot_messages
def create_simple_community_realm():
# type: () -> None
simple_realm = Realm.objects.create(
string_id="simple", name="Simple Realm", restricted_to_domain=False,
invite_required=False, org_type=Realm.COMMUNITY, domain="simple.com")
names = [
("alice", "alice@example.com"),
("bob", "bob@foo.edu"),
("cindy", "cindy@foo.tv"),
]
create_users(simple_realm, names)
user_profiles = UserProfile.objects.filter(realm__string_id='simple')
create_user_presences(user_profiles)
def create_user_presences(user_profiles):
# type: (Iterable[UserProfile]) -> None
for user in user_profiles:
status = 1 # type: int
date = now()
client = get_client("website")
UserPresence.objects.get_or_create(
user_profile=user,
client=client,
timestamp=date,
status=status)