test_helpers: Require that login calls actually succeed.

This caught several bugs where test code wasn't doing what it's author
intended.
This commit is contained in:
Tim Abbott
2016-06-27 11:45:41 -07:00
parent 4cac7bbb32
commit f7e87bc1f0
2 changed files with 6 additions and 3 deletions

View File

@@ -256,10 +256,13 @@ class AuthedTestCase(TestCase):
return self.client.post('/accounts/login/',
{'username': email, 'password': password})
def login(self, email, password=None):
def login(self, email, password=None, fails=False):
if password is None:
password = initial_password(email)
self.client.login(username=email, password=password)
if not fails:
self.assertTrue(self.client.login(username=email, password=password))
else:
self.assertFalse(self.client.login(username=email, password=password))
def register(self, username, password, domain="zulip.com"):
# type: (text_type, text_type, text_type) -> HttpResponse

View File

@@ -123,7 +123,7 @@ class LoginTest(AuthedTestCase):
def test_login_bad_password(self):
# type: () -> None
self.login("hamlet@zulip.com", "wrongpassword")
self.login("hamlet@zulip.com", password="wrongpassword", fails=True)
self.assertIsNone(get_session_dict_user(self.client.session))
def test_login_nonexist_user(self):