diff --git a/zerver/tests/test_alert_words.py b/zerver/tests/test_alert_words.py
index bb477e2d31..964b853480 100644
--- a/zerver/tests/test_alert_words.py
+++ b/zerver/tests/test_alert_words.py
@@ -109,7 +109,7 @@ class AlertWordTests(ZulipTestCase):
def test_json_list_default(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_get('/json/users/me/alert_words')
self.assert_json_success(result)
@@ -119,7 +119,7 @@ class AlertWordTests(ZulipTestCase):
def test_json_list_add(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_put('/json/users/me/alert_words', {'alert_words': ujson.dumps(['one ', '\n two', 'three'])})
self.assert_json_success(result)
@@ -131,7 +131,7 @@ class AlertWordTests(ZulipTestCase):
def test_json_list_remove(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_put('/json/users/me/alert_words', {'alert_words': ujson.dumps(['one', 'two', 'three'])})
self.assert_json_success(result)
@@ -146,7 +146,7 @@ class AlertWordTests(ZulipTestCase):
def test_json_list_set(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_put('/json/users/me/alert_words', {'alert_words': ujson.dumps(['one', 'two', 'three'])})
self.assert_json_success(result)
@@ -168,7 +168,7 @@ class AlertWordTests(ZulipTestCase):
def test_alert_flags(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
user_profile_hamlet = self.example_user('hamlet')
result = self.client_put('/json/users/me/alert_words', {'alert_words': ujson.dumps(['one', 'two', 'three'])})
diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py
index d26918f804..6c52a05a10 100644
--- a/zerver/tests/test_auth_backends.py
+++ b/zerver/tests/test_auth_backends.py
@@ -637,7 +637,7 @@ class GitHubAuthBackendTest(ZulipTestCase):
with mock.patch('social_core.backends.github.GithubOAuth2.do_auth',
side_effect=do_auth):
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
response = dict(email=email, name='Hamlet')
result = self.backend.do_auth(response=response)
self.assert_in_response('action="/register/"', result)
@@ -804,13 +804,13 @@ class GoogleSubdomainLoginTest(GoogleOAuthTest):
token_response = ResponseMock(200, {'access_token': "unique_token"})
account_data = dict(name=dict(formatted="Full Name"),
emails=[dict(type="account",
- value="hamlet@zulip.com")])
+ value=self.example_email("hamlet"))])
account_response = ResponseMock(200, account_data)
with self.settings(REALMS_HAVE_SUBDOMAINS=True):
result = self.google_oauth2_test(token_response, account_response, 'zulip')
data = unsign_subdomain_cookie(result)
- self.assertEqual(data['email'], 'hamlet@zulip.com')
+ self.assertEqual(data['email'], self.example_email("hamlet"))
self.assertEqual(data['name'], 'Full Name')
self.assertEqual(data['subdomain'], 'zulip')
self.assertEqual(result.status_code, 302)
@@ -825,7 +825,7 @@ class GoogleSubdomainLoginTest(GoogleOAuthTest):
token_response = ResponseMock(200, {'access_token': "unique_token"})
account_data = dict(name=dict(formatted="Full Name"),
emails=[dict(type="account",
- value="hamlet@zulip.com")])
+ value=self.example_email("hamlet"))])
account_response = ResponseMock(200, account_data)
with self.settings(REALMS_HAVE_SUBDOMAINS=True):
# Verify that the right thing happens with an invalid-format OTP
@@ -845,7 +845,7 @@ class GoogleSubdomainLoginTest(GoogleOAuthTest):
query_params = urllib.parse.parse_qs(parsed_url.query)
self.assertEqual(parsed_url.scheme, 'zulip')
self.assertEqual(query_params["realm"], ['http://zulip.testserver'])
- self.assertEqual(query_params["email"], ['hamlet@zulip.com'])
+ self.assertEqual(query_params["email"], [self.example_email("hamlet")])
encrypted_api_key = query_params["otp_encrypted_api_key"][0]
self.assertEqual(self.example_user('hamlet').api_key,
otp_decrypt_api_key(encrypted_api_key, mobile_flow_otp))
@@ -853,7 +853,7 @@ class GoogleSubdomainLoginTest(GoogleOAuthTest):
def test_log_into_subdomain(self):
# type: () -> None
data = {'name': 'Full Name',
- 'email': 'hamlet@zulip.com',
+ 'email': self.example_email("hamlet"),
'subdomain': 'zulip',
'is_signup': False}
@@ -876,7 +876,7 @@ class GoogleSubdomainLoginTest(GoogleOAuthTest):
def test_log_into_subdomain_when_is_signup_is_true(self):
# type: () -> None
data = {'name': 'Full Name',
- 'email': 'hamlet@zulip.com',
+ 'email': self.example_email("hamlet"),
'subdomain': 'zulip',
'is_signup': True}
@@ -921,7 +921,7 @@ class GoogleSubdomainLoginTest(GoogleOAuthTest):
token_response = ResponseMock(200, {'access_token': "unique_token"})
account_data = dict(name=dict(formatted="Full Name"),
emails=[dict(type="account",
- value="hamlet@zulip.com")])
+ value=self.example_email("hamlet"))])
account_response = ResponseMock(200, account_data)
result = self.google_oauth2_test(token_response, account_response, 'acme')
self.assertEqual(result.status_code, 302)
@@ -930,7 +930,7 @@ class GoogleSubdomainLoginTest(GoogleOAuthTest):
def test_user_cannot_log_into_wrong_subdomain(self):
# type: () -> None
data = {'name': 'Full Name',
- 'email': 'hamlet@zulip.com',
+ 'email': self.example_email("hamlet"),
'subdomain': 'acme'}
self.client.cookies = SimpleCookie(self.get_signed_subdomain_cookie(data))
@@ -1008,7 +1008,7 @@ class GoogleLoginTest(GoogleOAuthTest):
token_response = ResponseMock(200, {'access_token': "unique_token"})
account_data = dict(name=dict(formatted="Full Name"),
emails=[dict(type="account",
- value="hamlet@zulip.com")])
+ value=self.example_email("hamlet"))])
account_response = ResponseMock(200, account_data)
self.google_oauth2_test(token_response, account_response)
@@ -1052,7 +1052,7 @@ class GoogleLoginTest(GoogleOAuthTest):
token_response = ResponseMock(200, {'access_token': "unique_token"})
account_data = dict(name=dict(formatted="Full Name"),
emails=[dict(type="account",
- value="hamlet@zulip.com")])
+ value=self.example_email("hamlet"))])
account_response = ResponseMock(200, account_data)
with self.settings(REALMS_HAVE_SUBDOMAINS=True):
result = self.google_oauth2_test(token_response, account_response)
@@ -1101,7 +1101,7 @@ class GoogleLoginTest(GoogleOAuthTest):
token_response = ResponseMock(200, {'access_token': "unique_token"})
account_data = dict(name=dict(givenName="Test", familyName="User"),
emails=[dict(type="account",
- value="hamlet@zulip.com")])
+ value=self.example_email("hamlet"))])
account_response = ResponseMock(200, account_data)
self.google_oauth2_test(token_response, account_response)
@@ -1192,7 +1192,7 @@ class FetchAPIKeyTest(ZulipTestCase):
'apiclient.sample_tools.client.verify_id_token',
return_value={
"email_verified": True,
- "email": "hamlet@zulip.com",
+ "email": self.example_email("hamlet"),
}):
result = self.client_post("/api/v1/fetch_api_key",
dict(username="google-oauth2-token",
@@ -1494,7 +1494,7 @@ class TestDevAuthBackend(ZulipTestCase):
def test_login_failure(self):
# type: () -> None
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
data = {'direct_email': email}
with self.settings(AUTHENTICATION_BACKENDS=('zproject.backends.EmailAuthBackend',)):
with self.assertRaisesRegex(Exception, 'Direct login not supported.'):
@@ -1536,7 +1536,7 @@ class TestZulipRemoteUserBackend(ZulipTestCase):
def test_login_failure(self):
# type: () -> None
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
result = self.client_post('/accounts/login/sso/', REMOTE_USER=email)
self.assertEqual(result.status_code, 200) # This should ideally be not 200.
self.assertIs(get_session_dict_user(self.client.session), None)
@@ -1565,7 +1565,7 @@ class TestZulipRemoteUserBackend(ZulipTestCase):
def test_login_failure_due_to_wrong_subdomain(self):
# type: () -> None
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
with self.settings(REALMS_HAVE_SUBDOMAINS=True,
AUTHENTICATION_BACKENDS=('zproject.backends.ZulipRemoteUserBackend',)):
with mock.patch('zerver.views.auth.get_subdomain', return_value='acme'):
@@ -1577,7 +1577,7 @@ class TestZulipRemoteUserBackend(ZulipTestCase):
def test_login_failure_due_to_empty_subdomain(self):
# type: () -> None
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
with self.settings(REALMS_HAVE_SUBDOMAINS=True,
AUTHENTICATION_BACKENDS=('zproject.backends.ZulipRemoteUserBackend',)):
with mock.patch('zerver.views.auth.get_subdomain', return_value=''):
@@ -1608,7 +1608,7 @@ class TestJWTLogin(ZulipTestCase):
# type: () -> None
payload = {'user': 'hamlet', 'realm': 'zulip.com'}
with self.settings(JWT_AUTH_KEYS={'': 'key'}):
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
realm = get_realm('zulip')
auth_key = settings.JWT_AUTH_KEYS['']
web_token = jwt.encode(payload, auth_key).decode('utf8')
@@ -1759,10 +1759,10 @@ class TestLDAP(ZulipTestCase):
LDAP_APPEND_DOMAIN='zulip.com',
AUTH_LDAP_BIND_PASSWORD='',
AUTH_LDAP_USER_DN_TEMPLATE='uid=%(user)s,ou=users,dc=zulip,dc=com'):
- user_profile = self.backend.authenticate('hamlet@zulip.com', 'testing')
+ user_profile = self.backend.authenticate(self.example_email("hamlet"), 'testing')
assert(user_profile is not None)
- self.assertEqual(user_profile.email, 'hamlet@zulip.com')
+ self.assertEqual(user_profile.email, self.example_email("hamlet"))
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',))
def test_login_failure_due_to_wrong_password(self):
@@ -1776,7 +1776,7 @@ class TestLDAP(ZulipTestCase):
LDAP_APPEND_DOMAIN='zulip.com',
AUTH_LDAP_BIND_PASSWORD='',
AUTH_LDAP_USER_DN_TEMPLATE='uid=%(user)s,ou=users,dc=zulip,dc=com'):
- user = self.backend.authenticate('hamlet@zulip.com', 'wrong')
+ user = self.backend.authenticate(self.example_email("hamlet"), 'wrong')
self.assertIs(user, None)
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',))
@@ -1826,8 +1826,8 @@ class TestLDAP(ZulipTestCase):
attrs = {'fn': ['Full Name'], 'sn': ['Short Name']}
backend = self.backend
- email = 'hamlet@zulip.com'
- user_profile, created = backend.get_or_create_user(email, _LDAPUser())
+ email = self.example_email("hamlet")
+ user_profile, created = backend.get_or_create_user(str(email), _LDAPUser())
self.assertFalse(created)
self.assertEqual(user_profile.email, email)
@@ -1880,7 +1880,7 @@ class TestLDAP(ZulipTestCase):
def test_django_to_ldap_username_when_domain_does_not_match(self):
# type: () -> None
backend = self.backend
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
with self.assertRaisesRegex(Exception, 'Username does not match LDAP domain.'):
with self.settings(LDAP_APPEND_DOMAIN='acme.com'):
backend.django_to_ldap_username(email)
@@ -1898,7 +1898,7 @@ class TestLDAP(ZulipTestCase):
LDAP_APPEND_DOMAIN='zulip.com',
AUTH_LDAP_BIND_PASSWORD='',
AUTH_LDAP_USER_DN_TEMPLATE='uid=%(user)s,ou=users,dc=zulip,dc=com'):
- user_profile = self.backend.authenticate('hamlet@zulip.com', 'testing',
+ user_profile = self.backend.authenticate(self.example_email("hamlet"), 'testing',
realm_subdomain='acme')
self.assertIs(user_profile, None)
@@ -1915,7 +1915,7 @@ class TestLDAP(ZulipTestCase):
LDAP_APPEND_DOMAIN='zulip.com',
AUTH_LDAP_BIND_PASSWORD='',
AUTH_LDAP_USER_DN_TEMPLATE='uid=%(user)s,ou=users,dc=zulip,dc=com'):
- user_profile = self.backend.authenticate('hamlet@zulip.com', 'testing',
+ user_profile = self.backend.authenticate(self.example_email("hamlet"), 'testing',
realm_subdomain='')
self.assertIs(user_profile, None)
@@ -1932,10 +1932,10 @@ class TestLDAP(ZulipTestCase):
LDAP_APPEND_DOMAIN='zulip.com',
AUTH_LDAP_BIND_PASSWORD='',
AUTH_LDAP_USER_DN_TEMPLATE='uid=%(user)s,ou=users,dc=zulip,dc=com'):
- user_profile = self.backend.authenticate('hamlet@zulip.com', 'testing',
+ user_profile = self.backend.authenticate(self.example_email("hamlet"), 'testing',
realm_subdomain=None)
assert(user_profile is not None)
- self.assertEqual(user_profile.email, 'hamlet@zulip.com')
+ self.assertEqual(user_profile.email, self.example_email("hamlet"))
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',))
def test_login_success_with_valid_subdomain(self):
@@ -1950,10 +1950,10 @@ class TestLDAP(ZulipTestCase):
LDAP_APPEND_DOMAIN='zulip.com',
AUTH_LDAP_BIND_PASSWORD='',
AUTH_LDAP_USER_DN_TEMPLATE='uid=%(user)s,ou=users,dc=zulip,dc=com'):
- user_profile = self.backend.authenticate('hamlet@zulip.com', 'testing',
+ user_profile = self.backend.authenticate(self.example_email("hamlet"), 'testing',
realm_subdomain='zulip')
assert(user_profile is not None)
- self.assertEqual(user_profile.email, 'hamlet@zulip.com')
+ self.assertEqual(user_profile.email, self.example_email("hamlet"))
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',))
def test_login_success_when_user_does_not_exist_with_valid_subdomain(self):
@@ -1980,7 +1980,7 @@ class TestZulipLDAPUserPopulator(ZulipTestCase):
def test_authenticate(self):
# type: () -> None
backend = ZulipLDAPUserPopulator()
- result = backend.authenticate('hamlet@zulip.com', 'testing') # type: ignore # complains that the function does not return any value!
+ result = backend.authenticate(self.example_email("hamlet"), 'testing') # type: ignore # complains that the function does not return any value!
self.assertIs(result, None)
class TestZulipAuthMixin(ZulipTestCase):
@@ -2017,7 +2017,7 @@ class TestMaybeSendToRegistration(ZulipTestCase):
with self.settings(ONLY_SSO=True):
with mock.patch('zerver.views.auth.HomepageForm', return_value=Form()):
self.assertEqual(PreregistrationUser.objects.all().count(), 0)
- result = maybe_send_to_registration(request, 'hamlet@zulip.com')
+ result = maybe_send_to_registration(request, self.example_email("hamlet"))
self.assertEqual(result.status_code, 302)
confirmation = Confirmation.objects.all().first()
confirmation_key = confirmation.confirmation_key
@@ -2044,7 +2044,7 @@ class TestMaybeSendToRegistration(ZulipTestCase):
# type: () -> bool
return True
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
user = PreregistrationUser(email=email)
user.save()
@@ -2099,7 +2099,7 @@ class TestAdminSetBackends(ZulipTestCase):
class LoginEmailValidatorTestCase(ZulipTestCase):
def test_valid_email(self):
# type: () -> None
- validate_login_email(u'hamlet@zulip.com')
+ validate_login_email(self.example_email("hamlet"))
def test_invalid_email(self):
# type: () -> None
diff --git a/zerver/tests/test_bugdown.py b/zerver/tests/test_bugdown.py
index a2aa21aa5d..d77be856d0 100644
--- a/zerver/tests/test_bugdown.py
+++ b/zerver/tests/test_bugdown.py
@@ -694,7 +694,7 @@ class BugdownTest(ZulipTestCase):
'
'
- '@King Hamlet
' % ('hamlet@zulip.com', user_id))
+ '@King Hamlet' % (self.example_email("hamlet"), user_id))
self.assertEqual(msg.mentions_user_ids, set([user_profile.id]))
def test_mention_shortname(self):
@@ -708,7 +708,7 @@ class BugdownTest(ZulipTestCase):
self.assertEqual(render_markdown(msg, content),
''
- '@King Hamlet
' % ('hamlet@zulip.com', user_id))
+ '@King Hamlet' % (self.example_email("hamlet"), user_id))
self.assertEqual(msg.mentions_user_ids, set([user_profile.id]))
def test_mention_multiple(self):
@@ -959,7 +959,7 @@ class BugdownApiTests(ZulipTestCase):
data = ujson.loads(result.content)
user_id = self.example_user('hamlet').id
self.assertEqual(data['rendered'],
- u'This mentions #Denmark and @King Hamlet.
' % (get_stream("Denmark", get_realm("zulip")).id, 'hamlet@zulip.com', user_id))
+ u'This mentions #Denmark and @King Hamlet.
' % (get_stream("Denmark", get_realm("zulip")).id, self.example_email("hamlet"), user_id))
class BugdownErrorTests(ZulipTestCase):
def test_bugdown_error_handling(self):
diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.py
index 8c0c61de38..e8fdca68de 100644
--- a/zerver/tests/test_decorators.py
+++ b/zerver/tests/test_decorators.py
@@ -565,7 +565,7 @@ class DeactivatedRealmTest(ZulipTestCase):
# Even if a logged-in session was leaked, it still wouldn't work
realm.deactivated = False
realm.save()
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
realm.deactivated = True
realm.save()
@@ -579,7 +579,7 @@ class DeactivatedRealmTest(ZulipTestCase):
"content": "Test message",
"client": "test suite",
"to": "othello@zulip.com"},
- **self.api_auth("hamlet@zulip.com"))
+ **self.api_auth(self.example_email("hamlet")))
self.assert_json_error_contains(result, "has been deactivated", status_code=401)
def test_fetch_api_key_deactivated_realm(self):
@@ -607,7 +607,7 @@ class DeactivatedRealmTest(ZulipTestCase):
"""
do_deactivate_realm(get_realm("zulip"))
- result = self.login_with_return("hamlet@zulip.com")
+ result = self.login_with_return(self.example_email("hamlet"))
self.assert_in_response("has been deactivated", result)
def test_webhook_deactivated_realm(self):
@@ -617,7 +617,7 @@ class DeactivatedRealmTest(ZulipTestCase):
"""
do_deactivate_realm(get_realm("zulip"))
- email = "hamlet@zulip.com"
+ email = self.example_email("hamlet")
api_key = self.get_api_key(email)
url = "/api/v1/external/jira?api_key=%s&stream=jira_custom" % (api_key,)
data = self.fixture_data('jira', "created_v2")
@@ -712,7 +712,7 @@ class InactiveUserTest(ZulipTestCase):
"content": "Test message",
"client": "test suite",
"to": "othello@zulip.com"},
- **self.api_auth("hamlet@zulip.com"))
+ **self.api_auth(self.example_email("hamlet")))
self.assert_json_error_contains(result, "Account not active", status_code=401)
def test_fetch_api_key_deactivated_user(self):
@@ -742,7 +742,7 @@ class InactiveUserTest(ZulipTestCase):
user_profile = self.example_user('hamlet')
do_deactivate_user(user_profile)
- result = self.login_with_return("hamlet@zulip.com")
+ result = self.login_with_return(self.example_email("hamlet"))
self.assert_in_response("Please enter a correct email and password", result)
def test_webhook_deactivated_user(self):
@@ -1001,12 +1001,12 @@ class TestAuthenticatedJsonPostViewDecorator(ZulipTestCase):
class TestAuthenticatedJsonViewDecorator(ZulipTestCase):
def test_authenticated_json_view_if_subdomain_is_invalid(self):
# type: () -> None
- user_email = 'hamlet@zulip.com'
+ user_email = self.example_email("hamlet")
self.login(user_email)
with self.settings(REALMS_HAVE_SUBDOMAINS=True):
with mock.patch('logging.warning') as mock_warning, \
mock.patch('zerver.decorator.get_subdomain', return_value=''):
- self.assert_json_error_contains(self._do_test(user_email),
+ self.assert_json_error_contains(self._do_test(str(user_email)),
"Account is not associated with this "
"subdomain")
mock_warning.assert_called_with(
@@ -1015,7 +1015,7 @@ class TestAuthenticatedJsonViewDecorator(ZulipTestCase):
with mock.patch('logging.warning') as mock_warning, \
mock.patch('zerver.decorator.get_subdomain', return_value='acme'):
- self.assert_json_error_contains(self._do_test(user_email),
+ self.assert_json_error_contains(self._do_test(str(user_email)),
"Account is not associated with this "
"subdomain")
mock_warning.assert_called_with(
@@ -1030,7 +1030,7 @@ class TestAuthenticatedJsonViewDecorator(ZulipTestCase):
class TestZulipLoginRequiredDecorator(ZulipTestCase):
def test_zulip_login_required_if_subdomain_is_invalid(self):
# type: () -> None
- user_email = 'hamlet@zulip.com'
+ user_email = self.example_email("hamlet")
self.login(user_email)
with self.settings(REALMS_HAVE_SUBDOMAINS=True):
@@ -1098,14 +1098,14 @@ class ReturnSuccessOnHeadRequestDecorator(ZulipTestCase):
class RestAPITest(ZulipTestCase):
def test_method_not_allowed(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_patch('/json/users')
self.assertEqual(result.status_code, 405)
self.assert_in_response('Method Not Allowed', result)
def test_options_method(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_options('/json/users')
self.assertEqual(result.status_code, 204)
self.assertEqual(str(result['Allow']), 'GET, POST')
diff --git a/zerver/tests/test_email_change.py b/zerver/tests/test_email_change.py
index fa37d86ac0..f2408b91ed 100644
--- a/zerver/tests/test_email_change.py
+++ b/zerver/tests/test_email_change.py
@@ -23,7 +23,7 @@ from zerver.models import get_user, EmailChangeStatus, Realm, get_realm
class EmailChangeTestCase(ZulipTestCase):
def test_confirm_email_change_with_non_existent_key(self):
# type: () -> None
- self.login('hamlet@zulip.com')
+ self.login(self.example_email("hamlet"))
key = generate_key()
with self.assertRaises(EmailChangeConfirmation.DoesNotExist):
url = EmailChangeConfirmation.objects.get_activation_url(key)
@@ -35,7 +35,7 @@ class EmailChangeTestCase(ZulipTestCase):
def test_confirm_email_change_with_invalid_key(self):
# type: () -> None
- self.login('hamlet@zulip.com')
+ self.login(self.example_email("hamlet"))
key = 'invalid key'
with self.assertRaises(EmailChangeConfirmation.DoesNotExist):
url = EmailChangeConfirmation.objects.get_activation_url(key)
@@ -61,7 +61,7 @@ class EmailChangeTestCase(ZulipTestCase):
user_profile = self.example_user('hamlet')
old_email = user_profile.email
new_email = 'hamlet-new@zulip.com'
- self.login('hamlet@zulip.com')
+ self.login(self.example_email("hamlet"))
obj = EmailChangeStatus.objects.create(new_email=new_email,
old_email=old_email,
user_profile=user_profile,
@@ -110,7 +110,7 @@ class EmailChangeTestCase(ZulipTestCase):
def test_end_to_end_flow(self):
# type: () -> None
data = {'email': 'hamlet-new@zulip.com'}
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
self.login(email)
url = '/json/settings/change'
self.assertEqual(len(mail.outbox), 0)
@@ -176,7 +176,7 @@ class EmailChangeTestCase(ZulipTestCase):
def test_post_invalid_email(self):
# type: () -> None
data = {'email': 'hamlet-new'}
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
self.login(email)
url = '/json/settings/change'
result = self.client_post(url, data)
@@ -184,8 +184,8 @@ class EmailChangeTestCase(ZulipTestCase):
def test_post_same_email(self):
# type: () -> None
- data = {'email': 'hamlet@zulip.com'}
- email = 'hamlet@zulip.com'
+ data = {'email': self.example_email("hamlet")}
+ email = self.example_email("hamlet")
self.login(email)
url = '/json/settings/change'
result = self.client_post(url, data)
diff --git a/zerver/tests/test_email_mirror.py b/zerver/tests/test_email_mirror.py
index 330b5ec832..06fbd5674e 100644
--- a/zerver/tests/test_email_mirror.py
+++ b/zerver/tests/test_email_mirror.py
@@ -179,7 +179,7 @@ class TestMissedPersonalMessageEmailMessages(ZulipTestCase):
process_message(incoming_valid_message)
- # self.login("hamlet@zulip.com")
+ # self.login(self.example_email("hamlet"))
# confirm that Hamlet got the message
user_profile = self.example_user('hamlet')
message = most_recent_message(user_profile)
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index 37f6e3b8b8..a1e2ee965d 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -96,7 +96,7 @@ class EventsEndpointTest(ZulipTestCase):
# This test is intended to get minimal coverage on the
# events_register code paths
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
with mock.patch('zerver.views.events_register.do_events_register', return_value={}):
result = self.client_post('/json/register', **self.api_auth(email))
self.assert_json_success(result)
@@ -456,7 +456,7 @@ class EventsRegisterTest(ZulipTestCase):
])
events = self.do_test(
- lambda: self.send_message("hamlet@zulip.com", "Verona", Recipient.STREAM, "hello"),
+ lambda: self.send_message(self.example_email("hamlet"), "Verona", Recipient.STREAM, "hello"),
)
error = schema_checker('events[0]', events[0])
self.assert_on_error(error)
@@ -527,7 +527,7 @@ class EventsRegisterTest(ZulipTestCase):
('operation', equals("add")),
])
- message = self.send_message("cordelia@zulip.com", "hamlet@zulip.com", Recipient.PERSONAL, "hello")
+ message = self.send_message("cordelia@zulip.com", self.example_email("hamlet"), Recipient.PERSONAL, "hello")
user_profile = self.example_user('hamlet')
events = self.do_test(
lambda: do_update_message_flags(user_profile, 'add', 'starred',
@@ -565,7 +565,7 @@ class EventsRegisterTest(ZulipTestCase):
])),
])
- message_id = self.send_message("hamlet@zulip.com", "Verona", Recipient.STREAM, "hello")
+ message_id = self.send_message(self.example_email("hamlet"), "Verona", Recipient.STREAM, "hello")
message = Message.objects.get(id=message_id)
events = self.do_test(
lambda: do_add_reaction(
@@ -589,7 +589,7 @@ class EventsRegisterTest(ZulipTestCase):
])),
])
- message_id = self.send_message("hamlet@zulip.com", "Verona", Recipient.STREAM, "hello")
+ message_id = self.send_message(self.example_email("hamlet"), "Verona", Recipient.STREAM, "hello")
message = Message.objects.get(id=message_id)
events = self.do_test(
lambda: do_remove_reaction(
@@ -1421,7 +1421,7 @@ class EventsRegisterTest(ZulipTestCase):
])
# Subscribe to a totally new stream, so it's just Hamlet on it
- action = lambda: self.subscribe_to_stream("hamlet@zulip.com", "test_stream") # type: Callable
+ action = lambda: self.subscribe_to_stream(self.example_email("hamlet"), "test_stream") # type: Callable
events = self.do_test(action, event_types=["subscription", "realm_user"],
include_subscribers=include_subscribers)
error = add_schema_checker('events[0]', events[0])
@@ -1460,7 +1460,7 @@ class EventsRegisterTest(ZulipTestCase):
self.assert_on_error(error)
# Now resubscribe a user, to make sure that works on a vacated stream
- action = lambda: self.subscribe_to_stream("hamlet@zulip.com", "test_stream")
+ action = lambda: self.subscribe_to_stream(self.example_email("hamlet"), "test_stream")
events = self.do_test(action,
include_subscribers=include_subscribers,
num_events=2)
diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py
index b278d5e97f..6a1b15955a 100644
--- a/zerver/tests/test_home.py
+++ b/zerver/tests/test_home.py
@@ -146,7 +146,7 @@ class HomeTest(ZulipTestCase):
"zulip_version",
]
- email = "hamlet@zulip.com"
+ email = self.example_email("hamlet")
# Verify fails if logged-out
result = self.client_get('/')
@@ -258,7 +258,7 @@ class HomeTest(ZulipTestCase):
def test_accept_terms_of_service(self):
# type: () -> None
- email = "hamlet@zulip.com"
+ email = self.example_email("hamlet")
self.login(email)
result = self.client_post('/accounts/accept_terms/')
@@ -271,7 +271,7 @@ class HomeTest(ZulipTestCase):
def test_bad_narrow(self):
# type: () -> None
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
self.login(email)
with patch('logging.exception') as mock:
result = self._get_home_page(stream='Invalid Stream')
@@ -293,7 +293,7 @@ class HomeTest(ZulipTestCase):
def test_topic_narrow(self):
# type: () -> None
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
self.login(email)
result = self._get_home_page(stream='Denmark', topic='lunch')
self._sanity_check(result)
@@ -302,7 +302,7 @@ class HomeTest(ZulipTestCase):
def test_notifications_stream(self):
# type: () -> None
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
realm = get_realm('zulip')
realm.notifications_stream = get_stream('Denmark', realm)
realm.save()
@@ -350,7 +350,7 @@ class HomeTest(ZulipTestCase):
def test_new_stream(self):
# type: () -> None
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
stream_name = 'New stream'
self.subscribe_to_stream(email, stream_name)
self.login(email)
@@ -385,7 +385,7 @@ class HomeTest(ZulipTestCase):
def test_desktop_home(self):
# type: () -> None
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
self.login(email)
result = self.client_get("/desktop_home")
self.assertEqual(result.status_code, 301)
@@ -397,7 +397,7 @@ class HomeTest(ZulipTestCase):
def test_generate_204(self):
# type: () -> None
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
self.login(email)
result = self.client_get("/api/v1/generate_204")
self.assertEqual(result.status_code, 204)
@@ -421,7 +421,7 @@ class HomeTest(ZulipTestCase):
def test_subdomain_homepage(self):
# type: () -> None
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
self.login(email)
with self.settings(SUBDOMAINS_HOMEPAGE=True):
with patch('zerver.views.home.get_subdomain', return_value=""):
diff --git a/zerver/tests/test_messages.py b/zerver/tests/test_messages.py
index c2d991e0d0..9d97c088dd 100644
--- a/zerver/tests/test_messages.py
+++ b/zerver/tests/test_messages.py
@@ -391,8 +391,8 @@ class PersonalMessagesTest(ZulipTestCase):
"""
If you send a personal, only you and the recipient see it.
"""
- self.login("hamlet@zulip.com")
- self.assert_personal("hamlet@zulip.com", "othello@zulip.com")
+ self.login(self.example_email("hamlet"))
+ self.assert_personal(self.example_email("hamlet"), "othello@zulip.com")
@slow("assert_personal checks several profiles")
def test_non_ascii_personal(self):
@@ -400,8 +400,8 @@ class PersonalMessagesTest(ZulipTestCase):
"""
Sending a PM containing non-ASCII characters succeeds.
"""
- self.login("hamlet@zulip.com")
- self.assert_personal("hamlet@zulip.com", "othello@zulip.com", u"hümbüǵ")
+ self.login(self.example_email("hamlet"))
+ self.assert_personal(self.example_email("hamlet"), "othello@zulip.com", u"hümbüǵ")
class StreamMessagesTest(ZulipTestCase):
@@ -445,7 +445,7 @@ class StreamMessagesTest(ZulipTestCase):
def test_not_too_many_queries(self):
# type: () -> None
- recipient_list = ['hamlet@zulip.com', 'iago@zulip.com', 'cordelia@zulip.com', 'othello@zulip.com']
+ recipient_list = [self.example_email("hamlet"), 'iago@zulip.com', 'cordelia@zulip.com', 'othello@zulip.com']
for email in recipient_list:
self.subscribe_to_stream(email, "Denmark")
@@ -473,7 +473,7 @@ class StreamMessagesTest(ZulipTestCase):
# type: () -> None
user_profile = self.example_user('iago')
self.subscribe_to_stream(user_profile.email, "Denmark")
- self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM,
+ self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM,
content="whatever", subject="my topic")
message = most_recent_message(user_profile)
row = Message.get_raw_db_rows([message.id])[0]
@@ -487,7 +487,7 @@ class StreamMessagesTest(ZulipTestCase):
# type: () -> None
user_profile = self.example_user('iago')
self.subscribe_to_stream(user_profile.email, "Denmark")
- self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM,
+ self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM,
content="whatever", subject="my topic")
message = most_recent_message(user_profile)
self.assertEqual(str(message),
@@ -498,7 +498,7 @@ class StreamMessagesTest(ZulipTestCase):
# type: () -> None
user_profile = self.example_user('iago')
self.subscribe_to_stream(user_profile.email, "Denmark")
- self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM,
+ self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM,
content="test @**Iago** rules")
message = most_recent_message(user_profile)
assert(UserMessage.objects.get(user_profile=user_profile, message=message).flags.mentioned.is_set)
@@ -546,7 +546,7 @@ class StreamMessagesTest(ZulipTestCase):
Sending a stream message containing non-ASCII characters in the stream
name, subject, or message body succeeds.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
# Subscribe everyone to a stream with non-ASCII characters.
non_ascii_stream_name = u"hümbüǵ"
@@ -746,7 +746,7 @@ class MessagePOSTTest(ZulipTestCase):
Sending a message to a stream to which you are subscribed is
successful.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_post("/json/messages", {"type": "stream",
"to": "Verona",
"client": "test suite",
@@ -759,7 +759,7 @@ class MessagePOSTTest(ZulipTestCase):
"""
Same as above, but for the API view
"""
- email = "hamlet@zulip.com"
+ email = self.example_email("hamlet")
result = self.client_post("/api/v1/messages", {"type": "stream",
"to": "Verona",
"client": "test suite",
@@ -793,7 +793,7 @@ class MessagePOSTTest(ZulipTestCase):
"""
Sending a message to a nonexistent stream fails.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
self.assertFalse(Stream.objects.filter(name="nonexistent_stream"))
result = self.client_post("/json/messages", {"type": "stream",
"to": "nonexistent_stream",
@@ -807,7 +807,7 @@ class MessagePOSTTest(ZulipTestCase):
"""
Nonexistent stream name with bad characters should be escaped properly.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
self.assertFalse(Stream.objects.filter(name="""&<"'>"""))
result = self.client_post("/json/messages", {"type": "stream",
"to": """&<"'>""",
@@ -821,7 +821,7 @@ class MessagePOSTTest(ZulipTestCase):
"""
Sending a personal message to a valid username is successful.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_post("/json/messages", {"type": "private",
"content": "Test message",
"client": "test suite",
@@ -833,7 +833,7 @@ class MessagePOSTTest(ZulipTestCase):
"""
Sending a personal message to an invalid email returns error JSON.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_post("/json/messages", {"type": "private",
"content": "Test message",
"client": "test suite",
@@ -845,7 +845,7 @@ class MessagePOSTTest(ZulipTestCase):
"""
Sending a message of unknown type returns error JSON.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_post("/json/messages", {"type": "invalid type",
"content": "Test message",
"client": "test suite",
@@ -857,7 +857,7 @@ class MessagePOSTTest(ZulipTestCase):
"""
Sending a message that is empty or only whitespace should fail
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_post("/json/messages", {"type": "private",
"content": " ",
"client": "test suite",
@@ -918,7 +918,7 @@ class MessagePOSTTest(ZulipTestCase):
Sending a message longer than the maximum message length succeeds but is
truncated.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
post_data = {"type": "stream", "to": "Verona", "client": "test suite",
"content": " I like whitespace at the end! \n\n \n", "subject": "Test subject"}
result = self.client_post("/json/messages", post_data)
@@ -932,7 +932,7 @@ class MessagePOSTTest(ZulipTestCase):
Sending a message longer than the maximum message length succeeds but is
truncated.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
long_message = "A" * (MAX_MESSAGE_LENGTH + 1)
post_data = {"type": "stream", "to": "Verona", "client": "test suite",
"content": long_message, "subject": "Test subject"}
@@ -949,7 +949,7 @@ class MessagePOSTTest(ZulipTestCase):
Sending a message with a topic longer than the maximum topic length
succeeds, but the topic is truncated.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
long_topic = "A" * (MAX_SUBJECT_LENGTH + 1)
post_data = {"type": "stream", "to": "Verona", "client": "test suite",
"content": "test content", "subject": long_topic}
@@ -962,7 +962,7 @@ class MessagePOSTTest(ZulipTestCase):
def test_send_forged_message_as_not_superuser(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_post("/json/messages", {"type": "stream",
"to": "Verona",
"client": "test suite",
@@ -973,7 +973,7 @@ class MessagePOSTTest(ZulipTestCase):
def test_send_message_as_not_superuser_to_different_domain(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_post("/json/messages", {"type": "stream",
"to": "Verona",
"client": "test suite",
@@ -1101,8 +1101,8 @@ class EditMessageTest(ZulipTestCase):
# type: () -> None
"""This is also tested by a client test, but here we can verify
the cache against the database"""
- self.login("hamlet@zulip.com")
- msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
+ self.login(self.example_email("hamlet"))
+ msg_id = self.send_message(self.example_email("hamlet"), "Scotland", Recipient.STREAM,
subject="editing", content="before edit")
result = self.client_patch("/json/messages/" + str(msg_id), {
'message_id': msg_id,
@@ -1120,8 +1120,8 @@ class EditMessageTest(ZulipTestCase):
def test_fetch_raw_message(self):
# type: () -> None
- self.login("hamlet@zulip.com")
- msg_id = self.send_message("hamlet@zulip.com", "cordelia@zulip.com", Recipient.PERSONAL,
+ self.login(self.example_email("hamlet"))
+ msg_id = self.send_message(self.example_email("hamlet"), "cordelia@zulip.com", Recipient.PERSONAL,
subject="editing", content="**before** edit")
result = self.client_get('/json/messages/' + str(msg_id))
self.assert_json_success(result)
@@ -1142,7 +1142,7 @@ class EditMessageTest(ZulipTestCase):
def test_fetch_raw_message_stream_wrong_realm(self):
# type: () -> None
- email = "hamlet@zulip.com"
+ email = self.example_email("hamlet")
self.login(email)
stream = self.make_stream('public_stream')
self.subscribe_to_stream(email, stream.name)
@@ -1157,7 +1157,7 @@ class EditMessageTest(ZulipTestCase):
def test_fetch_raw_message_private_stream(self):
# type: () -> None
- email = "hamlet@zulip.com"
+ email = self.example_email("hamlet")
self.login(email)
stream = self.make_stream('private_stream', invite_only=True)
self.subscribe_to_stream(email, stream.name)
@@ -1171,7 +1171,7 @@ class EditMessageTest(ZulipTestCase):
def test_edit_message_no_permission(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
msg_id = self.send_message("iago@zulip.com", "Scotland", Recipient.STREAM,
subject="editing", content="before edit")
result = self.client_patch("/json/messages/" + str(msg_id), {
@@ -1182,8 +1182,8 @@ class EditMessageTest(ZulipTestCase):
def test_edit_message_no_changes(self):
# type: () -> None
- self.login("hamlet@zulip.com")
- msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
+ self.login(self.example_email("hamlet"))
+ msg_id = self.send_message(self.example_email("hamlet"), "Scotland", Recipient.STREAM,
subject="editing", content="before edit")
result = self.client_patch("/json/messages/" + str(msg_id), {
'message_id': msg_id,
@@ -1192,8 +1192,8 @@ class EditMessageTest(ZulipTestCase):
def test_edit_message_no_topic(self):
# type: () -> None
- self.login("hamlet@zulip.com")
- msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
+ self.login(self.example_email("hamlet"))
+ msg_id = self.send_message(self.example_email("hamlet"), "Scotland", Recipient.STREAM,
subject="editing", content="before edit")
result = self.client_patch("/json/messages/" + str(msg_id), {
'message_id': msg_id,
@@ -1203,8 +1203,8 @@ class EditMessageTest(ZulipTestCase):
def test_edit_message_no_content(self):
# type: () -> None
- self.login("hamlet@zulip.com")
- msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
+ self.login(self.example_email("hamlet"))
+ msg_id = self.send_message(self.example_email("hamlet"), "Scotland", Recipient.STREAM,
subject="editing", content="before edit")
result = self.client_patch("/json/messages/" + str(msg_id), {
'message_id': msg_id,
@@ -1216,8 +1216,8 @@ class EditMessageTest(ZulipTestCase):
def test_edit_message_history(self):
# type: () -> None
- self.login("hamlet@zulip.com")
- msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
+ self.login(self.example_email("hamlet"))
+ msg_id = self.send_message(self.example_email("hamlet"), "Scotland", Recipient.STREAM,
subject="editing", content="content before edit")
new_content = 'content after edit'
@@ -1246,9 +1246,9 @@ class EditMessageTest(ZulipTestCase):
# type: () -> None
"""This test verifies the accuracy of construction of Zulip's edit
history data structures."""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
hamlet = self.example_user('hamlet')
- msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
+ msg_id = self.send_message(self.example_email("hamlet"), "Scotland", Recipient.STREAM,
subject="subject 1", content="content 1")
result = self.client_patch("/json/messages/" + str(msg_id), {
'message_id': msg_id,
@@ -1426,14 +1426,14 @@ class EditMessageTest(ZulipTestCase):
def test_propagate_topic_forward(self):
# type: () -> None
- self.login("hamlet@zulip.com")
- id1 = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
+ self.login(self.example_email("hamlet"))
+ id1 = self.send_message(self.example_email("hamlet"), "Scotland", Recipient.STREAM,
subject="topic1")
id2 = self.send_message("iago@zulip.com", "Scotland", Recipient.STREAM,
subject="topic1")
id3 = self.send_message("iago@zulip.com", "Rome", Recipient.STREAM,
subject="topic1")
- id4 = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
+ id4 = self.send_message(self.example_email("hamlet"), "Scotland", Recipient.STREAM,
subject="topic2")
id5 = self.send_message("iago@zulip.com", "Scotland", Recipient.STREAM,
subject="topic1")
@@ -1453,14 +1453,14 @@ class EditMessageTest(ZulipTestCase):
def test_propagate_all_topics(self):
# type: () -> None
- self.login("hamlet@zulip.com")
- id1 = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
+ self.login(self.example_email("hamlet"))
+ id1 = self.send_message(self.example_email("hamlet"), "Scotland", Recipient.STREAM,
subject="topic1")
- id2 = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
+ id2 = self.send_message(self.example_email("hamlet"), "Scotland", Recipient.STREAM,
subject="topic1")
id3 = self.send_message("iago@zulip.com", "Rome", Recipient.STREAM,
subject="topic1")
- id4 = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
+ id4 = self.send_message(self.example_email("hamlet"), "Scotland", Recipient.STREAM,
subject="topic2")
id5 = self.send_message("iago@zulip.com", "Scotland", Recipient.STREAM,
subject="topic1")
@@ -1677,8 +1677,8 @@ class StarTests(ZulipTestCase):
You can set a message as starred/un-starred through
POST /json/messages/flags.
"""
- self.login("hamlet@zulip.com")
- message_ids = [self.send_message("hamlet@zulip.com", "hamlet@zulip.com",
+ self.login(self.example_email("hamlet"))
+ message_ids = [self.send_message(self.example_email("hamlet"), self.example_email("hamlet"),
Recipient.PERSONAL, "test")]
# Star a message.
@@ -1706,14 +1706,14 @@ class StarTests(ZulipTestCase):
POST /json/messages/flags.
"""
stream_name = "new_stream"
- self.subscribe_to_stream("hamlet@zulip.com", stream_name)
- self.login("hamlet@zulip.com")
- message_ids = [self.send_message("hamlet@zulip.com", stream_name,
+ self.subscribe_to_stream(self.example_email("hamlet"), stream_name)
+ self.login(self.example_email("hamlet"))
+ message_ids = [self.send_message(self.example_email("hamlet"), stream_name,
Recipient.STREAM, "test")]
# Send a second message so we can verify it isn't modified
- other_message_ids = [self.send_message("hamlet@zulip.com", stream_name,
+ other_message_ids = [self.send_message(self.example_email("hamlet"), stream_name,
Recipient.STREAM, "test_unused")]
- received_message_ids = [self.send_message("hamlet@zulip.com", ['cordelia@zulip.com'],
+ received_message_ids = [self.send_message(self.example_email("hamlet"), ['cordelia@zulip.com'],
Recipient.PERSONAL, "test_received")]
# Now login as another user who wasn't on that stream
@@ -1764,8 +1764,8 @@ class StarTests(ZulipTestCase):
You can set a message as starred/un-starred through
POST /json/messages/flags.
"""
- self.login("hamlet@zulip.com")
- message_ids = [self.send_message("hamlet@zulip.com", "hamlet@zulip.com",
+ self.login(self.example_email("hamlet"))
+ message_ids = [self.send_message(self.example_email("hamlet"), self.example_email("hamlet"),
Recipient.PERSONAL, "test")]
# Starring private messages you didn't receive fails.
@@ -1777,9 +1777,9 @@ class StarTests(ZulipTestCase):
# type: () -> None
stream_name = "private_stream"
self.make_stream(stream_name, invite_only=True)
- self.subscribe_to_stream("hamlet@zulip.com", stream_name)
- self.login("hamlet@zulip.com")
- message_ids = [self.send_message("hamlet@zulip.com", stream_name,
+ self.subscribe_to_stream(self.example_email("hamlet"), stream_name)
+ self.login(self.example_email("hamlet"))
+ message_ids = [self.send_message(self.example_email("hamlet"), stream_name,
Recipient.STREAM, "test")]
# Starring private stream messages you received works
@@ -1864,7 +1864,7 @@ class LogDictTest(ZulipTestCase):
stream_name = 'Denmark'
topic_name = 'Copenhagen'
content = 'find me some good coffee shops'
- # self.login("hamlet@zulip.com")
+ # self.login(self.example_email("hamlet"))
message_id = self.send_message(email, stream_name,
message_type=Recipient.STREAM,
subject=topic_name,
@@ -1878,7 +1878,7 @@ class LogDictTest(ZulipTestCase):
self.assertEqual(dct['id'], message.id)
self.assertEqual(dct['recipient'], 'Denmark')
self.assertEqual(dct['sender_realm_str'], 'zulip')
- self.assertEqual(dct['sender_email'], 'hamlet@zulip.com')
+ self.assertEqual(dct['sender_email'], self.example_email("hamlet"))
self.assertEqual(dct['sender_full_name'], 'King Hamlet')
self.assertEqual(dct['sender_id'], self.example_user('hamlet').id)
self.assertEqual(dct['sender_short_name'], 'hamlet')
diff --git a/zerver/tests/test_narrow.py b/zerver/tests/test_narrow.py
index 71039082ae..704e73aba2 100644
--- a/zerver/tests/test_narrow.py
+++ b/zerver/tests/test_narrow.py
@@ -170,12 +170,12 @@ class NarrowBuilderTest(ZulipTestCase):
def test_add_term_using_pm_with_operator_the_same_user_as_operand(self):
# type: () -> None
- term = dict(operator='pm-with', operand='hamlet@zulip.com')
+ term = dict(operator='pm-with', operand=self.example_email("hamlet"))
self._do_add_term_test(term, 'WHERE sender_id = :sender_id_1 AND recipient_id = :recipient_id_1')
def test_add_term_using_pm_with_operator_the_same_user_as_operand_and_negated(self): # NEGATED
# type: () -> None
- term = dict(operator='pm-with', operand='hamlet@zulip.com', negated=True)
+ term = dict(operator='pm-with', operand=self.example_email("hamlet"), negated=True)
self._do_add_term_test(term, 'WHERE NOT (sender_id = :sender_id_1 AND recipient_id = :recipient_id_1)')
def test_add_term_using_pm_with_operator_and_more_than_user_as_operand(self):
@@ -437,7 +437,7 @@ class GetOldMessagesTest(ZulipTestCase):
"""
Test old `/json/messages` returns reactions.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
messages = self.get_and_check_messages(dict())
message_id = messages['messages'][0]['id']
@@ -448,7 +448,7 @@ class GetOldMessagesTest(ZulipTestCase):
payload = self.client_put(url)
self.assert_json_success(payload)
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
messages = self.get_and_check_messages({})
message_to_assert = None
for message in messages['messages']:
@@ -466,7 +466,7 @@ class GetOldMessagesTest(ZulipTestCase):
A call to GET /json/messages with valid parameters returns a list of
messages.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
self.get_and_check_messages(dict())
# We have to support the legacy tuple style while there are old
@@ -511,7 +511,7 @@ class GetOldMessagesTest(ZulipTestCase):
A request for old messages with a narrow by group-pm-with only returns
group-private conversations with that user.
"""
- me = 'hamlet@zulip.com'
+ me = self.example_email("hamlet")
matching_message_ids = []
matching_message_ids.append(self.send_message(me, ['iago@zulip.com', 'cordelia@zulip.com', 'othello@zulip.com'], Recipient.HUDDLE))
@@ -539,8 +539,8 @@ class GetOldMessagesTest(ZulipTestCase):
# We need to subscribe to a stream and then send a message to
# it to ensure that we actually have a stream message in this
# narrow view.
- self.subscribe_to_stream("hamlet@zulip.com", 'Scotland')
- self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM)
+ self.subscribe_to_stream(self.example_email("hamlet"), 'Scotland')
+ self.send_message(self.example_email("hamlet"), "Scotland", Recipient.STREAM)
messages = get_user_messages(self.example_user('hamlet'))
stream_messages = [msg for msg in messages if msg.recipient.type == Recipient.STREAM]
stream_name = get_display_recipient(stream_messages[0].recipient)
@@ -670,12 +670,12 @@ class GetOldMessagesTest(ZulipTestCase):
A request for old messages with a narrow by sender only returns
messages sent by that person.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
# We need to send a message here to ensure that we actually
# have a stream message in this narrow view.
- self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM)
+ self.send_message(self.example_email("hamlet"), "Scotland", Recipient.STREAM)
self.send_message("othello@zulip.com", "Scotland", Recipient.STREAM)
- self.send_message("othello@zulip.com", "hamlet@zulip.com", Recipient.PERSONAL)
+ self.send_message("othello@zulip.com", self.example_email("hamlet"), Recipient.PERSONAL)
self.send_message("iago@zulip.com", "Scotland", Recipient.STREAM)
narrow = [dict(operator='sender', operand='othello@zulip.com')]
@@ -804,9 +804,9 @@ class GetOldMessagesTest(ZulipTestCase):
def test_get_messages_with_search_not_subscribed(self):
# type: () -> None
"""Verify support for searching a stream you're not subscribed to"""
- self.subscribe_to_stream("hamlet@zulip.com", "newstream")
+ self.subscribe_to_stream(self.example_email("hamlet"), "newstream")
self.send_message(
- sender_name="hamlet@zulip.com",
+ sender_name=self.example_email("hamlet"),
raw_recipients="newstream",
message_type=Recipient.STREAM,
content="Public special content!",
@@ -936,7 +936,7 @@ class GetOldMessagesTest(ZulipTestCase):
anchor, num_before, and num_after are all required
POST parameters for get_messages.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
required_args = (("anchor", 1), ("num_before", 1), ("num_after", 1)) # type: Tuple[Tuple[Text, int], ...]
@@ -952,7 +952,7 @@ class GetOldMessagesTest(ZulipTestCase):
num_before, num_after, and narrow must all be non-negative
integers or strings that can be converted to non-negative integers.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
other_params = [("narrow", {}), ("anchor", 0)]
int_params = ["num_before", "num_after"]
@@ -975,7 +975,7 @@ class GetOldMessagesTest(ZulipTestCase):
"""
narrow must be a list of string pairs.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
other_params = [("anchor", 0), ("num_before", 0), ("num_after", 0)] # type: List[Tuple[Text, Union[int, str, bool]]]
@@ -992,7 +992,7 @@ class GetOldMessagesTest(ZulipTestCase):
"""
Unrecognized narrow operators are rejected.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
for operator in ['', 'foo', 'stream:verona', '__init__']:
narrow = [dict(operator=operator, operand='')]
params = dict(anchor=0, num_before=0, num_after=0, narrow=ujson.dumps(narrow))
@@ -1005,7 +1005,7 @@ class GetOldMessagesTest(ZulipTestCase):
"""
We expect search operands to be strings, not integers.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
not_a_string = 42
narrow = [dict(operator='stream', operand=not_a_string)]
params = dict(anchor=0, num_before=0, num_after=0, narrow=ujson.dumps(narrow))
@@ -1027,7 +1027,7 @@ class GetOldMessagesTest(ZulipTestCase):
If an invalid stream name is requested in get_messages, an error is
returned.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
bad_stream_content = (0, [], ["x", "y"]) # type: Sequence
self.exercise_bad_narrow_operand("stream", bad_stream_content,
"Bad value for 'narrow'")
@@ -1038,20 +1038,20 @@ class GetOldMessagesTest(ZulipTestCase):
If an invalid 'pm-with' is requested in get_messages, an
error is returned.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
bad_stream_content = (0, [], ["x", "y"]) # type: Tuple[int, List[None], List[Text]]
self.exercise_bad_narrow_operand("pm-with", bad_stream_content,
"Bad value for 'narrow'")
def test_bad_narrow_nonexistent_stream(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
self.exercise_bad_narrow_operand("stream", ['non-existent stream'],
"Invalid narrow operator: unknown stream")
def test_bad_narrow_nonexistent_email(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
self.exercise_bad_narrow_operand("pm-with", ['non-existent-user@zulip.com'],
"Invalid narrow operator: unknown user")
@@ -1085,7 +1085,7 @@ class GetOldMessagesTest(ZulipTestCase):
# Have Othello send messages to Hamlet that he hasn't read.
self.send_message("othello@zulip.com", "Scotland", Recipient.STREAM)
- last_message_id_to_hamlet = self.send_message("othello@zulip.com", "hamlet@zulip.com", Recipient.PERSONAL)
+ last_message_id_to_hamlet = self.send_message("othello@zulip.com", self.example_email("hamlet"), Recipient.PERSONAL)
# Add a few messages that help us test that our query doesn't
# look at messages that are irrelevant to Hamlet.
@@ -1311,7 +1311,7 @@ class GetOldMessagesTest(ZulipTestCase):
sql_template = 'SELECT anon_1.message_id, anon_1.flags \nFROM (SELECT message_id, flags \nFROM zerver_usermessage JOIN zerver_message ON zerver_usermessage.message_id = zerver_message.id \nWHERE user_profile_id = {hamlet_id} AND sender_id = {hamlet_id} AND recipient_id = {hamlet_recipient} AND message_id >= 0 ORDER BY message_id ASC \n LIMIT 10) AS anon_1 ORDER BY message_id ASC'
sql = sql_template.format(**query_ids)
self.common_check_get_messages_query({'anchor': 0, 'num_before': 0, 'num_after': 10,
- 'narrow': '[["pm-with", "hamlet@zulip.com"]]'},
+ 'narrow': '[["pm-with", "%s"]]' % (self.example_email("hamlet"),)},
sql)
sql_template = 'SELECT anon_1.message_id, anon_1.flags \nFROM (SELECT message_id, flags \nFROM zerver_usermessage JOIN zerver_message ON zerver_usermessage.message_id = zerver_message.id \nWHERE user_profile_id = {hamlet_id} AND recipient_id = {scotland_recipient} AND (flags & 2) != 0 AND message_id >= 0 ORDER BY message_id ASC \n LIMIT 10) AS anon_1 ORDER BY message_id ASC'
diff --git a/zerver/tests/test_presence.py b/zerver/tests/test_presence.py
index 4a5a1efd20..a6cf5eceb0 100644
--- a/zerver/tests/test_presence.py
+++ b/zerver/tests/test_presence.py
@@ -31,7 +31,7 @@ import ujson
class ActivityTest(ZulipTestCase):
def test_activity(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
client, _ = Client.objects.get_or_create(name='website')
query = '/json/users/me/pointer'
last_visit = timezone_now()
@@ -96,14 +96,14 @@ class UserPresenceModelTests(ZulipTestCase):
class UserPresenceTests(ZulipTestCase):
def test_invalid_presence(self):
# type: () -> None
- email = "hamlet@zulip.com"
+ email = self.example_email("hamlet")
self.login(email)
result = self.client_post("/json/users/me/presence", {'status': 'foo'})
self.assert_json_error(result, 'Invalid status: foo')
def test_set_idle(self):
# type: () -> None
- email = "hamlet@zulip.com"
+ email = self.example_email("hamlet")
self.login(email)
client = 'website'
@@ -113,7 +113,7 @@ class UserPresenceTests(ZulipTestCase):
self.assertEqual(json['presences'][email][client]['status'], 'idle')
self.assertIn('timestamp', json['presences'][email][client])
self.assertIsInstance(json['presences'][email][client]['timestamp'], int)
- self.assertEqual(list(json['presences'].keys()), ['hamlet@zulip.com'])
+ self.assertEqual(list(json['presences'].keys()), [self.example_email("hamlet")])
timestamp = json['presences'][email][client]['timestamp']
email = "othello@zulip.com"
@@ -121,21 +121,21 @@ class UserPresenceTests(ZulipTestCase):
result = self.client_post("/json/users/me/presence", {'status': 'idle'})
json = ujson.loads(result.content)
self.assertEqual(json['presences'][email][client]['status'], 'idle')
- self.assertEqual(json['presences']['hamlet@zulip.com'][client]['status'], 'idle')
- self.assertEqual(sorted(json['presences'].keys()), ['hamlet@zulip.com', 'othello@zulip.com'])
+ self.assertEqual(json['presences'][self.example_email("hamlet")][client]['status'], 'idle')
+ self.assertEqual(sorted(json['presences'].keys()), [self.example_email("hamlet"), 'othello@zulip.com'])
newer_timestamp = json['presences'][email][client]['timestamp']
self.assertGreaterEqual(newer_timestamp, timestamp)
def test_set_active(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
client = 'website'
result = self.client_post("/json/users/me/presence", {'status': 'idle'})
self.assert_json_success(result)
json = ujson.loads(result.content)
- self.assertEqual(json['presences']["hamlet@zulip.com"][client]['status'], 'idle')
+ self.assertEqual(json['presences'][self.example_email("hamlet")][client]['status'], 'idle')
email = "othello@zulip.com"
self.login("othello@zulip.com")
@@ -143,13 +143,13 @@ class UserPresenceTests(ZulipTestCase):
self.assert_json_success(result)
json = ujson.loads(result.content)
self.assertEqual(json['presences'][email][client]['status'], 'idle')
- self.assertEqual(json['presences']['hamlet@zulip.com'][client]['status'], 'idle')
+ self.assertEqual(json['presences'][self.example_email("hamlet")][client]['status'], 'idle')
result = self.client_post("/json/users/me/presence", {'status': 'active'})
self.assert_json_success(result)
json = ujson.loads(result.content)
self.assertEqual(json['presences'][email][client]['status'], 'active')
- self.assertEqual(json['presences']['hamlet@zulip.com'][client]['status'], 'idle')
+ self.assertEqual(json['presences'][self.example_email("hamlet")][client]['status'], 'idle')
def test_no_mit(self):
# type: () -> None
@@ -201,11 +201,11 @@ class UserPresenceTests(ZulipTestCase):
self.logout()
# Ensure we don't see hamlet@zulip.com information leakage
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_post("/json/users/me/presence", {'status': 'idle'})
self.assert_json_success(result)
json = ujson.loads(result.content)
- self.assertEqual(json['presences']["hamlet@zulip.com"]["website"]['status'], 'idle')
+ self.assertEqual(json['presences'][self.example_email("hamlet")]["website"]['status'], 'idle')
# We only want @zulip.com emails
for email in json['presences'].keys():
self.assertEqual(email_to_domain(email), 'zulip.com')
@@ -244,7 +244,7 @@ class SingleUserPresenceTests(ZulipTestCase):
self.assert_json_error(result, "No such user")
# Then, we check everything works
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_get("/json/users/othello@zulip.com/presence")
result_dict = ujson.loads(result.content)
self.assertEqual(
diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py
index 48ecff8275..5ce0f22863 100644
--- a/zerver/tests/test_push_notifications.py
+++ b/zerver/tests/test_push_notifications.py
@@ -117,7 +117,7 @@ class PushBouncerNotificationTest(BouncerTestCase):
**self.get_auth())
self.assert_json_error(result, "Missing 'token_kind' argument")
result = self.client_post(endpoint, {'token': token, 'token_kind': token_kind},
- **self.api_auth("hamlet@zulip.com"))
+ **self.api_auth(self.example_email("hamlet")))
self.assert_json_error(result, "Must validate with valid Zulip server API key")
def test_register_remote_push_user_paramas(self):
@@ -139,7 +139,7 @@ class PushBouncerNotificationTest(BouncerTestCase):
self.assert_json_error(result, "Missing 'user_id' argument")
result = self.client_post(endpoint, {'user_id': user_id, 'token_kind': token_kind,
'token': token},
- **self.api_auth("hamlet@zulip.com"))
+ **self.api_auth(self.example_email("hamlet")))
self.assert_json_error(result, "Must validate with valid Zulip server API key")
def test_remote_push_user_endpoints(self):
@@ -562,7 +562,7 @@ class TestGetGCMPayload(PushNotificationTest):
"time": apn.datetime_to_timestamp(message.pub_date),
"content": 'a' * 200 + '...',
"content_truncated": True,
- "sender_email": "hamlet@zulip.com",
+ "sender_email": self.example_email("hamlet"),
"sender_full_name": "King Hamlet",
"sender_avatar_url": apn.avatar_url(message.sender),
"recipient_type": "stream",
@@ -584,7 +584,7 @@ class TestGetGCMPayload(PushNotificationTest):
"time": apn.datetime_to_timestamp(message.pub_date),
"content": message.content,
"content_truncated": False,
- "sender_email": "hamlet@zulip.com",
+ "sender_email": self.example_email("hamlet"),
"sender_full_name": "King Hamlet",
"sender_avatar_url": apn.avatar_url(message.sender),
"recipient_type": "private",
diff --git a/zerver/tests/test_reactions.py b/zerver/tests/test_reactions.py
index cfdb2eda54..562502914c 100644
--- a/zerver/tests/test_reactions.py
+++ b/zerver/tests/test_reactions.py
@@ -16,7 +16,7 @@ class ReactionEmojiTest(ZulipTestCase):
"""
Sending reaction without emoji fails
"""
- sender = 'hamlet@zulip.com'
+ sender = self.example_email("hamlet")
result = self.client_put('/api/v1/messages/1/emoji_reactions/',
**self.api_auth(sender))
self.assertEqual(result.status_code, 400)
@@ -26,7 +26,7 @@ class ReactionEmojiTest(ZulipTestCase):
"""
Sending invalid emoji fails
"""
- sender = 'hamlet@zulip.com'
+ sender = self.example_email("hamlet")
result = self.client_put('/api/v1/messages/1/emoji_reactions/foo',
**self.api_auth(sender))
self.assert_json_error(result, "Emoji 'foo' does not exist")
@@ -36,7 +36,7 @@ class ReactionEmojiTest(ZulipTestCase):
"""
Removing invalid emoji fails
"""
- sender = 'hamlet@zulip.com'
+ sender = self.example_email("hamlet")
result = self.client_delete('/api/v1/messages/1/emoji_reactions/foo',
**self.api_auth(sender))
self.assert_json_error(result, "Emoji 'foo' does not exist")
@@ -46,7 +46,7 @@ class ReactionEmojiTest(ZulipTestCase):
"""
Reacting with valid emoji succeeds
"""
- sender = 'hamlet@zulip.com'
+ sender = self.example_email("hamlet")
result = self.client_put('/api/v1/messages/1/emoji_reactions/smile',
**self.api_auth(sender))
self.assert_json_success(result)
@@ -57,7 +57,7 @@ class ReactionEmojiTest(ZulipTestCase):
"""
Reacting with zulip emoji succeeds
"""
- sender = 'hamlet@zulip.com'
+ sender = self.example_email("hamlet")
result = self.client_put('/api/v1/messages/1/emoji_reactions/zulip',
**self.api_auth(sender))
self.assert_json_success(result)
@@ -96,7 +96,7 @@ class ReactionEmojiTest(ZulipTestCase):
"""
Reacting with valid realm emoji succeeds
"""
- sender = 'hamlet@zulip.com'
+ sender = self.example_email("hamlet")
emoji_name = 'my_emoji'
with get_test_image_file('img.png') as fp1:
emoji_data = {'f1': fp1}
@@ -120,7 +120,7 @@ class ReactionMessageIDTest(ZulipTestCase):
"""
Reacting without a message_id fails
"""
- sender = 'hamlet@zulip.com'
+ sender = self.example_email("hamlet")
result = self.client_put('/api/v1/messages//emoji_reactions/smile',
**self.api_auth(sender))
self.assertEqual(result.status_code, 404)
@@ -130,7 +130,7 @@ class ReactionMessageIDTest(ZulipTestCase):
"""
Reacting to an invalid message id fails
"""
- sender = 'hamlet@zulip.com'
+ sender = self.example_email("hamlet")
result = self.client_put('/api/v1/messages/-1/emoji_reactions/smile',
**self.api_auth(sender))
self.assertEqual(result.status_code, 404)
@@ -140,7 +140,7 @@ class ReactionMessageIDTest(ZulipTestCase):
"""
Reacting to a inaccessible (for instance, private) message fails
"""
- pm_sender = 'hamlet@zulip.com'
+ pm_sender = self.example_email("hamlet")
pm_recipient = 'othello@zulip.com'
reaction_sender = 'iago@zulip.com'
@@ -161,7 +161,7 @@ class ReactionTest(ZulipTestCase):
"""
Creating the same reaction twice fails
"""
- pm_sender = 'hamlet@zulip.com'
+ pm_sender = self.example_email("hamlet")
pm_recipient = 'othello@zulip.com'
reaction_sender = pm_recipient
@@ -185,7 +185,7 @@ class ReactionTest(ZulipTestCase):
"""
Removing a reaction twice fails
"""
- pm_sender = 'hamlet@zulip.com'
+ pm_sender = self.example_email("hamlet")
pm_recipient = 'othello@zulip.com'
reaction_sender = pm_recipient
diff --git a/zerver/tests/test_realm_domains.py b/zerver/tests/test_realm_domains.py
index 722f55f586..b2917320ce 100644
--- a/zerver/tests/test_realm_domains.py
+++ b/zerver/tests/test_realm_domains.py
@@ -33,7 +33,7 @@ class RealmDomainTest(ZulipTestCase):
def test_not_realm_admin(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_post("/json/realm/domains")
self.assert_json_error(result, 'Must be a realm administrator')
result = self.client_patch("/json/realm/domains/15")
diff --git a/zerver/tests/test_settings.py b/zerver/tests/test_settings.py
index d8fa54bf70..a136b21943 100644
--- a/zerver/tests/test_settings.py
+++ b/zerver/tests/test_settings.py
@@ -22,7 +22,7 @@ class ChangeSettingsTest(ZulipTestCase):
# are converted into check_for_toggle_param_patch.
def check_for_toggle_param(self, pattern, param):
# type: (str, str) -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
user_profile = self.example_user('hamlet')
json_result = self.client_post(pattern,
{param: ujson.dumps(True)})
@@ -42,7 +42,7 @@ class ChangeSettingsTest(ZulipTestCase):
# for check_for_toggle_param for PATCH.
def check_for_toggle_param_patch(self, pattern, param):
# type: (str, str) -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
user_profile = self.example_user('hamlet')
json_result = self.client_patch(pattern,
{param: ujson.dumps(True)})
@@ -64,12 +64,12 @@ class ChangeSettingsTest(ZulipTestCase):
A call to /json/settings/change with valid parameters changes the user's
settings correctly and returns correct values.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
json_result = self.client_post(
"/json/settings/change",
dict(
full_name='Foo Bar',
- old_password=initial_password('hamlet@zulip.com'),
+ old_password=initial_password(self.example_email("hamlet")),
new_password='foobar1',
confirm_password='foobar1',
))
@@ -79,7 +79,7 @@ class ChangeSettingsTest(ZulipTestCase):
self.assertEqual(self.example_user('hamlet').
full_name, "Foo Bar")
self.logout()
- self.login("hamlet@zulip.com", "foobar1")
+ self.login(self.example_email("hamlet"), "foobar1")
user_profile = self.example_user('hamlet')
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
@@ -114,7 +114,7 @@ class ChangeSettingsTest(ZulipTestCase):
def test_illegal_characters_in_name_changes(self):
# type: () -> None
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
self.login(email)
# Now try a name with invalid characters
@@ -161,7 +161,7 @@ class ChangeSettingsTest(ZulipTestCase):
"""
new_password and confirm_password must match
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_post(
"/json/settings/change",
dict(
@@ -176,7 +176,7 @@ class ChangeSettingsTest(ZulipTestCase):
"""
new_password and confirm_password must match
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_post(
"/json/settings/change",
dict(
@@ -193,7 +193,7 @@ class ChangeSettingsTest(ZulipTestCase):
to this API, or it should fail. (Eventually, we should
probably use a patch interface for these changes.)
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_post("/json/settings/change",
dict(old_password='ignored',))
self.assert_json_error(result, "No new data supplied")
diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py
index 621fdf1bc0..2412c4e5cb 100644
--- a/zerver/tests/test_signup.py
+++ b/zerver/tests/test_signup.py
@@ -71,7 +71,7 @@ class RedirectAndLogIntoSubdomainTestCase(ZulipTestCase):
# type: () -> None
realm = Realm.objects.all().first()
name = 'Hamlet'
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
response = redirect_and_log_into_subdomain(realm, name, email)
data = unsign_subdomain_cookie(response)
self.assertDictEqual(data, {'name': name, 'email': email,
@@ -113,7 +113,7 @@ class PasswordResetTest(ZulipTestCase):
def test_password_reset(self):
# type: () -> None
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
old_password = initial_password(email)
self.login(email)
@@ -157,7 +157,7 @@ class PasswordResetTest(ZulipTestCase):
def test_invalid_subdomain(self):
# type: () -> None
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
string_id = 'hamlet'
name = 'Hamlet'
do_create_realm(
@@ -189,7 +189,7 @@ class PasswordResetTest(ZulipTestCase):
def test_correct_subdomain(self):
# type: () -> None
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
string_id = 'zulip'
with self.settings(REALMS_HAVE_SUBDOMAINS=True):
@@ -236,13 +236,13 @@ class LoginTest(ZulipTestCase):
def test_login(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
user_profile = self.example_user('hamlet')
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
def test_login_bad_password(self):
# type: () -> None
- self.login("hamlet@zulip.com", password="wrongpassword", fails=True)
+ self.login(self.example_email("hamlet"), password="wrongpassword", fails=True)
self.assertIsNone(get_session_dict_user(self.client.session))
def test_login_nonexist_user(self):
@@ -297,12 +297,12 @@ class LoginTest(ZulipTestCase):
realm.deactivated = True
realm.save(update_fields=["deactivated"])
- result = self.login_with_return("hamlet@zulip.com")
+ result = self.login_with_return(self.example_email("hamlet"))
self.assert_in_response("has been deactivated", result)
def test_logout(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
# We use the logout API, not self.logout, to make sure we test
# the actual logout code path.
self.client_post('/accounts/logout/')
@@ -376,7 +376,7 @@ class InviteUserTest(ZulipTestCase):
A call to /json/invite_users with valid parameters causes an invitation
email to be sent.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
invitee = "alice-test@zulip.com"
self.assert_json_success(self.invite(invitee, ["Denmark"]))
self.assertTrue(find_key_by_email(invitee))
@@ -388,7 +388,7 @@ class InviteUserTest(ZulipTestCase):
A call to /json/invite_users with valid parameters causes an invitation
email to be sent.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
invitee = "alice-test@zulip.com"
body = "Custom Text."
self.assert_json_success(self.invite(invitee, ["Denmark"], body))
@@ -401,7 +401,7 @@ class InviteUserTest(ZulipTestCase):
A call to /json/invite_users with valid parameters causes an invitation
email to be sent.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
email = "alice-test@zulip.com"
invitee = "Alice Test <{}>".format(email)
self.assert_json_success(self.invite(invitee, ["Denmark"]))
@@ -414,7 +414,7 @@ class InviteUserTest(ZulipTestCase):
A call to /json/invite_users with valid parameters causes an invitation
email to be sent.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
email = "alice-test@zulip.com"
email2 = "bob-test@zulip.com"
invitee = "Alice Test <{}>, {}".format(email, email2)
@@ -435,7 +435,7 @@ class InviteUserTest(ZulipTestCase):
realm.notifications_stream = notifications_stream
realm.save()
- self.login('hamlet@zulip.com')
+ self.login(self.example_email("hamlet"))
invitee = 'alice-test@zulip.com'
self.assert_json_success(self.invite(invitee, ['Denmark']))
self.assertTrue(find_key_by_email(invitee))
@@ -456,9 +456,9 @@ class InviteUserTest(ZulipTestCase):
private_stream_name = "Secret"
self.make_stream(private_stream_name, invite_only=True)
self.subscribe_to_stream(user_profile.email, private_stream_name)
- public_msg_id = self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM,
+ public_msg_id = self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM,
"Public topic", "Public message")
- secret_msg_id = self.send_message("hamlet@zulip.com", private_stream_name, Recipient.STREAM,
+ secret_msg_id = self.send_message(self.example_email("hamlet"), private_stream_name, Recipient.STREAM,
"Secret topic", "Secret message")
invitee = self.nonreg_email('alice')
self.assert_json_success(self.invite(invitee, [private_stream_name, "Denmark"]))
@@ -476,7 +476,7 @@ class InviteUserTest(ZulipTestCase):
"""
Invites multiple users with a variety of delimiters.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
# Intentionally use a weird string.
self.assert_json_success(self.invite(
"""bob-test@zulip.com, carol-test@zulip.com,
@@ -494,7 +494,7 @@ earl-test@zulip.com""", ["Denmark"]))
"""
Tests inviting with various missing or invalid parameters.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
self.assert_json_error(
self.client_post("/json/invite_users", {"invitee_emails": "foo@zulip.com",
"custom_body": ''}),
@@ -516,7 +516,7 @@ earl-test@zulip.com""", ["Denmark"]))
"""
Tests inviting to a non-existent stream.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
self.assert_json_error(self.invite("iago-test@zulip.com", ["NotARealStream"]),
"Stream does not exist: NotARealStream. No invites were sent.")
self.check_sent_emails([])
@@ -526,16 +526,16 @@ earl-test@zulip.com""", ["Denmark"]))
"""
If you invite an address already using Zulip, no invitation is sent.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
self.assert_json_error(
self.client_post("/json/invite_users",
- {"invitee_emails": "hamlet@zulip.com",
+ {"invitee_emails": self.example_email("hamlet"),
"stream": ["Denmark"],
"custom_body": ''}),
"We weren't able to invite anyone.")
self.assertRaises(PreregistrationUser.DoesNotExist,
lambda: PreregistrationUser.objects.get(
- email="hamlet@zulip.com"))
+ email=self.example_email("hamlet")))
self.check_sent_emails([])
def test_invite_some_existing_some_new(self):
@@ -544,8 +544,8 @@ earl-test@zulip.com""", ["Denmark"]))
If you invite a mix of already existing and new users, invitations are
only sent to the new users.
"""
- self.login("hamlet@zulip.com")
- existing = [u"hamlet@zulip.com", u"othello@zulip.com"]
+ self.login(self.example_email("hamlet"))
+ existing = [self.example_email("hamlet"), u"othello@zulip.com"]
new = [u"foo-test@zulip.com", u"bar-test@zulip.com"]
result = self.client_post("/json/invite_users",
@@ -580,7 +580,7 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
zulip_realm.restricted_to_domain = True
zulip_realm.save()
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
external_address = "foo@example.com"
self.assert_json_error(
@@ -597,7 +597,7 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
zulip_realm.restricted_to_domain = False
zulip_realm.save()
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
external_address = "foo@example.com"
self.assert_json_success(self.invite(external_address, ["Denmark"]))
@@ -615,7 +615,7 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
zulip_realm.restricted_to_domain = False
zulip_realm.save()
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
external_address = "foo@example.com"
self.assert_json_success(self.invite(external_address, ["Denmark"]))
@@ -633,19 +633,19 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
"""
Inviting someone to streams with non-ASCII characters succeeds.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
invitee = "alice-test@zulip.com"
stream_name = u"hümbüǵ"
# Make sure we're subscribed before inviting someone.
- self.subscribe_to_stream("hamlet@zulip.com", stream_name)
+ self.subscribe_to_stream(self.example_email("hamlet"), stream_name)
self.assert_json_success(self.invite(invitee, [stream_name]))
def test_refer_friend(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
user = self.example_user('hamlet')
user.invites_granted = 1
user.invites_used = 0
@@ -663,7 +663,7 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
def test_refer_friend_no_email(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
user = self.example_user('hamlet')
user.invites_granted = 1
user.invites_used = 0
@@ -678,7 +678,7 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
def test_refer_friend_no_invites(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
user = self.example_user('hamlet')
user.invites_granted = 1
user.invites_used = 1
@@ -794,7 +794,7 @@ class EmailUnsubscribeTests(ZulipTestCase):
self.assertEqual(result.status_code, 200)
# Circumvent user_profile caching.
- user_profile = UserProfile.objects.get(email="hamlet@zulip.com")
+ user_profile = UserProfile.objects.get(email=self.example_email("hamlet"))
self.assertFalse(user_profile.enable_offline_email_notifications)
def test_welcome_unsubscribe(self):
@@ -803,7 +803,7 @@ class EmailUnsubscribeTests(ZulipTestCase):
We provide one-click unsubscribe links in welcome e-mails that you can
click even when logged out to stop receiving them.
"""
- email = "hamlet@zulip.com"
+ email = self.example_email("hamlet")
user_profile = self.example_user('hamlet')
# Simulate a new user signing up, which enqueues 2 welcome e-mails.
@@ -829,7 +829,7 @@ class EmailUnsubscribeTests(ZulipTestCase):
Unsubscribing from these emails also dequeues any digest email jobs that
have been queued.
"""
- email = "hamlet@zulip.com"
+ email = self.example_email("hamlet")
user_profile = self.example_user('hamlet')
self.assertTrue(user_profile.enable_digest_emails)
@@ -848,7 +848,7 @@ class EmailUnsubscribeTests(ZulipTestCase):
# The setting is toggled off, and scheduled jobs have been removed.
self.assertEqual(result.status_code, 200)
# Circumvent user_profile caching.
- user_profile = UserProfile.objects.get(email="hamlet@zulip.com")
+ user_profile = UserProfile.objects.get(email=self.example_email("hamlet"))
self.assertFalse(user_profile.enable_digest_emails)
self.assertEqual(0, len(ScheduledJob.objects.filter(
type=ScheduledJob.EMAIL, filter_string__iexact=email)))
@@ -910,7 +910,7 @@ class RealmCreationTest(ZulipTestCase):
a login page.
"""
with self.settings(OPEN_REALM_CREATION=True):
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
result = self.client_post('/create_realm/', {'email': email})
self.assertEqual(result.status_code, 302)
self.assertIn('login', result['Location'])
@@ -1053,7 +1053,7 @@ class UserSignUpTest(ZulipTestCase):
"""
Check if signing up with an active email redirects to a login page.
"""
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
result = self.client_post('/accounts/home/', {'email': email})
self.assertEqual(result.status_code, 302)
self.assertIn('login', result['Location'])
@@ -1617,7 +1617,7 @@ class DeactivateUserTest(ZulipTestCase):
def test_deactivate_user(self):
# type: () -> None
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
self.login(email)
user = self.example_user('hamlet')
self.assertTrue(user.is_active)
@@ -1638,7 +1638,7 @@ class DeactivateUserTest(ZulipTestCase):
user = self.example_user('iago')
self.assertTrue(user.is_active)
self.assertTrue(user.is_realm_admin)
- email = 'hamlet@zulip.com'
+ email = self.example_email("hamlet")
user_2 = self.example_user('hamlet')
do_change_is_admin(user_2, True)
self.assertTrue(user_2.is_realm_admin)
@@ -1726,7 +1726,7 @@ class TestFindMyTeam(ZulipTestCase):
def test_find_team_one_email(self):
# type: () -> None
- data = {'emails': 'hamlet@zulip.com'}
+ data = {'emails': self.example_email("hamlet")}
result = self.client_post('/find_my_team/', data)
self.assertEqual(result.status_code, 302)
self.assertEqual(result.url, '/find_my_team/?emails=hamlet%40zulip.com')
diff --git a/zerver/tests/test_typing.py b/zerver/tests/test_typing.py
index d813011e8f..1c935becac 100644
--- a/zerver/tests/test_typing.py
+++ b/zerver/tests/test_typing.py
@@ -17,7 +17,7 @@ class TypingNotificationOperatorTest(ZulipTestCase):
"""
Sending typing notification without op parameter fails
"""
- sender = 'hamlet@zulip.com'
+ sender = self.example_email("hamlet")
recipient = 'othello@zulip.com'
result = self.client_post('/api/v1/typing', {'to': recipient},
**self.api_auth(sender))
@@ -28,7 +28,7 @@ class TypingNotificationOperatorTest(ZulipTestCase):
"""
Sending typing notification with invalid value for op parameter fails
"""
- sender = 'hamlet@zulip.com'
+ sender = self.example_email("hamlet")
recipient = 'othello@zulip.com'
result = self.client_post('/api/v1/typing', {'to': recipient, 'op': 'foo'},
**self.api_auth(sender))
@@ -40,7 +40,7 @@ class TypingNotificationRecipientsTest(ZulipTestCase):
"""
Sending typing notification without recipient fails
"""
- sender = 'hamlet@zulip.com'
+ sender = self.example_email("hamlet")
result = self.client_post('/api/v1/typing', {'op': 'start'},
**self.api_auth(sender))
self.assert_json_error(result, 'Missing parameter: \'to\' (recipient)')
@@ -50,7 +50,7 @@ class TypingNotificationRecipientsTest(ZulipTestCase):
"""
Sending typing notification to invalid recipient fails
"""
- sender = 'hamlet@zulip.com'
+ sender = self.example_email("hamlet")
invalid = 'invalid email'
result = self.client_post('/api/v1/typing', {'op': 'start', 'to': invalid},
**self.api_auth(sender))
diff --git a/zerver/tests/test_unread.py b/zerver/tests/test_unread.py
index 828667183f..284be08845 100644
--- a/zerver/tests/test_unread.py
+++ b/zerver/tests/test_unread.py
@@ -21,7 +21,7 @@ class PointerTest(ZulipTestCase):
Posting a pointer to /update (in the form {"pointer": pointer}) changes
the pointer we store for your UserProfile.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
self.assertEqual(self.example_user('hamlet').pointer, -1)
msg_id = self.send_message("othello@zulip.com", "Verona", Recipient.STREAM)
result = self.client_post("/json/users/me/pointer", {"pointer": msg_id})
@@ -48,7 +48,7 @@ class PointerTest(ZulipTestCase):
Posting json to /json/users/me/pointer which does not contain a pointer key/value pair
returns a 400 and error message.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
self.assertEqual(self.example_user('hamlet').pointer, -1)
result = self.client_post("/json/users/me/pointer", {"foo": 1})
self.assert_json_error(result, "Missing 'pointer' argument")
@@ -60,7 +60,7 @@ class PointerTest(ZulipTestCase):
Posting json to /json/users/me/pointer with an invalid pointer returns a 400 and error
message.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
self.assertEqual(self.example_user('hamlet').pointer, -1)
result = self.client_post("/json/users/me/pointer", {"pointer": "foo"})
self.assert_json_error(result, "Bad value for 'pointer': foo")
@@ -72,7 +72,7 @@ class PointerTest(ZulipTestCase):
Posting json to /json/users/me/pointer with an out of range (< 0) pointer returns a 400
and error message.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
self.assertEqual(self.example_user('hamlet').pointer, -1)
result = self.client_post("/json/users/me/pointer", {"pointer": -2})
self.assert_json_error(result, "Bad value for 'pointer': -2")
@@ -85,7 +85,7 @@ class PointerTest(ZulipTestCase):
return an unread message older than the current pointer, when there's
no narrow set.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
# Ensure the pointer is not set (-1)
self.assertEqual(self.example_user('hamlet').pointer, -1)
# Mark all existing messages as read
@@ -164,26 +164,26 @@ class UnreadCountTests(ZulipTestCase):
# type: () -> None
self.unread_msg_ids = [
self.send_message(
- "iago@zulip.com", "hamlet@zulip.com", Recipient.PERSONAL, "hello"),
+ "iago@zulip.com", self.example_email("hamlet"), Recipient.PERSONAL, "hello"),
self.send_message(
- "iago@zulip.com", "hamlet@zulip.com", Recipient.PERSONAL, "hello2")]
+ "iago@zulip.com", self.example_email("hamlet"), Recipient.PERSONAL, "hello2")]
# Sending a new message results in unread UserMessages being created
def test_new_message(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
content = "Test message for unset read bit"
- last_msg = self.send_message("hamlet@zulip.com", "Verona", Recipient.STREAM, content)
+ last_msg = self.send_message(self.example_email("hamlet"), "Verona", Recipient.STREAM, content)
user_messages = list(UserMessage.objects.filter(message=last_msg))
self.assertEqual(len(user_messages) > 0, True)
for um in user_messages:
self.assertEqual(um.message.content, content)
- if um.user_profile.email != "hamlet@zulip.com":
+ if um.user_profile.email != self.example_email("hamlet"):
self.assertFalse(um.flags.read)
def test_update_flags(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_post("/json/messages/flags",
{"messages": ujson.dumps(self.unread_msg_ids),
@@ -213,11 +213,11 @@ class UnreadCountTests(ZulipTestCase):
def test_update_all_flags(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
- message_ids = [self.send_message("hamlet@zulip.com", "iago@zulip.com",
+ message_ids = [self.send_message(self.example_email("hamlet"), "iago@zulip.com",
Recipient.PERSONAL, "test"),
- self.send_message("hamlet@zulip.com", "cordelia@zulip.com",
+ self.send_message(self.example_email("hamlet"), "cordelia@zulip.com",
Recipient.PERSONAL, "test2")]
result = self.client_post("/json/messages/flags", {"messages": ujson.dumps(message_ids),
@@ -236,13 +236,13 @@ class UnreadCountTests(ZulipTestCase):
def test_mark_all_in_stream_read(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
user_profile = self.example_user('hamlet')
self.subscribe_to_stream(user_profile.email, "test_stream", user_profile.realm)
self.subscribe_to_stream("cordelia@zulip.com", "test_stream", user_profile.realm)
- message_id = self.send_message("hamlet@zulip.com", "test_stream", Recipient.STREAM, "hello")
- unrelated_message_id = self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM, "hello")
+ message_id = self.send_message(self.example_email("hamlet"), "test_stream", Recipient.STREAM, "hello")
+ unrelated_message_id = self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, "hello")
events = [] # type: List[Dict[str, Any]]
with tornado_redirected_to_list(events):
@@ -266,19 +266,19 @@ class UnreadCountTests(ZulipTestCase):
um = list(UserMessage.objects.filter(message=message_id))
for msg in um:
- if msg.user_profile.email == "hamlet@zulip.com":
+ if msg.user_profile.email == self.example_email("hamlet"):
self.assertTrue(msg.flags.read)
else:
self.assertFalse(msg.flags.read)
unrelated_messages = list(UserMessage.objects.filter(message=unrelated_message_id))
for msg in unrelated_messages:
- if msg.user_profile.email == "hamlet@zulip.com":
+ if msg.user_profile.email == self.example_email("hamlet"):
self.assertFalse(msg.flags.read)
def test_mark_all_in_invalid_stream_read(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
invalid_stream_name = ""
result = self.client_post("/json/messages/flags", {"messages": ujson.dumps([]),
"op": "add",
@@ -288,12 +288,12 @@ class UnreadCountTests(ZulipTestCase):
def test_mark_all_in_stream_topic_read(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
user_profile = self.example_user('hamlet')
self.subscribe_to_stream(user_profile.email, "test_stream", user_profile.realm)
- message_id = self.send_message("hamlet@zulip.com", "test_stream", Recipient.STREAM, "hello", "test_topic")
- unrelated_message_id = self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM, "hello", "Denmark2")
+ message_id = self.send_message(self.example_email("hamlet"), "test_stream", Recipient.STREAM, "hello", "test_topic")
+ unrelated_message_id = self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, "hello", "Denmark2")
events = [] # type: List[Dict[str, Any]]
with tornado_redirected_to_list(events):
result = self.client_post("/json/messages/flags", {"messages": ujson.dumps([]),
@@ -317,17 +317,17 @@ class UnreadCountTests(ZulipTestCase):
um = list(UserMessage.objects.filter(message=message_id))
for msg in um:
- if msg.user_profile.email == "hamlet@zulip.com":
+ if msg.user_profile.email == self.example_email("hamlet"):
self.assertTrue(msg.flags.read)
unrelated_messages = list(UserMessage.objects.filter(message=unrelated_message_id))
for msg in unrelated_messages:
- if msg.user_profile.email == "hamlet@zulip.com":
+ if msg.user_profile.email == self.example_email("hamlet"):
self.assertFalse(msg.flags.read)
def test_mark_all_in_invalid_topic_read(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
invalid_topic_name = "abc"
result = self.client_post("/json/messages/flags", {"messages": ujson.dumps([]),
"op": "add",
diff --git a/zerver/tests/test_upload.py b/zerver/tests/test_upload.py
index ea57b4c33b..e818b46c38 100644
--- a/zerver/tests/test_upload.py
+++ b/zerver/tests/test_upload.py
@@ -68,7 +68,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
fp.name = "zulip.txt"
# Upload file via API
- auth_headers = self.api_auth('hamlet@zulip.com')
+ auth_headers = self.api_auth(self.example_email("hamlet"))
result = self.client_post('/api/v1/user_uploads', {'file': fp}, **auth_headers)
json = ujson.loads(result.content)
self.assertIn("uri", json)
@@ -83,7 +83,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
self.assertEqual(b"zulip!", data)
# Files uploaded through the API should be accesible via the web client
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
self.assert_url_serves_contents_of_file(uri, b"zulip!")
def test_filename_encoding(self):
@@ -129,7 +129,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
"""
Attempting to upload big files should fail.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
fp = StringIO("bah!")
fp.name = "a.txt"
@@ -144,7 +144,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
"""
Attempting to upload two files should fail.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
fp = StringIO("bah!")
fp.name = "a.txt"
fp2 = StringIO("pshaw!")
@@ -158,14 +158,14 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
"""
Calling this endpoint with no files should fail.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_post("/json/upload_file")
self.assert_json_error(result, "You must specify a file to upload")
def test_download_non_existent_file(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
response = self.client_get('/user_uploads/unk/nonexistent_file')
self.assertEqual(response.status_code, 404)
self.assertIn('File not found', str(response.content))
@@ -179,7 +179,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
entry in the database. This entry will be marked unclaimed till a message
refers it.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
fp = StringIO("zulip!")
fp.name = "zulip.txt"
@@ -199,14 +199,14 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
entry = Attachment.objects.get(file_name='zulip.txt')
self.assertEqual(entry.is_claimed(), False)
- self.subscribe_to_stream("hamlet@zulip.com", "Denmark")
+ self.subscribe_to_stream(self.example_email("hamlet"), "Denmark")
body = "First message ...[zulip.txt](http://localhost:9991" + uri + ")"
- self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM, body, "test")
+ self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, body, "test")
self.assertIn('title="zulip.txt"', self.get_last_message().rendered_content)
def test_file_download_unauthed(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
fp = StringIO("zulip!")
fp.name = "zulip.txt"
result = self.client_post("/json/upload_file", {'file': fp})
@@ -223,7 +223,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
'''
Trying to download deleted files should return 404 error
'''
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
fp = StringIO("zulip!")
fp.name = "zulip.txt"
result = self.client_post("/json/upload_file", {'file': fp})
@@ -240,7 +240,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
'''
Trying to download a file that was never uploaded will return a json_error
'''
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
response = self.client_get("http://localhost:9991/user_uploads/1/ff/gg/abc.py")
self.assertEqual(response.status_code, 404)
self.assert_in_response('File not found.', response)
@@ -248,7 +248,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
def test_delete_old_unclaimed_attachments(self):
# type: () -> None
# Upload some files and make them older than a weeek
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
d1 = StringIO("zulip!")
d1.name = "dummy_1.txt"
result = self.client_post("/json/upload_file", {'file': d1})
@@ -273,9 +273,9 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
d2_attachment.save()
# Send message refering only dummy_1
- self.subscribe_to_stream("hamlet@zulip.com", "Denmark")
+ self.subscribe_to_stream(self.example_email("hamlet"), "Denmark")
body = "Some files here ...[zulip.txt](http://localhost:9991/user_uploads/" + d1_path_id + ")"
- self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM, body, "test")
+ self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, body, "test")
# dummy_2 should not exist in database or the uploads folder
do_delete_old_unclaimed_attachments(2)
@@ -284,9 +284,9 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
def test_attachment_url_without_upload(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
body = "Test message ...[zulip.txt](http://localhost:9991/user_uploads/1/64/fake_path_id.txt)"
- self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM, body, "test")
+ self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, body, "test")
self.assertFalse(Attachment.objects.filter(path_id = "1/64/fake_path_id.txt").exists())
def test_multiple_claim_attachments(self):
@@ -295,7 +295,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
This test tries to claim the same attachment twice. The messages field in
the Attachment model should have both the messages in its entry.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
d1 = StringIO("zulip!")
d1.name = "dummy_1.txt"
result = self.client_post("/json/upload_file", {'file': d1})
@@ -303,11 +303,11 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
uri = json["uri"]
d1_path_id = re.sub('/user_uploads/', '', uri)
- self.subscribe_to_stream("hamlet@zulip.com", "Denmark")
+ self.subscribe_to_stream(self.example_email("hamlet"), "Denmark")
body = "First message ...[zulip.txt](http://localhost:9991/user_uploads/" + d1_path_id + ")"
- self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM, body, "test")
+ self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, body, "test")
body = "Second message ...[zulip.txt](http://localhost:9991/user_uploads/" + d1_path_id + ")"
- self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM, body, "test")
+ self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, body, "test")
self.assertEqual(Attachment.objects.get(path_id=d1_path_id).messages.count(), 2)
@@ -315,7 +315,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
# type: () -> None
"""This test tries to claim the same attachment more than once, first
with a private stream and then with differnet recipients."""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
d1 = StringIO("zulip!")
d1.name = "dummy_1.txt"
result = self.client_post("/json/upload_file", {'file': d1})
@@ -324,11 +324,11 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
d1_path_id = re.sub('/user_uploads/', '', uri)
self.make_stream("private_stream", invite_only=True)
- self.subscribe_to_stream("hamlet@zulip.com", "private_stream")
+ self.subscribe_to_stream(self.example_email("hamlet"), "private_stream")
# First, send the mesasge to the new private stream.
body = "First message ...[zulip.txt](http://localhost:9991/user_uploads/" + d1_path_id + ")"
- self.send_message("hamlet@zulip.com", "private_stream", Recipient.STREAM, body, "test")
+ self.send_message(self.example_email("hamlet"), "private_stream", Recipient.STREAM, body, "test")
self.assertFalse(Attachment.objects.get(path_id=d1_path_id).is_realm_public)
self.assertEqual(Attachment.objects.get(path_id=d1_path_id).messages.count(), 1)
@@ -340,7 +340,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
# Then, have the owner PM it to another user, giving that other user access.
body = "Second message ...[zulip.txt](http://localhost:9991/user_uploads/" + d1_path_id + ")"
- self.send_message("hamlet@zulip.com", "othello@zulip.com", Recipient.PERSONAL, body, "test")
+ self.send_message(self.example_email("hamlet"), "othello@zulip.com", Recipient.PERSONAL, body, "test")
self.assertEqual(Attachment.objects.get(path_id=d1_path_id).messages.count(), 2)
self.assertFalse(Attachment.objects.get(path_id=d1_path_id).is_realm_public)
@@ -359,7 +359,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
f3 = StringIO("file3")
f3.name = "file3.txt"
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_post("/json/upload_file", {'file': f1})
json = ujson.loads(result.content)
uri = json["uri"]
@@ -370,10 +370,10 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
uri = json["uri"]
f2_path_id = re.sub('/user_uploads/', '', uri)
- self.subscribe_to_stream("hamlet@zulip.com", "test")
+ self.subscribe_to_stream(self.example_email("hamlet"), "test")
body = ("[f1.txt](http://localhost:9991/user_uploads/" + f1_path_id + ")"
"[f2.txt](http://localhost:9991/user_uploads/" + f2_path_id + ")")
- msg_id = self.send_message("hamlet@zulip.com", "test", Recipient.STREAM, body, "test")
+ msg_id = self.send_message(self.example_email("hamlet"), "test", Recipient.STREAM, body, "test")
result = self.client_post("/json/upload_file", {'file': f3})
json = ujson.loads(result.content)
@@ -418,7 +418,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
"""
Unicode filenames should be processed correctly.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
for expected in ["Здравейте.txt", "test"]:
fp = StringIO("bah!")
fp.name = urllib.parse.quote(expected)
@@ -432,7 +432,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
"""
User quote for uploading should not be exceeded
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
d1 = StringIO("zulip!")
d1.name = "dummy_1.txt"
@@ -516,7 +516,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
def test_file_download_authorization_invite_only(self):
# type: () -> None
- subscribed_users = ["hamlet@zulip.com", "iago@zulip.com"]
+ subscribed_users = [self.example_email("hamlet"), "iago@zulip.com"]
unsubscribed_users = ["othello@zulip.com", "prospero@zulip.com"]
for user in subscribed_users:
self.subscribe_to_stream(user, "test-subscribe")
@@ -526,7 +526,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
stream.invite_only = True
stream.save()
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
fp = StringIO("zulip!")
fp.name = "zulip.txt"
result = self.client_post("/json/upload_file", {'file': fp})
@@ -534,7 +534,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
uri = json["uri"]
fp_path_id = re.sub('/user_uploads/', '', uri)
body = "First message ...[zulip.txt](http://localhost:9991/user_uploads/" + fp_path_id + ")"
- self.send_message("hamlet@zulip.com", "test-subscribe", Recipient.STREAM, body, "test")
+ self.send_message(self.example_email("hamlet"), "test-subscribe", Recipient.STREAM, body, "test")
self.logout()
# Subscribed user should be able to view file
@@ -556,12 +556,12 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
def test_file_download_authorization_public(self):
# type: () -> None
- subscribed_users = ["hamlet@zulip.com", "iago@zulip.com"]
+ subscribed_users = [self.example_email("hamlet"), "iago@zulip.com"]
unsubscribed_users = ["othello@zulip.com", "prospero@zulip.com"]
for user in subscribed_users:
self.subscribe_to_stream(user, "test-subscribe")
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
fp = StringIO("zulip!")
fp.name = "zulip.txt"
result = self.client_post("/json/upload_file", {'file': fp})
@@ -569,7 +569,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
uri = json["uri"]
fp_path_id = re.sub('/user_uploads/', '', uri)
body = "First message ...[zulip.txt](http://localhost:9991/user_uploads/" + fp_path_id + ")"
- self.send_message("hamlet@zulip.com", "test-subscribe", Recipient.STREAM, body, "test")
+ self.send_message(self.example_email("hamlet"), "test-subscribe", Recipient.STREAM, body, "test")
self.logout()
# Now all users should be able to access the files
@@ -611,7 +611,7 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
"""
Attempting to upload two files should fail.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
with get_test_image_file('img.png') as fp1, \
get_test_image_file('img.png') as fp2:
result = self.client_put_multipart("/json/users/me/avatar", {'f1': fp1, 'f2': fp2})
@@ -622,7 +622,7 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
"""
Calling this endpoint with no files should fail.
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
result = self.client_put_multipart("/json/users/me/avatar")
self.assert_json_error(result, "You must upload exactly one avatar.")
@@ -637,7 +637,7 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
def test_get_gravatar_avatar(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
cordelia = self.example_user('cordelia')
cordelia.avatar_source = UserProfile.AVATAR_FROM_GRAVATAR
@@ -654,7 +654,7 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
def test_get_user_avatar(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
cordelia = self.example_user('cordelia')
cordelia.avatar_source = UserProfile.AVATAR_FROM_USER
@@ -669,7 +669,7 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
def test_get_user_avatar_medium(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
cordelia = self.example_user('cordelia')
cordelia.avatar_source = UserProfile.AVATAR_FROM_USER
@@ -687,7 +687,7 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
# It's debatable whether we should generate avatars for non-users,
# but this test just validates the current code's behavior.
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
response = self.client_get("/avatar/nonexistent_user@zulip.com?foo=bar")
redirect_url = response['Location']
@@ -703,7 +703,7 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
for fname, rfname in self.correct_files:
# TODO: use self.subTest once we're exclusively on python 3 by uncommenting the line below.
# with self.subTest(fname=fname):
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
with get_test_image_file(fname) as fp:
result = self.client_put_multipart("/json/users/me/avatar", {'file': fp})
@@ -742,7 +742,7 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
"""
for fname in self.corrupt_files:
# with self.subTest(fname=fname):
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
with get_test_image_file(fname) as fp:
result = self.client_put_multipart("/json/users/me/avatar", {'file': fp})
@@ -755,7 +755,7 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
"""
A DELETE request to /json/users/me/avatar should delete the user avatar and return gravatar URL
"""
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
hamlet = self.example_user('hamlet')
hamlet.avatar_source = UserProfile.AVATAR_FROM_USER
hamlet.save()
@@ -773,7 +773,7 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
def test_avatar_upload_file_size_error(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
with get_test_image_file(self.correct_files[0][0]) as fp:
with self.settings(MAX_AVATAR_FILE_SIZE=0):
result = self.client_put_multipart("/json/users/me/avatar", {'file': fp})
@@ -824,14 +824,14 @@ class RealmIconTest(UploadSerializeMixin, ZulipTestCase):
def test_no_admin_user_upload(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
with get_test_image_file(self.correct_files[0][0]) as fp:
result = self.client_put_multipart("/json/realm/icon", {'file': fp})
self.assert_json_error(result, 'Must be a realm administrator')
def test_get_gravatar_icon(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
realm = get_realm('zulip')
realm.icon_source = Realm.ICON_FROM_GRAVATAR
realm.save()
@@ -847,7 +847,7 @@ class RealmIconTest(UploadSerializeMixin, ZulipTestCase):
def test_get_realm_icon(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
realm = get_realm('zulip')
realm.icon_source = Realm.ICON_UPLOADED
@@ -954,7 +954,7 @@ class LocalStorageTest(UploadSerializeMixin, ZulipTestCase):
def test_delete_message_image_local(self):
# type: () -> None
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
fp = StringIO("zulip!")
fp.name = "zulip.txt"
result = self.client_post("/json/upload_file", {'file': fp})
@@ -1003,9 +1003,9 @@ class S3Test(ZulipTestCase):
uploaded_file = Attachment.objects.get(owner=user_profile, path_id=path_id)
self.assertEqual(len(b"zulip!"), uploaded_file.size)
- self.subscribe_to_stream("hamlet@zulip.com", "Denmark")
+ self.subscribe_to_stream(self.example_email("hamlet"), "Denmark")
body = "First message ...[zulip.txt](http://localhost:9991" + uri + ")"
- self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM, body, "test")
+ self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, body, "test")
self.assertIn('title="dummy.txt"', self.get_last_message().rendered_content)
@use_s3_backend
@@ -1029,7 +1029,7 @@ class S3Test(ZulipTestCase):
conn = S3Connection(settings.S3_KEY, settings.S3_SECRET_KEY)
conn.create_bucket(settings.S3_AUTH_UPLOADS_BUCKET)
- self.login("hamlet@zulip.com")
+ self.login(self.example_email("hamlet"))
fp = StringIO("zulip!")
fp.name = "zulip.txt"
@@ -1046,9 +1046,9 @@ class S3Test(ZulipTestCase):
self.assertEqual(b"zulip!", urllib.request.urlopen(redirect_url).read().strip()) # type: ignore # six.moves.urllib.request.urlopen is not defined in typeshed
- self.subscribe_to_stream("hamlet@zulip.com", "Denmark")
+ self.subscribe_to_stream(self.example_email("hamlet"), "Denmark")
body = "First message ...[zulip.txt](http://localhost:9991" + uri + ")"
- self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM, body, "test")
+ self.send_message(self.example_email("hamlet"), "Denmark", Recipient.STREAM, body, "test")
self.assertIn('title="zulip.txt"', self.get_last_message().rendered_content)
class UploadTitleTests(TestCase):
diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py
index ee0d0ae163..ff59fd5425 100644
--- a/zerver/tests/test_users.py
+++ b/zerver/tests/test_users.py
@@ -61,7 +61,7 @@ class PermissionTest(ZulipTestCase):
def test_updating_non_existent_user(self):
# type: () -> None
- self.login('hamlet@zulip.com')
+ self.login(self.example_email("hamlet"))
admin = self.example_user('hamlet')
do_change_is_admin(admin, True)
@@ -70,7 +70,7 @@ class PermissionTest(ZulipTestCase):
def test_admin_api(self):
# type: () -> None
- self.login('hamlet@zulip.com')
+ self.login(self.example_email("hamlet"))
admin = self.example_user('hamlet')
user = self.example_user('othello')
realm = admin.realm
@@ -80,7 +80,7 @@ class PermissionTest(ZulipTestCase):
result = self.client_get('/json/users')
self.assert_json_success(result)
members = ujson.loads(result.content)['members']
- hamlet = find_dict(members, 'email', 'hamlet@zulip.com')
+ hamlet = find_dict(members, 'email', self.example_email("hamlet"))
self.assertTrue(hamlet['is_admin'])
othello = find_dict(members, 'email', 'othello@zulip.com')
self.assertFalse(othello['is_admin'])
@@ -120,7 +120,7 @@ class PermissionTest(ZulipTestCase):
admin_users = realm.get_admin_users()
self.assertFalse(admin in admin_users)
person = events[0]['event']['person']
- self.assertEqual(person['email'], 'hamlet@zulip.com')
+ self.assertEqual(person['email'], self.example_email("hamlet"))
self.assertEqual(person['is_admin'], False)
with tornado_redirected_to_list([]):
result = self.client_patch('/json/users/iago@zulip.com', req)
@@ -143,7 +143,7 @@ class PermissionTest(ZulipTestCase):
def test_non_admin_cannot_change_full_name(self):
# type: () -> None
- self.login('hamlet@zulip.com')
+ self.login(self.example_email("hamlet"))
req = dict(full_name=ujson.dumps('new name'))
result = self.client_patch('/json/users/othello@zulip.com', req)
self.assert_json_error(result, 'Insufficient permission')
@@ -253,7 +253,7 @@ class UserProfileTest(ZulipTestCase):
hamlet = self.example_user('hamlet')
othello = self.example_user('othello')
dct = get_emails_from_user_ids([hamlet.id, othello.id])
- self.assertEqual(dct[hamlet.id], 'hamlet@zulip.com')
+ self.assertEqual(dct[hamlet.id], self.example_email("hamlet"))
self.assertEqual(dct[othello.id], 'othello@zulip.com')
class ActivateTest(ZulipTestCase):
@@ -369,7 +369,7 @@ class GetProfileTest(ZulipTestCase):
def test_get_pointer(self):
# type: () -> None
- email = "hamlet@zulip.com"
+ email = self.example_email("hamlet")
self.login(email)
result = self.client_get("/json/users/me/pointer")
self.assert_json_success(result)
@@ -384,14 +384,14 @@ class GetProfileTest(ZulipTestCase):
self.assert_length(queries, 1)
self.assert_length(cache_queries, 1)
- self.assertEqual(user_profile.email, 'hamlet@zulip.com')
+ self.assertEqual(user_profile.email, self.example_email("hamlet"))
def test_get_user_profile(self):
# type: () -> None
- self.login('hamlet@zulip.com')
+ self.login(self.example_email("hamlet"))
result = ujson.loads(self.client_get('/json/users/me').content)
self.assertEqual(result['short_name'], 'hamlet')
- self.assertEqual(result['email'], 'hamlet@zulip.com')
+ self.assertEqual(result['email'], self.example_email("hamlet"))
self.assertEqual(result['full_name'], 'King Hamlet')
self.assertIn("user_id", result)
self.assertFalse(result['is_bot'])
@@ -437,12 +437,12 @@ class GetProfileTest(ZulipTestCase):
def test_get_all_profiles_avatar_urls(self):
# type: () -> None
user_profile = self.example_user('hamlet')
- result = self.client_get("/api/v1/users", **self.api_auth('hamlet@zulip.com'))
+ result = self.client_get("/api/v1/users", **self.api_auth(self.example_email("hamlet")))
self.assert_json_success(result)
json = ujson.loads(result.content)
for user in json['members']:
- if user['email'] == 'hamlet@zulip.com':
+ if user['email'] == self.example_email("hamlet"):
self.assertEqual(
user['avatar_url'],
avatar_url(user_profile),