mirror of https://github.com/zulip/zulip.git
tests: Prevent misuse of assert_in_success_response.
Changing assert_in_success_response to require List[Text] instead of Iterable[Text] prevents the following misuse: self.assert_in_response_success("message", response) Currently, this will check whether 'm', 'e', 's', 'a', and 'g' separately appear in the response, which is probably not the intended behavior. The correct usage is as follows: self.assert_in_response_success(["message"], response)
This commit is contained in:
parent
a2d948f2e0
commit
fde1aa506b
|
@ -370,7 +370,7 @@ class ZulipTestCase(TestCase):
|
|||
self.assertIn(substring, response.content.decode('utf-8'))
|
||||
|
||||
def assert_in_success_response(self, substrings, response):
|
||||
# type: (Iterable[Text], HttpResponse) -> None
|
||||
# type: (List[Text], HttpResponse) -> None
|
||||
self.assertEqual(response.status_code, 200)
|
||||
decoded = response.content.decode('utf-8')
|
||||
for substring in substrings:
|
||||
|
|
|
@ -31,7 +31,7 @@ class EmailChangeTestCase(ZulipTestCase):
|
|||
url = EmailChangeConfirmation.objects.get_activation_url(
|
||||
key, 'testserver')
|
||||
response = self.client_get(url)
|
||||
self.assert_in_success_response("Whoops", response)
|
||||
self.assert_in_success_response(["Whoops"], response)
|
||||
|
||||
def test_confirm_email_change_with_invalid_key(self):
|
||||
# type: () -> None
|
||||
|
@ -43,7 +43,7 @@ class EmailChangeTestCase(ZulipTestCase):
|
|||
url = EmailChangeConfirmation.objects.get_activation_url(
|
||||
key, 'testserver')
|
||||
response = self.client_get(url)
|
||||
self.assert_in_success_response("Whoops", response)
|
||||
self.assert_in_success_response(["Whoops"], response)
|
||||
|
||||
def test_email_change_when_not_logging_in(self):
|
||||
# type: () -> None
|
||||
|
@ -73,7 +73,7 @@ class EmailChangeTestCase(ZulipTestCase):
|
|||
confirmation_key=key)
|
||||
url = EmailChangeConfirmation.objects.get_activation_url(key)
|
||||
response = self.client_get(url)
|
||||
self.assert_in_success_response("Whoops", response)
|
||||
self.assert_in_success_response(["Whoops"], response)
|
||||
|
||||
def test_confirm_email_change(self):
|
||||
# type: () -> None
|
||||
|
@ -93,7 +93,7 @@ class EmailChangeTestCase(ZulipTestCase):
|
|||
response = self.client_get(url)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assert_in_success_response("This confirms that the email address for your Zulip",
|
||||
self.assert_in_success_response(["This confirms that the email address for your Zulip"],
|
||||
response)
|
||||
user_profile = get_user_profile_by_email(new_email)
|
||||
self.assertTrue(bool(user_profile))
|
||||
|
@ -115,7 +115,7 @@ class EmailChangeTestCase(ZulipTestCase):
|
|||
self.assertEqual(len(mail.outbox), 0)
|
||||
result = self.client_post(url, data)
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
self.assert_in_success_response('We have sent you an email', result)
|
||||
self.assert_in_success_response(['We have sent you an email'], result)
|
||||
email_message = mail.outbox[0]
|
||||
self.assertEqual(
|
||||
email_message.subject,
|
||||
|
@ -127,7 +127,7 @@ class EmailChangeTestCase(ZulipTestCase):
|
|||
activation_url = [s for s in body.split('\n') if s][4]
|
||||
response = self.client_get(activation_url)
|
||||
|
||||
self.assert_in_success_response("This confirms that the email address",
|
||||
self.assert_in_success_response(["This confirms that the email address"],
|
||||
response)
|
||||
|
||||
def test_unauthorized_email_change(self):
|
||||
|
@ -153,7 +153,7 @@ class EmailChangeTestCase(ZulipTestCase):
|
|||
self.assertEqual(len(mail.outbox), 0)
|
||||
result = self.client_post(url, data)
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
self.assert_in_success_response('We have sent you an email', result)
|
||||
self.assert_in_success_response(['We have sent you an email'], result)
|
||||
email_message = mail.outbox[0]
|
||||
self.assertEqual(
|
||||
email_message.subject,
|
||||
|
|
|
@ -972,7 +972,7 @@ class UserSignUpTest(ZulipTestCase):
|
|||
|
||||
# Pick a password and agree to the ToS.
|
||||
result = self.submit_reg_form_for_user(email, password, full_name="<invalid>")
|
||||
self.assert_in_success_response("Invalid characters in name!", result)
|
||||
self.assert_in_success_response(["Invalid characters in name!"], result)
|
||||
|
||||
def test_unique_completely_open_domain(self):
|
||||
# type: () -> None
|
||||
|
|
Loading…
Reference in New Issue