test: Use example_user() in more places.

This commit replaces calls to get_user_profile_by_email() with
calls to self.example_user() by introducing a local variable.
This commit is contained in:
Steve Howell
2017-05-08 07:23:43 -07:00
committed by Tim Abbott
parent 7f9057ba99
commit 3a031f6814
4 changed files with 27 additions and 18 deletions

View File

@@ -381,8 +381,9 @@ class AuthBackendTest(ZulipTestCase):
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.GitHubAuthBackend',))
def test_github_backend(self):
# type: () -> None
email = 'hamlet@zulip.com'
self.setup_subdomain(get_user_profile_by_email(email))
user = self.example_user('hamlet')
email = user.email
self.setup_subdomain(user)
good_kwargs = dict(response=dict(email=email), return_data=dict(),
realm_subdomain='acme')
self.verify_backend(GitHubAuthBackend(),

View File

@@ -800,10 +800,11 @@ class SubscriptionPropertiesTest(ZulipTestCase):
A POST request to /json/subscriptions/property with stream_name and
color data sets the stream color, and for that stream only.
"""
test_email = "hamlet@zulip.com"
test_user = self.example_user('hamlet')
test_email = test_user.email
self.login(test_email)
old_subs, _ = gather_subscriptions(get_user_profile_by_email(test_email))
old_subs, _ = gather_subscriptions(test_user)
sub = old_subs[0]
stream_name = sub['name']
new_color = "#ffffff" # TODO: ensure that this is different from old_color
@@ -871,9 +872,10 @@ class SubscriptionPropertiesTest(ZulipTestCase):
Called by invalid request method. No other request method other than
'post' is allowed in this case.
"""
test_email = "hamlet@zulip.com"
test_user = self.example_user('hamlet')
test_email = test_user.email
self.login(test_email)
subs = gather_subscriptions(get_user_profile_by_email(test_email))[0]
subs = gather_subscriptions(test_user)[0]
result = self.client_get(
"/json/subscriptions/property",
@@ -887,9 +889,10 @@ class SubscriptionPropertiesTest(ZulipTestCase):
"""
Updating the color property requires a color.
"""
test_email = "hamlet@zulip.com"
test_user = self.example_user('hamlet')
test_email = test_user.email
self.login(test_email)
subs = gather_subscriptions(get_user_profile_by_email(test_email))[0]
subs = gather_subscriptions(test_user)[0]
result = self.client_post(
"/json/subscriptions/property",
{"subscription_data": ujson.dumps([{"property": "color",
@@ -930,9 +933,10 @@ class SubscriptionPropertiesTest(ZulipTestCase):
"""
Trying to set a property incorrectly returns a JSON error.
"""
test_email = "hamlet@zulip.com"
test_user = self.example_user('hamlet')
test_email = test_user.email
self.login(test_email)
subs = gather_subscriptions(get_user_profile_by_email(test_email))[0]
subs = gather_subscriptions(test_user)[0]
property_name = "in_home_view"
result = self.client_post(
@@ -993,9 +997,10 @@ class SubscriptionPropertiesTest(ZulipTestCase):
"""
Trying to set an invalid property returns a JSON error.
"""
test_email = "hamlet@zulip.com"
test_user = self.example_user('hamlet')
test_email = test_user.email
self.login(test_email)
subs = gather_subscriptions(get_user_profile_by_email(test_email))[0]
subs = gather_subscriptions(test_user)[0]
result = self.client_post(
"/json/subscriptions/property",
{"subscription_data": ujson.dumps([{"property": "bad",

View File

@@ -122,9 +122,10 @@ class TypingStartedNotificationTest(ZulipTestCase):
Sending typing notification to yourself
is successful.
"""
email = 'hamlet@zulip.com'
user = self.example_user('hamlet')
email = user.email
expected_recipient_emails = set([email])
expected_recipient_ids = set([get_user_profile_by_email(email).id])
expected_recipient_ids = set([user.id])
events = [] # type: List[Dict[str, Any]]
with tornado_redirected_to_list(events):
result = self.client_post('/api/v1/typing', {'to': email,
@@ -183,9 +184,10 @@ class StoppedTypingNotificationTest(ZulipTestCase):
Sending stopped typing notification to yourself
is successful.
"""
email = 'hamlet@zulip.com'
user = self.example_user('hamlet')
email = user.email
expected_recipient_emails = set([email])
expected_recipient_ids = set([get_user_profile_by_email(email).id])
expected_recipient_ids = set([user.id])
events = [] # type: List[Dict[str, Any]]
with tornado_redirected_to_list(events):

View File

@@ -33,8 +33,9 @@ class PointerTest(ZulipTestCase):
"""
Same as above, but for the API view
"""
email = "hamlet@zulip.com"
self.assertEqual(get_user_profile_by_email(email).pointer, -1)
user = self.example_user('hamlet')
email = user.email
self.assertEqual(user.pointer, -1)
msg_id = self.send_message("othello@zulip.com", "Verona", Recipient.STREAM)
result = self.client_post("/api/v1/users/me/pointer", {"pointer": msg_id},
**self.api_auth(email))