mirror of https://github.com/zulip/zulip.git
tests: Add assert_in_success_response in ZulipTestCase.
Clean up the instances of self.assertIn("string", result.content.decode("utf-8")), and replace them with self.assert_in_response("string"). Fixes: #2313
This commit is contained in:
parent
6ed1dc9341
commit
7a3ef2b0eb
|
@ -321,6 +321,13 @@ class ZulipTestCase(TestCase):
|
||||||
# type: (text_type, HttpResponse) -> None
|
# type: (text_type, HttpResponse) -> None
|
||||||
self.assertIn(substring, response.content.decode('utf-8'))
|
self.assertIn(substring, response.content.decode('utf-8'))
|
||||||
|
|
||||||
|
def assert_in_success_response(self, substrings, response):
|
||||||
|
# type: (Iterable[text_type], HttpResponse) -> None
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
decoded = response.content.decode('utf-8')
|
||||||
|
for substring in substrings:
|
||||||
|
self.assertIn(substring, decoded)
|
||||||
|
|
||||||
def fixture_data(self, type, action, file_type='json'):
|
def fixture_data(self, type, action, file_type='json'):
|
||||||
# type: (text_type, text_type, text_type) -> text_type
|
# type: (text_type, text_type, text_type) -> text_type
|
||||||
return force_text(open(os.path.join(os.path.dirname(__file__),
|
return force_text(open(os.path.join(os.path.dirname(__file__),
|
||||||
|
|
|
@ -76,8 +76,7 @@ class TestGenerateRealmCreationLink(ZulipTestCase):
|
||||||
with self.settings(OPEN_REALM_CREATION=False):
|
with self.settings(OPEN_REALM_CREATION=False):
|
||||||
# Check realm creation page is accessible
|
# Check realm creation page is accessible
|
||||||
result = self.client_get(generated_link)
|
result = self.client_get(generated_link)
|
||||||
self.assertEquals(result.status_code, 200)
|
self.assert_in_success_response([u"Let's get started…"], result)
|
||||||
self.assert_in_response(u"Let's get started…", result)
|
|
||||||
|
|
||||||
# Create Realm with generated link
|
# Create Realm with generated link
|
||||||
self.assertIsNone(get_realm_by_string_id('test'))
|
self.assertIsNone(get_realm_by_string_id('test'))
|
||||||
|
@ -90,8 +89,7 @@ class TestGenerateRealmCreationLink(ZulipTestCase):
|
||||||
|
|
||||||
# Generated link used for creating realm
|
# Generated link used for creating realm
|
||||||
result = self.client_get(generated_link)
|
result = self.client_get(generated_link)
|
||||||
self.assertEquals(result.status_code, 200)
|
self.assert_in_success_response(["The organization creation link has been expired or is not valid."], result)
|
||||||
self.assert_in_response("The organization creation link has been expired or is not valid.", result)
|
|
||||||
|
|
||||||
def test_realm_creation_with_random_link(self):
|
def test_realm_creation_with_random_link(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
|
@ -99,8 +97,7 @@ class TestGenerateRealmCreationLink(ZulipTestCase):
|
||||||
# Realm creation attempt with an invalid link should fail
|
# Realm creation attempt with an invalid link should fail
|
||||||
random_link = "/create_realm/5e89081eb13984e0f3b130bf7a4121d153f1614b"
|
random_link = "/create_realm/5e89081eb13984e0f3b130bf7a4121d153f1614b"
|
||||||
result = self.client_get(random_link)
|
result = self.client_get(random_link)
|
||||||
self.assertEquals(result.status_code, 200)
|
self.assert_in_success_response(["The organization creation link has been expired or is not valid."], result)
|
||||||
self.assert_in_response("The organization creation link has been expired or is not valid.", result)
|
|
||||||
|
|
||||||
def test_realm_creation_with_expired_link(self):
|
def test_realm_creation_with_expired_link(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
|
@ -113,5 +110,4 @@ class TestGenerateRealmCreationLink(ZulipTestCase):
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
result = self.client_get(generated_link)
|
result = self.client_get(generated_link)
|
||||||
self.assertEquals(result.status_code, 200)
|
self.assert_in_success_response(["The organization creation link has been expired or is not valid."], result)
|
||||||
self.assert_in_response("The organization creation link has been expired or is not valid.", result)
|
|
||||||
|
|
|
@ -197,16 +197,13 @@ class PasswordResetTest(ZulipTestCase):
|
||||||
tests here.
|
tests here.
|
||||||
'''
|
'''
|
||||||
result = self.client_get('/accounts/password/reset/done/')
|
result = self.client_get('/accounts/password/reset/done/')
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assert_in_success_response(["Check your email"], result)
|
||||||
self.assertIn('Check your email', result.content.decode("utf-8"))
|
|
||||||
|
|
||||||
result = self.client_get('/accounts/password/done/')
|
result = self.client_get('/accounts/password/done/')
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assert_in_success_response(["We've reset your password!"], result)
|
||||||
self.assertIn("We've reset your password!", result.content.decode("utf-8"))
|
|
||||||
|
|
||||||
result = self.client_get('/accounts/send_confirm/alice@example.com')
|
result = self.client_get('/accounts/send_confirm/alice@example.com')
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assert_in_success_response(["Still no email?"], result)
|
||||||
self.assertIn("Still no email?", result.content.decode("utf-8"))
|
|
||||||
|
|
||||||
class LoginTest(ZulipTestCase):
|
class LoginTest(ZulipTestCase):
|
||||||
"""
|
"""
|
||||||
|
@ -873,8 +870,7 @@ class UserSignUpTest(ZulipTestCase):
|
||||||
realm_subdomain=subdomain,
|
realm_subdomain=subdomain,
|
||||||
# Pass HTTP_HOST for the target subdomain
|
# Pass HTTP_HOST for the target subdomain
|
||||||
HTTP_HOST=subdomain + ".testserver")
|
HTTP_HOST=subdomain + ".testserver")
|
||||||
self.assertEquals(result.status_code, 200)
|
self.assert_in_success_response(["You're almost there."], result)
|
||||||
self.assertIn("You're almost there.", result.content.decode('utf8'))
|
|
||||||
|
|
||||||
def test_completely_open_domain_success(self):
|
def test_completely_open_domain_success(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
|
@ -917,8 +913,7 @@ class UserSignUpTest(ZulipTestCase):
|
||||||
realm_subdomain=subdomain,
|
realm_subdomain=subdomain,
|
||||||
# Pass HTTP_HOST for the target subdomain
|
# Pass HTTP_HOST for the target subdomain
|
||||||
HTTP_HOST=subdomain + ".testserver")
|
HTTP_HOST=subdomain + ".testserver")
|
||||||
self.assertEquals(result.status_code, 200)
|
self.assert_in_success_response(["You're almost there."], result)
|
||||||
self.assertIn("You're almost there.", result.content.decode('utf8'))
|
|
||||||
|
|
||||||
def test_failed_signup_due_to_restricted_domain(self):
|
def test_failed_signup_due_to_restricted_domain(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
|
@ -1006,10 +1001,10 @@ class UserSignUpTest(ZulipTestCase):
|
||||||
# Pass HTTP_HOST for the target subdomain
|
# Pass HTTP_HOST for the target subdomain
|
||||||
HTTP_HOST=subdomain + ".testserver")
|
HTTP_HOST=subdomain + ".testserver")
|
||||||
|
|
||||||
self.assertEquals(result.status_code, 200)
|
self.assert_in_success_response(["You're almost there.",
|
||||||
self.assertIn("You're almost there.", result.content.decode('utf8'))
|
"New User Name",
|
||||||
self.assertIn("New User Name", result.content.decode('utf8'))
|
"newuser@zulip.com"],
|
||||||
self.assertIn("newuser@zulip.com", result.content.decode('utf8'))
|
result)
|
||||||
|
|
||||||
# Test the TypeError exception handler
|
# Test the TypeError exception handler
|
||||||
mock_ldap.directory = {
|
mock_ldap.directory = {
|
||||||
|
@ -1026,10 +1021,10 @@ class UserSignUpTest(ZulipTestCase):
|
||||||
from_confirmation='1',
|
from_confirmation='1',
|
||||||
# Pass HTTP_HOST for the target subdomain
|
# Pass HTTP_HOST for the target subdomain
|
||||||
HTTP_HOST=subdomain + ".testserver")
|
HTTP_HOST=subdomain + ".testserver")
|
||||||
|
self.assert_in_success_response(["You're almost there.",
|
||||||
|
"newuser@zulip.com"],
|
||||||
|
result)
|
||||||
|
|
||||||
self.assertEquals(result.status_code, 200)
|
|
||||||
self.assertIn("You're almost there.", result.content.decode('utf8'))
|
|
||||||
self.assertIn("newuser@zulip.com", result.content.decode('utf8'))
|
|
||||||
|
|
||||||
mock_ldap.reset()
|
mock_ldap.reset()
|
||||||
mock_initialize.stop()
|
mock_initialize.stop()
|
||||||
|
|
|
@ -194,6 +194,7 @@ class TemplateTestCase(ZulipTestCase):
|
||||||
def test_custom_tos_template(self):
|
def test_custom_tos_template(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
response = self.client_get("/terms/")
|
response = self.client_get("/terms/")
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
self.assert_in_response(u"Thanks for using our products and services (\"Services\"). ", response)
|
self.assert_in_success_response([u"Thanks for using our products and services (\"Services\"). ",
|
||||||
self.assert_in_response(u"By using our Services, you are agreeing to these terms", response)
|
u"By using our Services, you are agreeing to these terms"],
|
||||||
|
response)
|
||||||
|
|
|
@ -1764,8 +1764,7 @@ class HelpTest(ZulipTestCase):
|
||||||
def test_browser_window_help(self):
|
def test_browser_window_help(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
result = self.client_get('/help/#the-browser-window')
|
result = self.client_get('/help/#the-browser-window')
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assert_in_success_response(["There are three panes"], result)
|
||||||
self.assertIn("There are three panes", result.content.decode("utf-8"))
|
|
||||||
|
|
||||||
class HomeTest(ZulipTestCase):
|
class HomeTest(ZulipTestCase):
|
||||||
@slow('big method')
|
@slow('big method')
|
||||||
|
|
Loading…
Reference in New Issue