mirror of
https://github.com/zulip/zulip.git
synced 2025-10-29 11:03:54 +00:00
zerver/tests: Use unicode strings.
* Use unicode strings for strings containing non-ASCII characters. * Decode response content when text output is expected.
This commit is contained in:
committed by
Tim Abbott
parent
161c27d0e9
commit
d740a87d04
@@ -238,8 +238,8 @@ class DevGetEmailsTest(AuthedTestCase):
|
||||
# type: () -> None
|
||||
result = self.client.get("/api/v1/dev_get_emails")
|
||||
self.assert_json_success(result)
|
||||
self.assertIn("direct_admins", result.content)
|
||||
self.assertIn("direct_users", result.content)
|
||||
self.assert_in_response("direct_admins", result)
|
||||
self.assert_in_response("direct_users", result)
|
||||
|
||||
def test_dev_auth_disabled(self):
|
||||
# type: () -> None
|
||||
|
||||
@@ -463,7 +463,7 @@ class DeactivatedRealmTest(AuthedTestCase):
|
||||
"""
|
||||
do_deactivate_realm(get_realm("zulip.com"))
|
||||
result = self.login_with_return("hamlet@zulip.com")
|
||||
self.assertIn("has been deactivated", result.content.replace("\n", " "))
|
||||
self.assertIn("has been deactivated", result.content.decode('utf-8').replace("\n", " "))
|
||||
|
||||
def test_webhook_deactivated_realm(self):
|
||||
"""
|
||||
@@ -495,7 +495,7 @@ class LoginRequiredTest(AuthedTestCase):
|
||||
# Verify succeeds once logged-in
|
||||
self.login(email)
|
||||
result = self.client.get('/accounts/accept_terms/')
|
||||
self.assertIn("I agree to the", result.content)
|
||||
self.assert_in_response("I agree to the", result)
|
||||
|
||||
# Verify fails if user deactivated (with session still valid)
|
||||
user_profile.is_active = False
|
||||
@@ -507,7 +507,7 @@ class LoginRequiredTest(AuthedTestCase):
|
||||
do_reactivate_user(user_profile)
|
||||
self.login(email)
|
||||
result = self.client.get('/accounts/accept_terms/')
|
||||
self.assertIn("I agree to the", result.content)
|
||||
self.assert_in_response("I agree to the", result)
|
||||
|
||||
# Verify fails if realm deactivated
|
||||
user_profile.realm.deactivated = True
|
||||
@@ -593,7 +593,7 @@ class InactiveUserTest(AuthedTestCase):
|
||||
do_deactivate_user(user_profile)
|
||||
|
||||
result = self.login_with_return("hamlet@zulip.com")
|
||||
self.assertIn("Please enter a correct email and password", result.content.replace("\n", " "))
|
||||
self.assertIn("Please enter a correct email and password", result.content.decode('utf-8').replace("\n", " "))
|
||||
|
||||
def test_webhook_deactivated_user(self):
|
||||
"""
|
||||
|
||||
@@ -12,7 +12,7 @@ from six.moves.http_cookies import SimpleCookie
|
||||
from zerver.lib.test_helpers import AuthedTestCase, skip_py3
|
||||
|
||||
|
||||
class TranslationTestCase(TestCase):
|
||||
class TranslationTestCase(AuthedTestCase):
|
||||
"""
|
||||
Tranlations strings should change with locale. URLs should be locale
|
||||
aware.
|
||||
@@ -30,44 +30,44 @@ class TranslationTestCase(TestCase):
|
||||
@skip_py3
|
||||
def test_accept_language_header(self):
|
||||
# type: () -> None
|
||||
languages = [('en', 'Register'),
|
||||
('de', 'Registrieren'),
|
||||
('sr', 'Региструј се'),
|
||||
('zh-cn', '注册'),
|
||||
languages = [('en', u'Register'),
|
||||
('de', u'Registrieren'),
|
||||
('sr', u'Региструј се'),
|
||||
('zh-cn', u'注册'),
|
||||
]
|
||||
|
||||
for lang, word in languages:
|
||||
response = self.fetch('get', '/integrations/', 200,
|
||||
HTTP_ACCEPT_LANGUAGE=lang)
|
||||
self.assertTrue(word in response.content)
|
||||
self.assert_in_response(word, response)
|
||||
|
||||
@skip_py3
|
||||
def test_cookie(self):
|
||||
# type: () -> None
|
||||
languages = [('en', 'Register'),
|
||||
('de', 'Registrieren'),
|
||||
('sr', 'Региструј се'),
|
||||
('zh-cn', '注册'),
|
||||
languages = [('en', u'Register'),
|
||||
('de', u'Registrieren'),
|
||||
('sr', u'Региструј се'),
|
||||
('zh-cn', u'注册'),
|
||||
]
|
||||
|
||||
for lang, word in languages:
|
||||
self.client.cookies = SimpleCookie({settings.LANGUAGE_COOKIE_NAME: lang}) # type: ignore # SimpleCookie has incomplete stubs in python 3
|
||||
|
||||
response = self.fetch('get', '/integrations/', 200)
|
||||
self.assertTrue(word in response.content)
|
||||
self.assert_in_response(word, response)
|
||||
|
||||
@skip_py3
|
||||
def test_i18n_urls(self):
|
||||
# type: () -> None
|
||||
languages = [('en', 'Register'),
|
||||
('de', 'Registrieren'),
|
||||
('sr', 'Региструј се'),
|
||||
('zh-cn', '注册'),
|
||||
languages = [('en', u'Register'),
|
||||
('de', u'Registrieren'),
|
||||
('sr', u'Региструј се'),
|
||||
('zh-cn', u'注册'),
|
||||
]
|
||||
|
||||
for lang, word in languages:
|
||||
response = self.fetch('get', '/{}/integrations/'.format(lang), 200)
|
||||
self.assertTrue(word in response.content)
|
||||
self.assert_in_response(word, response)
|
||||
|
||||
|
||||
class JsonTranslationTestCase(AuthedTestCase):
|
||||
|
||||
@@ -7,7 +7,7 @@ from django.core.management import call_command
|
||||
from zerver.models import get_realm
|
||||
from confirmation.models import RealmCreationKey, generate_realm_creation_url
|
||||
from datetime import timedelta
|
||||
from zerver.lib.test_helpers import skip_py3
|
||||
from zerver.lib.test_helpers import AuthedTestCase, skip_py3
|
||||
|
||||
class TestSendWebhookFixtureMessage(TestCase):
|
||||
COMMAND_NAME = 'send_webhook_fixture_message'
|
||||
@@ -61,7 +61,7 @@ class TestSendWebhookFixtureMessage(TestCase):
|
||||
self.assertTrue(open_mock.called)
|
||||
client.post.assert_called_once_with(self.url, {}, content_type="application/json")
|
||||
|
||||
class TestGenerateRealmCreationLink(TestCase):
|
||||
class TestGenerateRealmCreationLink(AuthedTestCase):
|
||||
COMMAND_NAME = "generate_realm_creation_link"
|
||||
|
||||
@skip_py3
|
||||
@@ -75,7 +75,7 @@ class TestGenerateRealmCreationLink(TestCase):
|
||||
# Check realm creation page is accessible
|
||||
result = self.client.get(generated_link)
|
||||
self.assertEquals(result.status_code, 200)
|
||||
self.assertIn("Let's get started…", result.content)
|
||||
self.assert_in_response(u"Let's get started…", result)
|
||||
|
||||
# Create Realm with generated link
|
||||
self.assertIsNone(get_realm(domain))
|
||||
@@ -84,12 +84,12 @@ class TestGenerateRealmCreationLink(TestCase):
|
||||
self.assertTrue(result["Location"].endswith(
|
||||
"/accounts/send_confirm/%s@%s" % (username, domain)))
|
||||
result = self.client.get(result["Location"])
|
||||
self.assertIn("Check your email so we can get started.", result.content)
|
||||
self.assert_in_response("Check your email so we can get started.", result)
|
||||
|
||||
# Generated link used for creating realm
|
||||
result = self.client.get(generated_link)
|
||||
self.assertEquals(result.status_code, 200)
|
||||
self.assertIn("The organization creation link has been expired or is not valid.", result.content)
|
||||
self.assert_in_response("The organization creation link has been expired or is not valid.", result)
|
||||
|
||||
@skip_py3
|
||||
def test_realm_creation_with_random_link(self):
|
||||
@@ -98,7 +98,7 @@ class TestGenerateRealmCreationLink(TestCase):
|
||||
random_link = "/create_realm/5e89081eb13984e0f3b130bf7a4121d153f1614b"
|
||||
result = self.client.get(random_link)
|
||||
self.assertEquals(result.status_code, 200)
|
||||
self.assertIn("The organization creation link has been expired or is not valid.", result.content)
|
||||
self.assert_in_response("The organization creation link has been expired or is not valid.", result)
|
||||
|
||||
@skip_py3
|
||||
def test_realm_creation_with_expired_link(self):
|
||||
@@ -112,4 +112,4 @@ class TestGenerateRealmCreationLink(TestCase):
|
||||
|
||||
result = self.client.get(generated_link)
|
||||
self.assertEquals(result.status_code, 200)
|
||||
self.assertIn("The organization creation link has been expired or is not valid.", result.content)
|
||||
self.assert_in_response("The organization creation link has been expired or is not valid.", result)
|
||||
|
||||
@@ -130,7 +130,7 @@ class LoginTest(AuthedTestCase):
|
||||
def test_login_nonexist_user(self):
|
||||
# type: () -> None
|
||||
result = self.login_with_return("xxx@zulip.com", "xxx")
|
||||
self.assertIn("Please enter a correct email and password", result.content)
|
||||
self.assert_in_response("Please enter a correct email and password", result)
|
||||
|
||||
def test_register(self):
|
||||
# type: () -> None
|
||||
@@ -159,7 +159,7 @@ class LoginTest(AuthedTestCase):
|
||||
realm.save(update_fields=["deactivated"])
|
||||
|
||||
result = self.register("test", "test")
|
||||
self.assertIn("has been deactivated", result.content.replace("\n", " "))
|
||||
self.assertIn("has been deactivated", result.content.decode('utf-8').replace("\n", " "))
|
||||
|
||||
with self.assertRaises(UserProfile.DoesNotExist):
|
||||
get_user_profile_by_email('test@zulip.com')
|
||||
@@ -175,7 +175,7 @@ class LoginTest(AuthedTestCase):
|
||||
realm.save(update_fields=["deactivated"])
|
||||
|
||||
result = self.login_with_return("hamlet@zulip.com")
|
||||
self.assertIn("has been deactivated", result.content.replace("\n", " "))
|
||||
self.assertIn("has been deactivated", result.content.decode('utf-8').replace("\n", " "))
|
||||
|
||||
def test_logout(self):
|
||||
# type: () -> None
|
||||
@@ -228,7 +228,7 @@ class LoginTest(AuthedTestCase):
|
||||
self.assertTrue(result["Location"].endswith(
|
||||
"/accounts/send_confirm/%s@%s" % (username, domain)))
|
||||
result = self.client.get(result["Location"])
|
||||
self.assertIn("Check your email so we can get started.", result.content)
|
||||
self.assert_in_response("Check your email so we can get started.", result)
|
||||
|
||||
# Visit the confirmation link.
|
||||
from django.core.mail import outbox
|
||||
@@ -251,7 +251,7 @@ class LoginTest(AuthedTestCase):
|
||||
|
||||
# Invite other users to join you.
|
||||
result = self.client.get(result["Location"])
|
||||
self.assertIn("You're the first one here!", result.content)
|
||||
self.assert_in_response("You're the first one here!", result)
|
||||
|
||||
# Reset the outbox for our invites.
|
||||
outbox.pop()
|
||||
@@ -584,7 +584,7 @@ class RealmCreationTest(AuthedTestCase):
|
||||
self.assertTrue(result["Location"].endswith(
|
||||
"/accounts/send_confirm/%s@%s" % (username, domain)))
|
||||
result = self.client.get(result["Location"])
|
||||
self.assertIn("Check your email so we can get started.", result.content)
|
||||
self.assert_in_response("Check your email so we can get started.", result)
|
||||
|
||||
# Visit the confirmation link.
|
||||
from django.core.mail import outbox
|
||||
@@ -613,4 +613,4 @@ class RealmCreationTest(AuthedTestCase):
|
||||
self.assertTrue(result["Location"].endswith("/invite/"))
|
||||
|
||||
result = self.client.get(result["Location"])
|
||||
self.assertIn("You're the first one here!", result.content)
|
||||
self.assert_in_response("You're the first one here!", result)
|
||||
|
||||
Reference in New Issue
Block a user