test_helpers: Refactor login test helpers.

We now have a separate login helper for the case where the return
value is desired.
This commit is contained in:
Tim Abbott
2016-06-27 11:36:04 -07:00
parent a05c03d3b5
commit 4cac7bbb32
3 changed files with 10 additions and 5 deletions

View File

@@ -249,13 +249,18 @@ class AuthedTestCase(TestCase):
encoded = urllib.parse.urlencode(info)
return self.client.delete(url, encoded, **kwargs)
def login(self, email, password=None):
def login_with_return(self, email, password=None):
# type: (text_type, Optional[text_type]) -> HttpResponse
if password is None:
password = initial_password(email)
return self.client.post('/accounts/login/',
{'username': email, 'password': password})
def login(self, email, password=None):
if password is None:
password = initial_password(email)
self.client.login(username=email, password=password)
def register(self, username, password, domain="zulip.com"):
# type: (text_type, text_type, text_type) -> HttpResponse
self.client.post('/accounts/home/',

View File

@@ -286,7 +286,7 @@ class DeactivatedRealmTest(AuthedTestCase):
"""
do_deactivate_realm(get_realm("zulip.com"))
result = self.login("hamlet@zulip.com")
result = self.login_with_return("hamlet@zulip.com")
self.assertIn("has been deactivated", result.content.replace("\n", " "))
def test_webhook_deactivated_realm(self):
@@ -414,7 +414,7 @@ class InactiveUserTest(AuthedTestCase):
user_profile = get_user_profile_by_email(email)
do_deactivate_user(user_profile)
result = self.login("hamlet@zulip.com")
result = self.login_with_return("hamlet@zulip.com")
self.assertIn("Please enter a correct email and password", result.content.replace("\n", " "))
def test_webhook_deactivated_user(self):

View File

@@ -128,7 +128,7 @@ class LoginTest(AuthedTestCase):
def test_login_nonexist_user(self):
# type: () -> None
result = self.login("xxx@zulip.com", "xxx")
result = self.login_with_return("xxx@zulip.com", "xxx")
self.assertIn("Please enter a correct email and password", result.content)
def test_register(self):
@@ -171,7 +171,7 @@ class LoginTest(AuthedTestCase):
realm.deactivated = True
realm.save(update_fields=["deactivated"])
result = self.login("hamlet@zulip.com")
result = self.login_with_return("hamlet@zulip.com")
self.assertIn("has been deactivated", result.content.replace("\n", " "))
def test_logout(self):