backend tests: Add 'AARON' as bot owner of OUTGOING_WEBHOOK_BOT.

This commit is contained in:
Robert Hönig
2017-09-26 11:34:31 +02:00
committed by Tim Abbott
parent 8a8d1410f8
commit c77b245944
3 changed files with 10 additions and 8 deletions

View File

@@ -6,8 +6,8 @@ from zerver.models import Realm, Stream, UserProfile, Huddle, \
Subscription, Recipient, Client, RealmAuditLog, get_huddle_hash Subscription, Recipient, Client, RealmAuditLog, get_huddle_hash
from zerver.lib.create_user import create_user_profile from zerver.lib.create_user import create_user_profile
def bulk_create_users(realm, users_raw, bot_type=None, tos_version=None, timezone=u""): def bulk_create_users(realm, users_raw, bot_type=None, bot_owner=None, tos_version=None, timezone=u""):
# type: (Realm, Set[Tuple[Text, Text, Text, bool]], Optional[int], Optional[Text], Text) -> None # type: (Realm, Set[Tuple[Text, Text, Text, bool]], Optional[int], Optional[UserProfile], Optional[Text], Text) -> None
""" """
Creates and saves a UserProfile with the given email. Creates and saves a UserProfile with the given email.
Has some code based off of UserManage.create_user, but doesn't .save() Has some code based off of UserManage.create_user, but doesn't .save()
@@ -20,7 +20,7 @@ def bulk_create_users(realm, users_raw, bot_type=None, tos_version=None, timezon
for (email, full_name, short_name, active) in users: for (email, full_name, short_name, active) in users:
profile = create_user_profile(realm, email, profile = create_user_profile(realm, email,
initial_password(email), active, bot_type, initial_password(email), active, bot_type,
full_name, short_name, None, False, tos_version, full_name, short_name, bot_owner, False, tos_version,
timezone, tutorial_status=UserProfile.TUTORIAL_FINISHED, timezone, tutorial_status=UserProfile.TUTORIAL_FINISHED,
enter_sends=True) enter_sends=True)
profiles_to_create.append(profile) profiles_to_create.append(profile)

View File

@@ -227,6 +227,7 @@ class ZulipTestCase(TestCase):
aaron=u'aaron@zulip.com', aaron=u'aaron@zulip.com',
ZOE=u'ZOE@zulip.com', ZOE=u'ZOE@zulip.com',
webhook_bot=u'webhook-bot@zulip.com', webhook_bot=u'webhook-bot@zulip.com',
outgoing_webhook_bot=u'outgoing-webhook@zulip.com'
) )
mit_user_map = dict( mit_user_map = dict(

View File

@@ -25,7 +25,7 @@ import os
import ujson import ujson
import itertools import itertools
from six.moves import range from six.moves import range
from typing import Any, Callable, Dict, List, Iterable, Mapping, Sequence, Set, Tuple, Text from typing import Any, Callable, Dict, List, Iterable, Mapping, Optional, Sequence, Set, Tuple, Text
settings.TORNADO_SERVER = None settings.TORNADO_SERVER = None
# Disable using memcached caches to avoid 'unsupported pickle # Disable using memcached caches to avoid 'unsupported pickle
@@ -35,14 +35,14 @@ settings.CACHES['default'] = {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache' 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
} }
def create_users(realm, name_list, bot_type=None): def create_users(realm, name_list, bot_type=None, bot_owner=None):
# type: (Realm, Iterable[Tuple[Text, Text]], int) -> None # type: (Realm, Iterable[Tuple[Text, Text]], Optional[int], Optional[UserProfile]) -> None
user_set = set() # type: Set[Tuple[Text, Text, Text, bool]] user_set = set() # type: Set[Tuple[Text, Text, Text, bool]]
for full_name, email in name_list: for full_name, email in name_list:
short_name = email_to_username(email) short_name = email_to_username(email)
user_set.add((email, full_name, short_name, True)) user_set.add((email, full_name, short_name, True))
tos_version = settings.TOS_VERSION if bot_type is None else 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) bulk_create_users(realm, user_set, bot_type=bot_type, bot_owner=bot_owner, tos_version=tos_version)
class Command(BaseCommand): class Command(BaseCommand):
help = "Populate a test database" help = "Populate a test database"
@@ -294,8 +294,9 @@ class Command(BaseCommand):
zulip_outgoing_bots = [ zulip_outgoing_bots = [
("Outgoing Webhook", "outgoing-webhook@zulip.com") ("Outgoing Webhook", "outgoing-webhook@zulip.com")
] ]
aaron = get_user("AARON@zulip.com", zulip_realm)
create_users(zulip_realm, zulip_outgoing_bots, create_users(zulip_realm, zulip_outgoing_bots,
bot_type=UserProfile.OUTGOING_WEBHOOK_BOT) bot_type=UserProfile.OUTGOING_WEBHOOK_BOT, bot_owner=aaron)
# TODO: Clean up this initial bot creation code # TODO: Clean up this initial bot creation code
Service.objects.create( Service.objects.create(
name="test", name="test",