Add client_post() test helper.

This makes us more consistent, since we have other wrappers
like client_patch, client_put, and client_delete.

Wrapping also will facilitate instrumentation of our posting code.
This commit is contained in:
Steve Howell
2016-07-27 15:30:22 -07:00
committed by Tim Abbott
parent eb34c249d7
commit 38f2a2f475
14 changed files with 201 additions and 198 deletions

View File

@@ -230,11 +230,14 @@ class AuthedTestCase(TestCase):
encoded = urllib.parse.urlencode(info) encoded = urllib.parse.urlencode(info)
return self.client.delete(url, encoded, **kwargs) return self.client.delete(url, encoded, **kwargs)
def client_post(self, url, info={}, **kwargs):
return self.client.post(url, info, **kwargs)
def login_with_return(self, email, password=None): def login_with_return(self, email, password=None):
# type: (text_type, Optional[text_type]) -> HttpResponse # type: (text_type, Optional[text_type]) -> HttpResponse
if password is None: if password is None:
password = initial_password(email) password = initial_password(email)
return self.client.post('/accounts/login/', return self.client_post('/accounts/login/',
{'username': email, 'password': password}) {'username': email, 'password': password})
def login(self, email, password=None, fails=False): def login(self, email, password=None, fails=False):
@@ -247,7 +250,7 @@ class AuthedTestCase(TestCase):
def register(self, username, password, domain="zulip.com"): def register(self, username, password, domain="zulip.com"):
# type: (text_type, text_type, text_type) -> HttpResponse # type: (text_type, text_type, text_type) -> HttpResponse
self.client.post('/accounts/home/', self.client_post('/accounts/home/',
{'email': username + "@" + domain}) {'email': username + "@" + domain})
return self.submit_reg_form_for_user(username, password, domain=domain) return self.submit_reg_form_for_user(username, password, domain=domain)
@@ -259,7 +262,7 @@ class AuthedTestCase(TestCase):
If things are working correctly the account should be fully If things are working correctly the account should be fully
registered after this call. registered after this call.
""" """
return self.client.post('/accounts/register/', return self.client_post('/accounts/register/',
{'full_name': username, 'password': password, {'full_name': username, 'password': password,
'key': find_key_by_email(username + '@' + domain), 'key': find_key_by_email(username + '@' + domain),
'terms': True}) 'terms': True})
@@ -397,7 +400,7 @@ class AuthedTestCase(TestCase):
post_data = {'subscriptions': ujson.dumps([{"name": stream} for stream in streams]), post_data = {'subscriptions': ujson.dumps([{"name": stream} for stream in streams]),
'invite_only': ujson.dumps(invite_only)} 'invite_only': ujson.dumps(invite_only)}
post_data.update(extra_post_data) post_data.update(extra_post_data)
result = self.client.post("/api/v1/users/me/subscriptions", post_data, **self.api_auth(email)) result = self.client_post("/api/v1/users/me/subscriptions", post_data, **self.api_auth(email))
return result return result
def send_json_payload(self, email, url, payload, stream_name=None, **post_params): def send_json_payload(self, email, url, payload, stream_name=None, **post_params):
@@ -405,7 +408,7 @@ class AuthedTestCase(TestCase):
if stream_name is not None: if stream_name is not None:
self.subscribe_to_stream(email, stream_name) self.subscribe_to_stream(email, stream_name)
result = self.client.post(url, payload, **post_params) result = self.client_post(url, payload, **post_params)
self.assert_json_success(result) self.assert_json_success(result)
# Check the correct message was sent # Check the correct message was sent

View File

@@ -160,14 +160,14 @@ class FetchAPIKeyTest(AuthedTestCase):
def test_success(self): def test_success(self):
# type: () -> None # type: () -> None
result = self.client.post("/api/v1/fetch_api_key", result = self.client_post("/api/v1/fetch_api_key",
dict(username=self.email, dict(username=self.email,
password=initial_password(self.email))) password=initial_password(self.email)))
self.assert_json_success(result) self.assert_json_success(result)
def test_wrong_password(self): def test_wrong_password(self):
# type: () -> None # type: () -> None
result = self.client.post("/api/v1/fetch_api_key", result = self.client_post("/api/v1/fetch_api_key",
dict(username=self.email, dict(username=self.email,
password="wrong")) password="wrong"))
self.assert_json_error(result, "Your username or password is incorrect.", 403) self.assert_json_error(result, "Your username or password is incorrect.", 403)
@@ -175,7 +175,7 @@ class FetchAPIKeyTest(AuthedTestCase):
def test_password_auth_disabled(self): def test_password_auth_disabled(self):
# type: () -> None # type: () -> None
with mock.patch('zproject.backends.password_auth_enabled', return_value=False): with mock.patch('zproject.backends.password_auth_enabled', return_value=False):
result = self.client.post("/api/v1/fetch_api_key", result = self.client_post("/api/v1/fetch_api_key",
dict(username=self.email, dict(username=self.email,
password=initial_password(self.email))) password=initial_password(self.email)))
self.assert_json_error_contains(result, "Password auth is disabled", 403) self.assert_json_error_contains(result, "Password auth is disabled", 403)
@@ -183,7 +183,7 @@ class FetchAPIKeyTest(AuthedTestCase):
def test_inactive_user(self): def test_inactive_user(self):
# type: () -> None # type: () -> None
do_deactivate_user(self.user_profile) do_deactivate_user(self.user_profile)
result = self.client.post("/api/v1/fetch_api_key", result = self.client_post("/api/v1/fetch_api_key",
dict(username=self.email, dict(username=self.email,
password=initial_password(self.email))) password=initial_password(self.email)))
self.assert_json_error_contains(result, "Your account has been disabled", 403) self.assert_json_error_contains(result, "Your account has been disabled", 403)
@@ -191,7 +191,7 @@ class FetchAPIKeyTest(AuthedTestCase):
def test_deactivated_realm(self): def test_deactivated_realm(self):
# type: () -> None # type: () -> None
do_deactivate_realm(self.user_profile.realm) do_deactivate_realm(self.user_profile.realm)
result = self.client.post("/api/v1/fetch_api_key", result = self.client_post("/api/v1/fetch_api_key",
dict(username=self.email, dict(username=self.email,
password=initial_password(self.email))) password=initial_password(self.email)))
self.assert_json_error_contains(result, "Your realm has been deactivated", 403) self.assert_json_error_contains(result, "Your realm has been deactivated", 403)
@@ -204,7 +204,7 @@ class DevFetchAPIKeyTest(AuthedTestCase):
def test_success(self): def test_success(self):
# type: () -> None # type: () -> None
result = self.client.post("/api/v1/dev_fetch_api_key", result = self.client_post("/api/v1/dev_fetch_api_key",
dict(username=self.email)) dict(username=self.email))
self.assert_json_success(result) self.assert_json_success(result)
data = ujson.loads(result.content) data = ujson.loads(result.content)
@@ -214,21 +214,21 @@ class DevFetchAPIKeyTest(AuthedTestCase):
def test_inactive_user(self): def test_inactive_user(self):
# type: () -> None # type: () -> None
do_deactivate_user(self.user_profile) do_deactivate_user(self.user_profile)
result = self.client.post("/api/v1/dev_fetch_api_key", result = self.client_post("/api/v1/dev_fetch_api_key",
dict(username=self.email)) dict(username=self.email))
self.assert_json_error_contains(result, "Your account has been disabled", 403) self.assert_json_error_contains(result, "Your account has been disabled", 403)
def test_deactivated_realm(self): def test_deactivated_realm(self):
# type: () -> None # type: () -> None
do_deactivate_realm(self.user_profile.realm) do_deactivate_realm(self.user_profile.realm)
result = self.client.post("/api/v1/dev_fetch_api_key", result = self.client_post("/api/v1/dev_fetch_api_key",
dict(username=self.email)) dict(username=self.email))
self.assert_json_error_contains(result, "Your realm has been deactivated", 403) self.assert_json_error_contains(result, "Your realm has been deactivated", 403)
def test_dev_auth_disabled(self): def test_dev_auth_disabled(self):
# type: () -> None # type: () -> None
with mock.patch('zerver.views.dev_auth_enabled', return_value=False): with mock.patch('zerver.views.dev_auth_enabled', return_value=False):
result = self.client.post("/api/v1/dev_fetch_api_key", result = self.client_post("/api/v1/dev_fetch_api_key",
dict(username=self.email)) dict(username=self.email))
self.assert_json_error_contains(result, "Dev environment not enabled.", 400) self.assert_json_error_contains(result, "Dev environment not enabled.", 400)

View File

@@ -412,7 +412,7 @@ class DeactivatedRealmTest(AuthedTestCase):
realm = get_realm("zulip.com") realm = get_realm("zulip.com")
do_deactivate_realm(get_realm("zulip.com")) do_deactivate_realm(get_realm("zulip.com"))
result = self.client.post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"content": "Test message", "content": "Test message",
"client": "test suite", "client": "test suite",
"to": "othello@zulip.com"}) "to": "othello@zulip.com"})
@@ -425,13 +425,13 @@ class DeactivatedRealmTest(AuthedTestCase):
realm.deactivated = True realm.deactivated = True
realm.save() realm.save()
result = self.client.post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"content": "Test message", "content": "Test message",
"client": "test suite", "client": "test suite",
"to": "othello@zulip.com"}) "to": "othello@zulip.com"})
self.assert_json_error_contains(result, "has been deactivated", status_code=400) self.assert_json_error_contains(result, "has been deactivated", status_code=400)
result = self.client.post("/api/v1/messages", {"type": "private", result = self.client_post("/api/v1/messages", {"type": "private",
"content": "Test message", "content": "Test message",
"client": "test suite", "client": "test suite",
"to": "othello@zulip.com"}, "to": "othello@zulip.com"},
@@ -452,7 +452,7 @@ class DeactivatedRealmTest(AuthedTestCase):
self.login(email) self.login(email)
realm.deactivated = True realm.deactivated = True
realm.save() realm.save()
result = self.client.post("/json/fetch_api_key", {"password": test_password}) result = self.client_post("/json/fetch_api_key", {"password": test_password})
self.assert_json_error_contains(result, "has been deactivated", status_code=400) self.assert_json_error_contains(result, "has been deactivated", status_code=400)
def test_login_deactivated_realm(self): def test_login_deactivated_realm(self):
@@ -474,7 +474,7 @@ class DeactivatedRealmTest(AuthedTestCase):
api_key = self.get_api_key(email) api_key = self.get_api_key(email)
url = "/api/v1/external/jira?api_key=%s&stream=jira_custom" % (api_key,) url = "/api/v1/external/jira?api_key=%s&stream=jira_custom" % (api_key,)
data = self.fixture_data('jira', "created") data = self.fixture_data('jira', "created")
result = self.client.post(url, data, result = self.client_post(url, data,
content_type="application/json") content_type="application/json")
self.assert_json_error_contains(result, "has been deactivated", status_code=400) self.assert_json_error_contains(result, "has been deactivated", status_code=400)
@@ -518,14 +518,14 @@ class FetchAPIKeyTest(AuthedTestCase):
email = "cordelia@zulip.com" email = "cordelia@zulip.com"
self.login(email) self.login(email)
result = self.client.post("/json/fetch_api_key", {"password": initial_password(email)}) result = self.client_post("/json/fetch_api_key", {"password": initial_password(email)})
self.assert_json_success(result) self.assert_json_success(result)
def test_fetch_api_key_wrong_password(self): def test_fetch_api_key_wrong_password(self):
email = "cordelia@zulip.com" email = "cordelia@zulip.com"
self.login(email) self.login(email)
result = self.client.post("/json/fetch_api_key", {"password": "wrong_password"}) result = self.client_post("/json/fetch_api_key", {"password": "wrong_password"})
self.assert_json_error_contains(result, "password is incorrect") self.assert_json_error_contains(result, "password is incorrect")
class InactiveUserTest(AuthedTestCase): class InactiveUserTest(AuthedTestCase):
@@ -539,7 +539,7 @@ class InactiveUserTest(AuthedTestCase):
self.login(email) self.login(email)
do_deactivate_user(user_profile) do_deactivate_user(user_profile)
result = self.client.post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"content": "Test message", "content": "Test message",
"client": "test suite", "client": "test suite",
"to": "othello@zulip.com"}) "to": "othello@zulip.com"})
@@ -551,13 +551,13 @@ class InactiveUserTest(AuthedTestCase):
user_profile.is_active = False user_profile.is_active = False
user_profile.save() user_profile.save()
result = self.client.post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"content": "Test message", "content": "Test message",
"client": "test suite", "client": "test suite",
"to": "othello@zulip.com"}) "to": "othello@zulip.com"})
self.assert_json_error_contains(result, "Account not active", status_code=400) self.assert_json_error_contains(result, "Account not active", status_code=400)
result = self.client.post("/api/v1/messages", {"type": "private", result = self.client_post("/api/v1/messages", {"type": "private",
"content": "Test message", "content": "Test message",
"client": "test suite", "client": "test suite",
"to": "othello@zulip.com"}, "to": "othello@zulip.com"},
@@ -577,7 +577,7 @@ class InactiveUserTest(AuthedTestCase):
self.login(email) self.login(email)
user_profile.is_active = False user_profile.is_active = False
user_profile.save() user_profile.save()
result = self.client.post("/json/fetch_api_key", {"password": test_password}) result = self.client_post("/json/fetch_api_key", {"password": test_password})
self.assert_json_error_contains(result, "Account not active", status_code=400) self.assert_json_error_contains(result, "Account not active", status_code=400)
def test_login_deactivated_user(self): def test_login_deactivated_user(self):
@@ -604,7 +604,7 @@ class InactiveUserTest(AuthedTestCase):
api_key = self.get_api_key(email) api_key = self.get_api_key(email)
url = "/api/v1/external/jira?api_key=%s&stream=jira_custom" % (api_key,) url = "/api/v1/external/jira?api_key=%s&stream=jira_custom" % (api_key,)
data = self.fixture_data('jira', "created") data = self.fixture_data('jira', "created")
result = self.client.post(url, data, result = self.client_post(url, data,
content_type="application/json") content_type="application/json")
self.assert_json_error_contains(result, "Account not active", status_code=400) self.assert_json_error_contains(result, "Account not active", status_code=400)
@@ -730,7 +730,7 @@ class TestAuthenticatedJsonPostViewDecorator(AuthedTestCase):
def _do_test(self, user_email): def _do_test(self, user_email):
data = {"status": '"started"'} data = {"status": '"started"'}
return self.client.post(r'/json/tutorial_status', data) return self.client_post(r'/json/tutorial_status', data)
def _login(self, user_email, password=None): def _login(self, user_email, password=None):
if password: if password:

View File

@@ -109,7 +109,7 @@ class TestMissedPersonalMessageEmailMessages(AuthedTestCase):
# have Hamlet send Othello a PM. Othello will reply via email # have Hamlet send Othello a PM. Othello will reply via email
# Hamlet will receive the message. # Hamlet will receive the message.
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"content": "test_receive_missed_message_email_messages", "content": "test_receive_missed_message_email_messages",
"client": "test suite", "client": "test suite",
"to": "othello@zulip.com"}) "to": "othello@zulip.com"})
@@ -148,7 +148,7 @@ class TestMissedHuddleMessageEmailMessages(AuthedTestCase):
# have Othello send Iago and Cordelia a PM. Cordelia will reply via email # have Othello send Iago and Cordelia a PM. Cordelia will reply via email
# Iago and Othello will receive the message. # Iago and Othello will receive the message.
self.login("othello@zulip.com") self.login("othello@zulip.com")
result = self.client.post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"content": "test_receive_missed_message_email_messages", "content": "test_receive_missed_message_email_messages",
"client": "test suite", "client": "test suite",
"to": ujson.dumps(["cordelia@zulip.com", "to": ujson.dumps(["cordelia@zulip.com",
@@ -196,7 +196,7 @@ class TestDigestEmailMessages(AuthedTestCase):
# have Hamlet send Othello a PM. Othello will reply via email # have Hamlet send Othello a PM. Othello will reply via email
# Hamlet will receive the message. # Hamlet will receive the message.
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"content": "test_receive_missed_message_email_messages", "content": "test_receive_missed_message_email_messages",
"client": "test suite", "client": "test suite",
"to": "othello@zulip.com"}) "to": "othello@zulip.com"})

View File

@@ -68,7 +68,7 @@ class RateLimitTests(AuthedTestCase):
def send_api_message(self, email, api_key, content): def send_api_message(self, email, api_key, content):
# type: (text_type, text_type, text_type) -> HttpResponse # type: (text_type, text_type, text_type) -> HttpResponse
return self.client.post("/api/v1/send_message", {"type": "stream", return self.client_post("/api/v1/send_message", {"type": "stream",
"to": "Verona", "to": "Verona",
"client": "test suite", "client": "test suite",
"content": content, "content": content,
@@ -133,7 +133,7 @@ class APNSTokenTests(AuthedTestCase):
email = "cordelia@zulip.com" email = "cordelia@zulip.com"
self.login(email) self.login(email)
result = self.client.post('/json/users/me/apns_device_token', {'token': "test_token"}) result = self.client_post('/json/users/me/apns_device_token', {'token': "test_token"})
self.assert_json_success(result) self.assert_json_success(result)
def test_delete_token(self): def test_delete_token(self):
@@ -142,7 +142,7 @@ class APNSTokenTests(AuthedTestCase):
self.login(email) self.login(email)
token = "test_token" token = "test_token"
result = self.client.post('/json/users/me/apns_device_token', {'token': token}) result = self.client_post('/json/users/me/apns_device_token', {'token': token})
self.assert_json_success(result) self.assert_json_success(result)
result = self.client_delete('/json/users/me/apns_device_token', {'token': token}) result = self.client_delete('/json/users/me/apns_device_token', {'token': token})
@@ -154,7 +154,7 @@ class GCMTokenTests(AuthedTestCase):
email = "cordelia@zulip.com" email = "cordelia@zulip.com"
self.login(email) self.login(email)
result = self.client.post('/json/users/me/apns_device_token', {'token': "test_token"}) result = self.client_post('/json/users/me/apns_device_token', {'token': "test_token"})
self.assert_json_success(result) self.assert_json_success(result)
def test_delete_token(self): def test_delete_token(self):
@@ -163,7 +163,7 @@ class GCMTokenTests(AuthedTestCase):
self.login(email) self.login(email)
token = "test_token" token = "test_token"
result = self.client.post('/json/users/me/android_gcm_reg_id', {'token': token}) result = self.client_post('/json/users/me/android_gcm_reg_id', {'token': token})
self.assert_json_success(result) self.assert_json_success(result)
result = self.client.delete('/json/users/me/android_gcm_reg_id', urllib.parse.urlencode({'token': token})) result = self.client.delete('/json/users/me/android_gcm_reg_id', urllib.parse.urlencode({'token': token}))
@@ -174,9 +174,9 @@ class GCMTokenTests(AuthedTestCase):
token = "test_token" token = "test_token"
self.login("cordelia@zulip.com") self.login("cordelia@zulip.com")
result = self.client.post('/json/users/me/android_gcm_reg_id', {'token': token}) result = self.client_post('/json/users/me/android_gcm_reg_id', {'token': token})
self.assert_json_success(result) self.assert_json_success(result)
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post('/json/users/me/android_gcm_reg_id', {'token': token}) result = self.client_post('/json/users/me/android_gcm_reg_id', {'token': token})
self.assert_json_success(result) self.assert_json_success(result)

View File

@@ -80,7 +80,7 @@ class JiraHookTests(WebhookTestCase):
# type: () -> None # type: () -> None
url = self.build_webhook_url() url = self.build_webhook_url()
result = self.client.post(url, result = self.client_post(url,
self.get_body('unknown'), self.get_body('unknown'),
stream_name="jira", stream_name="jira",
content_type="application/json") content_type="application/json")
@@ -301,7 +301,7 @@ class GithubV1HookTests(WebhookTestCase):
prior_count = Message.objects.count() prior_count = Message.objects.count()
result = self.client.post(self.URL_TEMPLATE, data) result = self.client_post(self.URL_TEMPLATE, data)
self.assert_json_success(result) self.assert_json_success(result)
after_count = Message.objects.count() after_count = Message.objects.count()
@@ -433,7 +433,7 @@ class GithubV2HookTests(WebhookTestCase):
prior_count = Message.objects.count() prior_count = Message.objects.count()
result = self.client.post(self.URL_TEMPLATE, data) result = self.client_post(self.URL_TEMPLATE, data)
self.assert_json_success(result) self.assert_json_success(result)
after_count = Message.objects.count() after_count = Message.objects.count()
@@ -1064,7 +1064,7 @@ class TeamcityHookTests(WebhookTestCase):
# type: () -> None # type: () -> None
expected_message = u"Your personal build of Project :: Compile build 5535 - CL 123456 is broken with status Exit code 1 (new)! :thumbsdown:\nDetails: [changes](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952&tab=buildChangesDiv), [build log](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952)" expected_message = u"Your personal build of Project :: Compile build 5535 - CL 123456 is broken with status Exit code 1 (new)! :thumbsdown:\nDetails: [changes](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952&tab=buildChangesDiv), [build log](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952)"
payload = ujson.dumps(ujson.loads(self.fixture_data(self.FIXTURE_DIR_NAME, 'personal'))) payload = ujson.dumps(ujson.loads(self.fixture_data(self.FIXTURE_DIR_NAME, 'personal')))
self.client.post(self.url, payload, content_type="application/json") self.client_post(self.url, payload, content_type="application/json")
msg = self.get_last_message() msg = self.get_last_message()
self.assertEqual(msg.content, expected_message) self.assertEqual(msg.content, expected_message)
@@ -1408,7 +1408,7 @@ class CrashlyticsHookTests(WebhookTestCase):
last_message_before_request = self.get_last_message() last_message_before_request = self.get_last_message()
payload = self.get_body('verification') payload = self.get_body('verification')
url = self.build_webhook_url() url = self.build_webhook_url()
result = self.client.post(url, payload, content_type="application/json") result = self.client_post(url, payload, content_type="application/json")
last_message_after_request = self.get_last_message() last_message_after_request = self.get_last_message()
self.assert_json_success(result) self.assert_json_success(result)
self.assertEqual(last_message_after_request.pk, last_message_before_request.pk) self.assertEqual(last_message_after_request.pk, last_message_before_request.pk)

View File

@@ -19,7 +19,7 @@ class TranslationTestCase(AuthedTestCase):
aware. aware.
""" """
# e.g. self.client.post(url) if method is "post" # e.g. self.client_post(url) if method is "post"
def fetch(self, method, url, expected_status, **kwargs): def fetch(self, method, url, expected_status, **kwargs):
# type: (str, str, int, **Any) -> HttpResponse # type: (str, str, int, **Any) -> HttpResponse
response = getattr(self.client, method)(url, **kwargs) response = getattr(self.client, method)(url, **kwargs)
@@ -75,7 +75,7 @@ class JsonTranslationTestCase(AuthedTestCase):
mock_gettext.return_value = dummy_value mock_gettext.return_value = dummy_value
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/refer_friend", result = self.client_post("/json/refer_friend",
HTTP_ACCEPT_LANGUAGE='de') HTTP_ACCEPT_LANGUAGE='de')
self.assert_json_error_contains(result, self.assert_json_error_contains(result,

View File

@@ -78,7 +78,7 @@ class TestGenerateRealmCreationLink(AuthedTestCase):
# Create Realm with generated link # Create Realm with generated link
self.assertIsNone(get_realm(domain)) self.assertIsNone(get_realm(domain))
result = self.client.post(generated_link, {'email': email}) result = self.client_post(generated_link, {'email': email})
self.assertEquals(result.status_code, 302) self.assertEquals(result.status_code, 302)
self.assertTrue(result["Location"].endswith( self.assertTrue(result["Location"].endswith(
"/accounts/send_confirm/%s@%s" % (username, domain))) "/accounts/send_confirm/%s@%s" % (username, domain)))

View File

@@ -335,7 +335,7 @@ class StreamMessagesTest(AuthedTestCase):
user_profile = get_user_profile_by_email("iago@zulip.com") user_profile = get_user_profile_by_email("iago@zulip.com")
do_change_is_admin(user_profile, True, 'api_super_user') do_change_is_admin(user_profile, True, 'api_super_user')
result = self.client.post("/api/v1/send_message", {"type": "stream", result = self.client_post("/api/v1/send_message", {"type": "stream",
"to": "Verona", "to": "Verona",
"sender": "cordelia@zulip.com", "sender": "cordelia@zulip.com",
"client": "test suite", "client": "test suite",
@@ -346,7 +346,7 @@ class StreamMessagesTest(AuthedTestCase):
"api-key": user_profile.api_key}) "api-key": user_profile.api_key})
self.assert_json_success(result) self.assert_json_success(result)
do_change_is_admin(user_profile, False, 'api_super_user') do_change_is_admin(user_profile, False, 'api_super_user')
result = self.client.post("/api/v1/send_message", {"type": "stream", result = self.client_post("/api/v1/send_message", {"type": "stream",
"to": "Verona", "to": "Verona",
"sender": "cordelia@zulip.com", "sender": "cordelia@zulip.com",
"client": "test suite", "client": "test suite",
@@ -460,7 +460,7 @@ class MessagePOSTTest(AuthedTestCase):
successful. successful.
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/messages", {"type": "stream", result = self.client_post("/json/messages", {"type": "stream",
"to": "Verona", "to": "Verona",
"client": "test suite", "client": "test suite",
"content": "Test message", "content": "Test message",
@@ -473,7 +473,7 @@ class MessagePOSTTest(AuthedTestCase):
""" """
email = "hamlet@zulip.com" email = "hamlet@zulip.com"
api_key = self.get_api_key(email) api_key = self.get_api_key(email)
result = self.client.post("/api/v1/send_message", {"type": "stream", result = self.client_post("/api/v1/send_message", {"type": "stream",
"to": "Verona", "to": "Verona",
"client": "test suite", "client": "test suite",
"content": "Test message", "content": "Test message",
@@ -492,7 +492,7 @@ class MessagePOSTTest(AuthedTestCase):
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = get_user_profile_by_email("hamlet@zulip.com")
user_profile.default_sending_stream = get_stream('Verona', user_profile.realm) user_profile.default_sending_stream = get_stream('Verona', user_profile.realm)
user_profile.save() user_profile.save()
result = self.client.post("/api/v1/send_message", {"type": "stream", result = self.client_post("/api/v1/send_message", {"type": "stream",
"client": "test suite", "client": "test suite",
"content": "Test message no to", "content": "Test message no to",
"subject": "Test subject", "subject": "Test subject",
@@ -509,7 +509,7 @@ class MessagePOSTTest(AuthedTestCase):
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
self.assertFalse(Stream.objects.filter(name="nonexistent_stream")) self.assertFalse(Stream.objects.filter(name="nonexistent_stream"))
result = self.client.post("/json/messages", {"type": "stream", result = self.client_post("/json/messages", {"type": "stream",
"to": "nonexistent_stream", "to": "nonexistent_stream",
"client": "test suite", "client": "test suite",
"content": "Test message", "content": "Test message",
@@ -521,7 +521,7 @@ class MessagePOSTTest(AuthedTestCase):
Sending a personal message to a valid username is successful. Sending a personal message to a valid username is successful.
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"content": "Test message", "content": "Test message",
"client": "test suite", "client": "test suite",
"to": "othello@zulip.com"}) "to": "othello@zulip.com"})
@@ -532,7 +532,7 @@ class MessagePOSTTest(AuthedTestCase):
Sending a personal message to an invalid email returns error JSON. Sending a personal message to an invalid email returns error JSON.
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"content": "Test message", "content": "Test message",
"client": "test suite", "client": "test suite",
"to": "nonexistent"}) "to": "nonexistent"})
@@ -543,7 +543,7 @@ class MessagePOSTTest(AuthedTestCase):
Sending a message of unknown type returns error JSON. Sending a message of unknown type returns error JSON.
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/messages", {"type": "invalid type", result = self.client_post("/json/messages", {"type": "invalid type",
"content": "Test message", "content": "Test message",
"client": "test suite", "client": "test suite",
"to": "othello@zulip.com"}) "to": "othello@zulip.com"})
@@ -554,7 +554,7 @@ class MessagePOSTTest(AuthedTestCase):
Sending a message that is empty or only whitespace should fail Sending a message that is empty or only whitespace should fail
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"content": " ", "content": " ",
"client": "test suite", "client": "test suite",
"to": "othello@zulip.com"}) "to": "othello@zulip.com"})
@@ -565,7 +565,7 @@ class MessagePOSTTest(AuthedTestCase):
Sending a mirrored huddle message works Sending a mirrored huddle message works
""" """
self.login("starnine@mit.edu") self.login("starnine@mit.edu")
result = self.client.post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"sender": "sipbtest@mit.edu", "sender": "sipbtest@mit.edu",
"content": "Test message", "content": "Test message",
"client": "zephyr_mirror", "client": "zephyr_mirror",
@@ -578,7 +578,7 @@ class MessagePOSTTest(AuthedTestCase):
Sending a mirrored personal message works Sending a mirrored personal message works
""" """
self.login("starnine@mit.edu") self.login("starnine@mit.edu")
result = self.client.post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"sender": "sipbtest@mit.edu", "sender": "sipbtest@mit.edu",
"content": "Test message", "content": "Test message",
"client": "zephyr_mirror", "client": "zephyr_mirror",
@@ -598,10 +598,10 @@ class MessagePOSTTest(AuthedTestCase):
with mock.patch('DNS.dnslookup', return_value=[['starnine:*:84233:101:Athena Consulting Exchange User,,,:/mit/starnine:/bin/bash']]): with mock.patch('DNS.dnslookup', return_value=[['starnine:*:84233:101:Athena Consulting Exchange User,,,:/mit/starnine:/bin/bash']]):
self.login("starnine@mit.edu") self.login("starnine@mit.edu")
result1 = self.client.post("/json/messages", msg) result1 = self.client_post("/json/messages", msg)
with mock.patch('DNS.dnslookup', return_value=[['espuser:*:95494:101:Esp Classroom,,,:/mit/espuser:/bin/athena/bash']]): with mock.patch('DNS.dnslookup', return_value=[['espuser:*:95494:101:Esp Classroom,,,:/mit/espuser:/bin/athena/bash']]):
self.login("espuser@mit.edu") self.login("espuser@mit.edu")
result2 = self.client.post("/json/messages", msg) result2 = self.client_post("/json/messages", msg)
self.assertEqual(ujson.loads(result1.content)['id'], self.assertEqual(ujson.loads(result1.content)['id'],
ujson.loads(result2.content)['id']) ujson.loads(result2.content)['id'])
@@ -614,7 +614,7 @@ class MessagePOSTTest(AuthedTestCase):
long_message = "A" * (MAX_MESSAGE_LENGTH + 1) long_message = "A" * (MAX_MESSAGE_LENGTH + 1)
post_data = {"type": "stream", "to": "Verona", "client": "test suite", post_data = {"type": "stream", "to": "Verona", "client": "test suite",
"content": long_message, "subject": "Test subject"} "content": long_message, "subject": "Test subject"}
result = self.client.post("/json/messages", post_data) result = self.client_post("/json/messages", post_data)
self.assert_json_success(result) self.assert_json_success(result)
sent_message = self.get_last_message() sent_message = self.get_last_message()
@@ -630,7 +630,7 @@ class MessagePOSTTest(AuthedTestCase):
long_topic = "A" * (MAX_SUBJECT_LENGTH + 1) long_topic = "A" * (MAX_SUBJECT_LENGTH + 1)
post_data = {"type": "stream", "to": "Verona", "client": "test suite", post_data = {"type": "stream", "to": "Verona", "client": "test suite",
"content": "test content", "subject": long_topic} "content": "test content", "subject": long_topic}
result = self.client.post("/json/messages", post_data) result = self.client_post("/json/messages", post_data)
self.assert_json_success(result) self.assert_json_success(result)
sent_message = self.get_last_message() sent_message = self.get_last_message()
@@ -639,7 +639,7 @@ class MessagePOSTTest(AuthedTestCase):
def test_send_forged_message_as_not_superuser(self): def test_send_forged_message_as_not_superuser(self):
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/messages", {"type": "stream", result = self.client_post("/json/messages", {"type": "stream",
"to": "Verona", "to": "Verona",
"client": "test suite", "client": "test suite",
"content": "Test message", "content": "Test message",
@@ -649,7 +649,7 @@ class MessagePOSTTest(AuthedTestCase):
def test_send_message_as_not_superuser_to_different_domain(self): def test_send_message_as_not_superuser_to_different_domain(self):
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/messages", {"type": "stream", result = self.client_post("/json/messages", {"type": "stream",
"to": "Verona", "to": "Verona",
"client": "test suite", "client": "test suite",
"content": "Test message", "content": "Test message",
@@ -665,7 +665,7 @@ class MessagePOSTTest(AuthedTestCase):
user.is_api_super_user = True user.is_api_super_user = True
user.save() user.save()
self.login(email, password) self.login(email, password)
result = self.client.post("/json/messages", {"type": "stream", result = self.client_post("/json/messages", {"type": "stream",
"to": "Verona", "to": "Verona",
"client": "test suite", "client": "test suite",
"content": "Test message", "content": "Test message",
@@ -677,7 +677,7 @@ class MessagePOSTTest(AuthedTestCase):
def test_send_message_when_sender_is_not_set(self): def test_send_message_when_sender_is_not_set(self):
self.login("starnine@mit.edu") self.login("starnine@mit.edu")
result = self.client.post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"content": "Test message", "content": "Test message",
"client": "zephyr_mirror", "client": "zephyr_mirror",
"to": "starnine@mit.edu"}) "to": "starnine@mit.edu"})
@@ -685,7 +685,7 @@ class MessagePOSTTest(AuthedTestCase):
def test_send_message_as_not_superuser_when_type_is_not_private(self): def test_send_message_as_not_superuser_when_type_is_not_private(self):
self.login("starnine@mit.edu") self.login("starnine@mit.edu")
result = self.client.post("/json/messages", {"type": "not-private", result = self.client_post("/json/messages", {"type": "not-private",
"sender": "sipbtest@mit.edu", "sender": "sipbtest@mit.edu",
"content": "Test message", "content": "Test message",
"client": "zephyr_mirror", "client": "zephyr_mirror",
@@ -696,7 +696,7 @@ class MessagePOSTTest(AuthedTestCase):
def test_send_message_create_mirrored_message_user_returns_invalid_input(self, create_mirrored_message_users_mock): def test_send_message_create_mirrored_message_user_returns_invalid_input(self, create_mirrored_message_users_mock):
create_mirrored_message_users_mock.return_value = (False, True) create_mirrored_message_users_mock.return_value = (False, True)
self.login("starnine@mit.edu") self.login("starnine@mit.edu")
result = self.client.post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"sender": "sipbtest@mit.edu", "sender": "sipbtest@mit.edu",
"content": "Test message", "content": "Test message",
"client": "zephyr_mirror", "client": "zephyr_mirror",
@@ -712,7 +712,7 @@ class MessagePOSTTest(AuthedTestCase):
user.realm.domain = 'not_mit.edu' user.realm.domain = 'not_mit.edu'
user.realm.save() user.realm.save()
self.login("starnine@mit.edu") self.login("starnine@mit.edu")
result = self.client.post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"sender": "sipbtest@mit.edu", "sender": "sipbtest@mit.edu",
"content": "Test message", "content": "Test message",
"client": "zephyr_mirror", "client": "zephyr_mirror",
@@ -739,14 +739,14 @@ class EditMessageTest(AuthedTestCase):
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM, msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
subject="editing", content="before edit") subject="editing", content="before edit")
result = self.client.post("/json/update_message", { result = self.client_post("/json/update_message", {
'message_id': msg_id, 'message_id': msg_id,
'content': 'after edit' 'content': 'after edit'
}) })
self.assert_json_success(result) self.assert_json_success(result)
self.check_message(msg_id, content="after edit") self.check_message(msg_id, content="after edit")
result = self.client.post("/json/update_message", { result = self.client_post("/json/update_message", {
'message_id': msg_id, 'message_id': msg_id,
'subject': 'edited' 'subject': 'edited'
}) })
@@ -757,7 +757,7 @@ class EditMessageTest(AuthedTestCase):
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM, msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
subject="editing", content="before edit") subject="editing", content="before edit")
result = self.client.post("/json/update_message", { result = self.client_post("/json/update_message", {
'message_id': msg_id, 'message_id': msg_id,
}) })
self.assert_json_error(result, "Nothing to change") self.assert_json_error(result, "Nothing to change")
@@ -766,7 +766,7 @@ class EditMessageTest(AuthedTestCase):
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM, msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
subject="editing", content="before edit") subject="editing", content="before edit")
result = self.client.post("/json/update_message", { result = self.client_post("/json/update_message", {
'message_id': msg_id, 'message_id': msg_id,
'subject': ' ' 'subject': ' '
}) })
@@ -776,7 +776,7 @@ class EditMessageTest(AuthedTestCase):
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM, msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
subject="editing", content="before edit") subject="editing", content="before edit")
result = self.client.post("/json/update_message", { result = self.client_post("/json/update_message", {
'message_id': msg_id, 'message_id': msg_id,
'content': ' ' 'content': ' '
}) })
@@ -797,7 +797,7 @@ class EditMessageTest(AuthedTestCase):
params_dict = { 'message_id': id_, 'subject': new_subject } params_dict = { 'message_id': id_, 'subject': new_subject }
if not topic_only: if not topic_only:
params_dict['content'] = new_content params_dict['content'] = new_content
result = self.client.post("/json/update_message", params_dict) result = self.client_post("/json/update_message", params_dict)
self.assert_json_success(result) self.assert_json_success(result)
if topic_only: if topic_only:
self.check_message(id_, subject=new_subject) self.check_message(id_, subject=new_subject)
@@ -813,7 +813,7 @@ class EditMessageTest(AuthedTestCase):
params_dict = { 'message_id': id_, 'subject': new_subject } params_dict = { 'message_id': id_, 'subject': new_subject }
if not topic_only: if not topic_only:
params_dict['content'] = new_content params_dict['content'] = new_content
result = self.client.post("/json/update_message", params_dict) result = self.client_post("/json/update_message", params_dict)
message = Message.objects.get(id=id_) message = Message.objects.get(id=id_)
self.assert_json_error(result, error) self.assert_json_error(result, error)
self.check_message(id_, subject=old_subject, content=old_content) self.check_message(id_, subject=old_subject, content=old_content)
@@ -861,7 +861,7 @@ class EditMessageTest(AuthedTestCase):
id5 = self.send_message("iago@zulip.com", "Scotland", Recipient.STREAM, id5 = self.send_message("iago@zulip.com", "Scotland", Recipient.STREAM,
subject="topic1") subject="topic1")
result = self.client.post("/json/update_message", { result = self.client_post("/json/update_message", {
'message_id': id1, 'message_id': id1,
'subject': 'edited', 'subject': 'edited',
'propagate_mode': 'change_later' 'propagate_mode': 'change_later'
@@ -889,7 +889,7 @@ class EditMessageTest(AuthedTestCase):
id6 = self.send_message("iago@zulip.com", "Scotland", Recipient.STREAM, id6 = self.send_message("iago@zulip.com", "Scotland", Recipient.STREAM,
subject="topic3") subject="topic3")
result = self.client.post("/json/update_message", { result = self.client_post("/json/update_message", {
'message_id': id2, 'message_id': id2,
'subject': 'edited', 'subject': 'edited',
'propagate_mode': 'change_all' 'propagate_mode': 'change_all'
@@ -1076,7 +1076,7 @@ class MirroredMessageUsersTest(TestCase):
class StarTests(AuthedTestCase): class StarTests(AuthedTestCase):
def change_star(self, messages, add=True): def change_star(self, messages, add=True):
return self.client.post("/json/messages/flags", return self.client_post("/json/messages/flags",
{"messages": ujson.dumps(messages), {"messages": ujson.dumps(messages),
"op": "add" if add else "remove", "op": "add" if add else "remove",
"flag": "starred"}) "flag": "starred"})

View File

@@ -40,7 +40,7 @@ class PublicURLTest(TestCase):
def fetch(self, method, urls, expected_status): def fetch(self, method, urls, expected_status):
# type: (str, List[str], int) -> None # type: (str, List[str], int) -> None
for url in urls: for url in urls:
response = getattr(self.client, method)(url) # e.g. self.client.post(url) if method is "post" response = getattr(self.client, method)(url) # e.g. self.client_post(url) if method is "post"
self.assertEqual(response.status_code, expected_status, self.assertEqual(response.status_code, expected_status,
msg="Expected %d, received %d for %s to %s" % ( msg="Expected %d, received %d for %s to %s" % (
expected_status, response.status_code, method, url)) expected_status, response.status_code, method, url))
@@ -177,7 +177,7 @@ class LoginTest(AuthedTestCase):
def test_logout(self): def test_logout(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
self.client.post('/accounts/logout/') self.client_post('/accounts/logout/')
self.assertIsNone(get_session_dict_user(self.client.session)) self.assertIsNone(get_session_dict_user(self.client.session))
def test_non_ascii_login(self): def test_non_ascii_login(self):
@@ -192,11 +192,11 @@ class LoginTest(AuthedTestCase):
self.register("test", password) self.register("test", password)
user_profile = get_user_profile_by_email(email) user_profile = get_user_profile_by_email(email)
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id) self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
self.client.post('/accounts/logout/') self.client_post('/accounts/logout/')
self.assertIsNone(get_session_dict_user(self.client.session)) self.assertIsNone(get_session_dict_user(self.client.session))
# Logging in succeeds. # Logging in succeeds.
self.client.post('/accounts/logout/') self.client_post('/accounts/logout/')
self.login(email, password) self.login(email, password)
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id) self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
@@ -216,7 +216,7 @@ class LoginTest(AuthedTestCase):
Realm.objects.create(domain=domain, name="Test Inc.") Realm.objects.create(domain=domain, name="Test Inc.")
# Start the signup process by supplying an email address. # Start the signup process by supplying an email address.
result = self.client.post('/accounts/home/', {'email': email}) result = self.client_post('/accounts/home/', {'email': email})
# Check the redirect telling you to check your mail for a confirmation # Check the redirect telling you to check your mail for a confirmation
# link. # link.
@@ -256,7 +256,7 @@ class LoginTest(AuthedTestCase):
params = { params = {
'invitee_emails': ujson.dumps(invitees) 'invitee_emails': ujson.dumps(invitees)
} }
result = self.client.post('/json/bulk_invite_users', params) result = self.client_post('/json/bulk_invite_users', params)
self.assert_json_success(result) self.assert_json_success(result)
# We really did email these users, and they have PreregistrationUser # We really did email these users, and they have PreregistrationUser
@@ -284,7 +284,7 @@ class InviteUserTest(AuthedTestCase):
streams should be a list of strings. streams should be a list of strings.
""" """
return self.client.post("/json/invite_users", return self.client_post("/json/invite_users",
{"invitee_emails": users, {"invitee_emails": users,
"stream": streams}) "stream": streams})
@@ -303,7 +303,7 @@ class InviteUserTest(AuthedTestCase):
params = { params = {
'invitee_emails': ujson.dumps(invitees) 'invitee_emails': ujson.dumps(invitees)
} }
result = self.client.post('/json/bulk_invite_users', params) result = self.client_post('/json/bulk_invite_users', params)
self.assert_json_success(result) self.assert_json_success(result)
self.check_sent_emails(invitees) self.check_sent_emails(invitees)
@@ -370,7 +370,7 @@ earl-test@zulip.com""", ["Denmark"]))
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
self.assert_json_error( self.assert_json_error(
self.client.post("/json/invite_users", {"invitee_emails": "foo@zulip.com"}), self.client_post("/json/invite_users", {"invitee_emails": "foo@zulip.com"}),
"You must specify at least one stream for invitees to join.") "You must specify at least one stream for invitees to join.")
for address in ("noatsign.com", "outsideyourdomain@example.net"): for address in ("noatsign.com", "outsideyourdomain@example.net"):
@@ -396,7 +396,7 @@ earl-test@zulip.com""", ["Denmark"]))
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
self.assert_json_error( self.assert_json_error(
self.client.post("/json/invite_users", self.client_post("/json/invite_users",
{"invitee_emails": "hamlet@zulip.com", {"invitee_emails": "hamlet@zulip.com",
"stream": ["Denmark"]}), "stream": ["Denmark"]}),
"We weren't able to invite anyone.") "We weren't able to invite anyone.")
@@ -415,7 +415,7 @@ earl-test@zulip.com""", ["Denmark"]))
existing = ["hamlet@zulip.com", "othello@zulip.com"] existing = ["hamlet@zulip.com", "othello@zulip.com"]
new = ["foo-test@zulip.com", "bar-test@zulip.com"] new = ["foo-test@zulip.com", "bar-test@zulip.com"]
result = self.client.post("/json/invite_users", result = self.client_post("/json/invite_users",
{"invitee_emails": "\n".join(existing + new), {"invitee_emails": "\n".join(existing + new),
"stream": ["Denmark"]}) "stream": ["Denmark"]})
self.assert_json_error(result, self.assert_json_error(result,
@@ -574,7 +574,7 @@ class RealmCreationTest(AuthedTestCase):
with self.settings(OPEN_REALM_CREATION=True): with self.settings(OPEN_REALM_CREATION=True):
# Create new realm with the email # Create new realm with the email
result = self.client.post('/create_realm/', {'email': email}) result = self.client_post('/create_realm/', {'email': email})
self.assertEquals(result.status_code, 302) self.assertEquals(result.status_code, 302)
self.assertTrue(result["Location"].endswith( self.assertTrue(result["Location"].endswith(
"/accounts/send_confirm/%s@%s" % (username, domain))) "/accounts/send_confirm/%s@%s" % (username, domain)))

View File

@@ -52,7 +52,7 @@ class StreamAdminTest(AuthedTestCase):
params = { params = {
'stream_name': 'private_stream' 'stream_name': 'private_stream'
} }
result = self.client.post("/json/make_stream_public", params) result = self.client_post("/json/make_stream_public", params)
self.assert_json_error(result, 'You are not invited to this stream.') self.assert_json_error(result, 'You are not invited to this stream.')
do_add_subscription(user_profile, stream) do_add_subscription(user_profile, stream)
@@ -61,7 +61,7 @@ class StreamAdminTest(AuthedTestCase):
params = { params = {
'stream_name': 'private_stream' 'stream_name': 'private_stream'
} }
result = self.client.post("/json/make_stream_public", params) result = self.client_post("/json/make_stream_public", params)
self.assert_json_success(result) self.assert_json_success(result)
stream = Stream.objects.get(name='private_stream', realm=realm) stream = Stream.objects.get(name='private_stream', realm=realm)
self.assertFalse(stream.invite_only) self.assertFalse(stream.invite_only)
@@ -78,7 +78,7 @@ class StreamAdminTest(AuthedTestCase):
params = { params = {
'stream_name': 'public_stream' 'stream_name': 'public_stream'
} }
result = self.client.post("/json/make_stream_private", params) result = self.client_post("/json/make_stream_private", params)
self.assert_json_success(result) self.assert_json_success(result)
stream = Stream.objects.get(name='public_stream', realm=realm) stream = Stream.objects.get(name='public_stream', realm=realm)
self.assertTrue(stream.invite_only) self.assertTrue(stream.invite_only)
@@ -139,7 +139,7 @@ class StreamAdminTest(AuthedTestCase):
events = [] # type: List[Dict[str, Any]] events = [] # type: List[Dict[str, Any]]
with tornado_redirected_to_list(events): with tornado_redirected_to_list(events):
result = self.client.post('/json/rename_stream?old_name=stream_name1&new_name=stream_name2') result = self.client_post('/json/rename_stream?old_name=stream_name1&new_name=stream_name2')
self.assert_json_success(result) self.assert_json_success(result)
event = events[1]['event'] event = events[1]['event']
@@ -172,7 +172,7 @@ class StreamAdminTest(AuthedTestCase):
realm = user_profile.realm realm = user_profile.realm
stream, _ = create_stream_if_needed(realm, 'stream_name1') stream, _ = create_stream_if_needed(realm, 'stream_name1')
result = self.client.post('/json/rename_stream?old_name=stream_name1&new_name=stream_name2') result = self.client_post('/json/rename_stream?old_name=stream_name1&new_name=stream_name2')
self.assert_json_error(result, 'Must be a realm administrator') self.assert_json_error(result, 'Must be a realm administrator')
def test_change_stream_description(self): def test_change_stream_description(self):
@@ -288,7 +288,7 @@ class StreamAdminTest(AuthedTestCase):
self.assertNotIn(deactivated_stream_name, public_streams) self.assertNotIn(deactivated_stream_name, public_streams)
# Even if you could guess the new name, you can't subscribe to it. # Even if you could guess the new name, you can't subscribe to it.
result = self.client.post( result = self.client_post(
"/json/users/me/subscriptions", "/json/users/me/subscriptions",
{"subscriptions": ujson.dumps([{"name": deactivated_stream_name}])}) {"subscriptions": ujson.dumps([{"name": deactivated_stream_name}])})
self.assert_json_error( self.assert_json_error(
@@ -355,7 +355,7 @@ class StreamAdminTest(AuthedTestCase):
if other_user_subbed: if other_user_subbed:
do_add_subscription(other_user_profile, stream, no_log=True) do_add_subscription(other_user_profile, stream, no_log=True)
result = self.client.post( result = self.client_post(
"/json/subscriptions/remove", "/json/subscriptions/remove",
{"subscriptions": ujson.dumps([stream.name]), {"subscriptions": ujson.dumps([stream.name]),
"principals": ujson.dumps([other_email])}) "principals": ujson.dumps([other_email])})
@@ -465,7 +465,7 @@ class StreamAdminTest(AuthedTestCase):
stream_name = u"hümbüǵ" stream_name = u"hümbüǵ"
stream, _ = create_stream_if_needed(realm, stream_name) stream, _ = create_stream_if_needed(realm, stream_name)
result = self.client.post("/json/subscriptions/remove", result = self.client_post("/json/subscriptions/remove",
{"subscriptions": ujson.dumps([stream.name]), {"subscriptions": ujson.dumps([stream.name]),
"principals": ujson.dumps(["baduser@zulip.com"])}) "principals": ujson.dumps(["baduser@zulip.com"])})
self.assert_json_error( self.assert_json_error(
@@ -548,7 +548,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
sub = old_subs[0] sub = old_subs[0]
stream_name = sub['name'] stream_name = sub['name']
new_color = "#ffffff" # TODO: ensure that this is different from old_color new_color = "#ffffff" # TODO: ensure that this is different from old_color
result = self.client.post( result = self.client_post(
"/json/subscriptions/property", "/json/subscriptions/property",
{"subscription_data": ujson.dumps([{"property": "color", {"subscription_data": ujson.dumps([{"property": "color",
"stream": stream_name, "stream": stream_name,
@@ -581,7 +581,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
""" """
test_email = "hamlet@zulip.com" test_email = "hamlet@zulip.com"
self.login(test_email) self.login(test_email)
result = self.client.post( result = self.client_post(
"/json/subscriptions/property", "/json/subscriptions/property",
{"subscription_data": ujson.dumps([{"property": "color", {"subscription_data": ujson.dumps([{"property": "color",
"value": "#ffffff"}])}) "value": "#ffffff"}])})
@@ -614,7 +614,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
test_email = "hamlet@zulip.com" test_email = "hamlet@zulip.com"
self.login(test_email) self.login(test_email)
subs = gather_subscriptions(get_user_profile_by_email(test_email))[0] subs = gather_subscriptions(get_user_profile_by_email(test_email))[0]
result = self.client.post( result = self.client_post(
"/json/subscriptions/property", "/json/subscriptions/property",
{"subscription_data": ujson.dumps([{"property": "color", {"subscription_data": ujson.dumps([{"property": "color",
"stream": subs[0]["name"]}])}) "stream": subs[0]["name"]}])})
@@ -636,7 +636,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
sub = old_subs[0] sub = old_subs[0]
stream_name = sub['name'] stream_name = sub['name']
new_pin_to_top = not sub['pin_to_top'] new_pin_to_top = not sub['pin_to_top']
result = self.client.post( result = self.client_post(
"/json/subscriptions/property", "/json/subscriptions/property",
{"subscription_data": ujson.dumps([{"property": "pin_to_top", {"subscription_data": ujson.dumps([{"property": "pin_to_top",
"stream": stream_name, "stream": stream_name,
@@ -659,7 +659,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
subs = gather_subscriptions(get_user_profile_by_email(test_email))[0] subs = gather_subscriptions(get_user_profile_by_email(test_email))[0]
property_name = "in_home_view" property_name = "in_home_view"
result = self.client.post( result = self.client_post(
"/json/subscriptions/property", "/json/subscriptions/property",
{"subscription_data": ujson.dumps([{"property": property_name, {"subscription_data": ujson.dumps([{"property": property_name,
"value": "bad", "value": "bad",
@@ -669,7 +669,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
'%s is not a boolean' % (property_name,)) '%s is not a boolean' % (property_name,))
property_name = "desktop_notifications" property_name = "desktop_notifications"
result = self.client.post( result = self.client_post(
"/json/subscriptions/property", "/json/subscriptions/property",
{"subscription_data": ujson.dumps([{"property": property_name, {"subscription_data": ujson.dumps([{"property": property_name,
"value": "bad", "value": "bad",
@@ -679,7 +679,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
'%s is not a boolean' % (property_name,)) '%s is not a boolean' % (property_name,))
property_name = "audible_notifications" property_name = "audible_notifications"
result = self.client.post( result = self.client_post(
"/json/subscriptions/property", "/json/subscriptions/property",
{"subscription_data": ujson.dumps([{"property": property_name, {"subscription_data": ujson.dumps([{"property": property_name,
"value": "bad", "value": "bad",
@@ -689,7 +689,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
'%s is not a boolean' % (property_name,)) '%s is not a boolean' % (property_name,))
property_name = "color" property_name = "color"
result = self.client.post( result = self.client_post(
"/json/subscriptions/property", "/json/subscriptions/property",
{"subscription_data": ujson.dumps([{"property": property_name, {"subscription_data": ujson.dumps([{"property": property_name,
"value": False, "value": False,
@@ -704,7 +704,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
self.login(test_email) self.login(test_email)
stream_name = "invalid_stream" stream_name = "invalid_stream"
result = self.client.post( result = self.client_post(
"/json/subscriptions/property", "/json/subscriptions/property",
{"subscription_data": ujson.dumps([{"property": "in_home_view", {"subscription_data": ujson.dumps([{"property": "in_home_view",
"stream": stream_name, "stream": stream_name,
@@ -720,7 +720,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
test_email = "hamlet@zulip.com" test_email = "hamlet@zulip.com"
self.login(test_email) self.login(test_email)
subs = gather_subscriptions(get_user_profile_by_email(test_email))[0] subs = gather_subscriptions(get_user_profile_by_email(test_email))[0]
result = self.client.post( result = self.client_post(
"/json/subscriptions/property", "/json/subscriptions/property",
{"subscription_data": ujson.dumps([{"property": "bad", {"subscription_data": ujson.dumps([{"property": "bad",
"value": "bad", "value": "bad",
@@ -1379,7 +1379,7 @@ class SubscriptionAPITest(AuthedTestCase):
"removed": ["Denmark", "Scotland", "Verona"], "removed": ["Denmark", "Scotland", "Verona"],
"not_subscribed": ["Rome"], "result": "success"} "not_subscribed": ["Rome"], "result": "success"}
""" """
result = self.client.post("/json/subscriptions/remove", result = self.client_post("/json/subscriptions/remove",
{"subscriptions": ujson.dumps(subscriptions)}) {"subscriptions": ujson.dumps(subscriptions)})
self.assert_json_success(result) self.assert_json_success(result)
json = ujson.loads(result.content) json = ujson.loads(result.content)
@@ -1420,7 +1420,7 @@ class SubscriptionAPITest(AuthedTestCase):
random_streams = self.make_random_stream_names(self.streams) random_streams = self.make_random_stream_names(self.streams)
self.assertNotEqual(len(random_streams), 0) # necessary for full test coverage self.assertNotEqual(len(random_streams), 0) # necessary for full test coverage
streams_to_remove = random_streams[:1] # pick only one fake stream, to make checking the error message easy streams_to_remove = random_streams[:1] # pick only one fake stream, to make checking the error message easy
result = self.client.post("/json/subscriptions/remove", result = self.client_post("/json/subscriptions/remove",
{"subscriptions": ujson.dumps(streams_to_remove)}) {"subscriptions": ujson.dumps(streams_to_remove)})
self.assert_json_error(result, "Stream(s) (%s) do not exist" % (random_streams[0],)) self.assert_json_error(result, "Stream(s) (%s) do not exist" % (random_streams[0],))
@@ -1432,7 +1432,7 @@ class SubscriptionAPITest(AuthedTestCase):
subscribed values passed in as parameters. (If subscribed should not be subscribed values passed in as parameters. (If subscribed should not be
present, pass in None.) present, pass in None.)
""" """
result = self.client.post("/json/subscriptions/exists", result = self.client_post("/json/subscriptions/exists",
{"stream": stream}) {"stream": stream})
json = ujson.loads(result.content) json = ujson.loads(result.content)
self.assertIn("exists", json) self.assertIn("exists", json)
@@ -1484,7 +1484,7 @@ class SubscriptionAPITest(AuthedTestCase):
""" """
# currently, the only invalid stream name is the empty string # currently, the only invalid stream name is the empty string
invalid_stream_name = "" invalid_stream_name = ""
result = self.client.post("/json/subscriptions/exists", result = self.client_post("/json/subscriptions/exists",
{"stream": invalid_stream_name}) {"stream": invalid_stream_name})
self.assert_json_error(result, "Invalid characters in stream name") self.assert_json_error(result, "Invalid characters in stream name")
@@ -1494,7 +1494,7 @@ class SubscriptionAPITest(AuthedTestCase):
Call /json/subscriptions/exist on an existing stream and autosubscribe to it. Call /json/subscriptions/exist on an existing stream and autosubscribe to it.
""" """
stream_name = self.streams[0] stream_name = self.streams[0]
result = self.client.post("/json/subscriptions/exists", result = self.client_post("/json/subscriptions/exists",
{"stream": stream_name, "autosubscribe": True}) {"stream": stream_name, "autosubscribe": True})
self.assert_json_success(result) self.assert_json_success(result)
json = ujson.loads(result.content) json = ujson.loads(result.content)
@@ -1873,7 +1873,7 @@ class GetSubscribersTest(AuthedTestCase):
json_get_subscribers also returns the list of subscribers for a stream. json_get_subscribers also returns the list of subscribers for a stream.
""" """
stream_name = "unknown_stream" stream_name = "unknown_stream"
result = self.client.post("/json/get_subscribers", {"stream": stream_name}) result = self.client_post("/json/get_subscribers", {"stream": stream_name})
self.assert_json_error(result, "Stream does not exist: %s" % (stream_name,)) self.assert_json_error(result, "Stream does not exist: %s" % (stream_name,))
def test_json_get_subscribers(self): def test_json_get_subscribers(self):
@@ -1884,7 +1884,7 @@ class GetSubscribersTest(AuthedTestCase):
""" """
stream_name = gather_subscriptions(self.user_profile)[0][0]['name'] stream_name = gather_subscriptions(self.user_profile)[0][0]['name']
expected_subscribers = gather_subscriptions(self.user_profile)[0][0]['subscribers'] expected_subscribers = gather_subscriptions(self.user_profile)[0][0]['subscribers']
result = self.client.post("/json/get_subscribers", {"stream": stream_name}) result = self.client_post("/json/get_subscribers", {"stream": stream_name})
self.assert_json_success(result) self.assert_json_success(result)
result_dict = ujson.loads(result.content) result_dict = ujson.loads(result.content)
self.assertIn('subscribers', result_dict) self.assertIn('subscribers', result_dict)

View File

@@ -99,7 +99,7 @@ class UnreadCountTests(AuthedTestCase):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/messages/flags", result = self.client_post("/json/messages/flags",
{"messages": ujson.dumps(self.unread_msg_ids), {"messages": ujson.dumps(self.unread_msg_ids),
"op": "add", "op": "add",
"flag": "read"}) "flag": "read"})
@@ -113,7 +113,7 @@ class UnreadCountTests(AuthedTestCase):
found += 1 found += 1
self.assertEqual(found, 2) self.assertEqual(found, 2)
result = self.client.post("/json/messages/flags", result = self.client_post("/json/messages/flags",
{"messages": ujson.dumps([self.unread_msg_ids[1]]), {"messages": ujson.dumps([self.unread_msg_ids[1]]),
"op": "remove", "flag": "read"}) "op": "remove", "flag": "read"})
self.assert_json_success(result) self.assert_json_success(result)
@@ -134,12 +134,12 @@ class UnreadCountTests(AuthedTestCase):
self.send_message("hamlet@zulip.com", "cordelia@zulip.com", self.send_message("hamlet@zulip.com", "cordelia@zulip.com",
Recipient.PERSONAL, "test2")] Recipient.PERSONAL, "test2")]
result = self.client.post("/json/messages/flags", {"messages": ujson.dumps(message_ids), result = self.client_post("/json/messages/flags", {"messages": ujson.dumps(message_ids),
"op": "add", "op": "add",
"flag": "read"}) "flag": "read"})
self.assert_json_success(result) self.assert_json_success(result)
result = self.client.post("/json/messages/flags", {"messages": ujson.dumps([]), result = self.client_post("/json/messages/flags", {"messages": ujson.dumps([]),
"op": "remove", "op": "remove",
"flag": "read", "flag": "read",
"all": ujson.dumps(True)}) "all": ujson.dumps(True)})
@@ -159,7 +159,7 @@ class UnreadCountTests(AuthedTestCase):
events = [] # type: List[Dict[str, Any]] events = [] # type: List[Dict[str, Any]]
with tornado_redirected_to_list(events): with tornado_redirected_to_list(events):
result = self.client.post("/json/messages/flags", {"messages": ujson.dumps([]), result = self.client_post("/json/messages/flags", {"messages": ujson.dumps([]),
"op": "add", "op": "add",
"flag": "read", "flag": "read",
"stream_name": "test_stream"}) "stream_name": "test_stream"})
@@ -194,7 +194,7 @@ class UnreadCountTests(AuthedTestCase):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
invalid_stream_name = "" invalid_stream_name = ""
result = self.client.post("/json/messages/flags", {"messages": ujson.dumps([]), result = self.client_post("/json/messages/flags", {"messages": ujson.dumps([]),
"op": "add", "op": "add",
"flag": "read", "flag": "read",
"stream_name": invalid_stream_name}) "stream_name": invalid_stream_name})
@@ -210,7 +210,7 @@ class UnreadCountTests(AuthedTestCase):
unrelated_message_id = self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM, "hello", "Denmark2") unrelated_message_id = self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM, "hello", "Denmark2")
events = [] # type: List[Dict[str, Any]] events = [] # type: List[Dict[str, Any]]
with tornado_redirected_to_list(events): with tornado_redirected_to_list(events):
result = self.client.post("/json/messages/flags", {"messages": ujson.dumps([]), result = self.client_post("/json/messages/flags", {"messages": ujson.dumps([]),
"op": "add", "op": "add",
"flag": "read", "flag": "read",
"topic_name": "test_topic", "topic_name": "test_topic",
@@ -244,7 +244,7 @@ class UnreadCountTests(AuthedTestCase):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
invalid_topic_name = "abc" invalid_topic_name = "abc"
result = self.client.post("/json/messages/flags", {"messages": ujson.dumps([]), result = self.client_post("/json/messages/flags", {"messages": ujson.dumps([]),
"op": "add", "op": "add",
"flag": "read", "flag": "read",
"topic_name": invalid_topic_name, "topic_name": invalid_topic_name,

View File

@@ -52,7 +52,7 @@ class FileUploadTest(AuthedTestCase):
# Upload file via API # Upload file via API
auth_headers = self.api_auth('hamlet@zulip.com') auth_headers = self.api_auth('hamlet@zulip.com')
result = self.client.post('/api/v1/user_uploads', {'file': fp}, **auth_headers) result = self.client_post('/api/v1/user_uploads', {'file': fp}, **auth_headers)
json = ujson.loads(result.content) json = ujson.loads(result.content)
self.assertIn("uri", json) self.assertIn("uri", json)
uri = json["uri"] uri = json["uri"]
@@ -60,7 +60,7 @@ class FileUploadTest(AuthedTestCase):
self.assertEquals(base, uri[:len(base)]) self.assertEquals(base, uri[:len(base)])
# Download file via API # Download file via API
self.client.post('/accounts/logout/') self.client_post('/accounts/logout/')
response = self.client.get(uri, **auth_headers) response = self.client.get(uri, **auth_headers)
data = b"".join(response.streaming_content) data = b"".join(response.streaming_content)
self.assertEquals(b"zulip!", data) self.assertEquals(b"zulip!", data)
@@ -82,7 +82,7 @@ class FileUploadTest(AuthedTestCase):
fp2 = StringIO("pshaw!") fp2 = StringIO("pshaw!")
fp2.name = "b.txt" fp2.name = "b.txt"
result = self.client.post("/json/upload_file", {'f1': fp, 'f2': fp2}) result = self.client_post("/json/upload_file", {'f1': fp, 'f2': fp2})
self.assert_json_error(result, "You may only upload one file at a time") self.assert_json_error(result, "You may only upload one file at a time")
def test_no_file_upload_failure(self): def test_no_file_upload_failure(self):
@@ -92,7 +92,7 @@ class FileUploadTest(AuthedTestCase):
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/upload_file") result = self.client_post("/json/upload_file")
self.assert_json_error(result, "You must specify a file to upload") self.assert_json_error(result, "You must specify a file to upload")
# This test will go through the code path for uploading files onto LOCAL storage # This test will go through the code path for uploading files onto LOCAL storage
@@ -108,7 +108,7 @@ class FileUploadTest(AuthedTestCase):
fp = StringIO("zulip!") fp = StringIO("zulip!")
fp.name = "zulip.txt" fp.name = "zulip.txt"
result = self.client.post("/json/upload_file", {'file': fp}) result = self.client_post("/json/upload_file", {'file': fp})
self.assert_json_success(result) self.assert_json_success(result)
json = ujson.loads(result.content) json = ujson.loads(result.content)
self.assertIn("uri", json) self.assertIn("uri", json)
@@ -138,14 +138,14 @@ class FileUploadTest(AuthedTestCase):
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
d1 = StringIO("zulip!") d1 = StringIO("zulip!")
d1.name = "dummy_1.txt" d1.name = "dummy_1.txt"
result = self.client.post("/json/upload_file", {'file': d1}) result = self.client_post("/json/upload_file", {'file': d1})
json = ujson.loads(result.content) json = ujson.loads(result.content)
uri = json["uri"] uri = json["uri"]
d1_path_id = re.sub('/user_uploads/', '', uri) d1_path_id = re.sub('/user_uploads/', '', uri)
d2 = StringIO("zulip!") d2 = StringIO("zulip!")
d2.name = "dummy_2.txt" d2.name = "dummy_2.txt"
result = self.client.post("/json/upload_file", {'file': d2}) result = self.client_post("/json/upload_file", {'file': d2})
json = ujson.loads(result.content) json = ujson.loads(result.content)
uri = json["uri"] uri = json["uri"]
d2_path_id = re.sub('/user_uploads/', '', uri) d2_path_id = re.sub('/user_uploads/', '', uri)
@@ -177,7 +177,7 @@ class FileUploadTest(AuthedTestCase):
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
d1 = StringIO("zulip!") d1 = StringIO("zulip!")
d1.name = "dummy_1.txt" d1.name = "dummy_1.txt"
result = self.client.post("/json/upload_file", {'file': d1}) result = self.client_post("/json/upload_file", {'file': d1})
json = ujson.loads(result.content) json = ujson.loads(result.content)
uri = json["uri"] uri = json["uri"]
d1_path_id = re.sub('/user_uploads/', '', uri) d1_path_id = re.sub('/user_uploads/', '', uri)
@@ -199,12 +199,12 @@ class FileUploadTest(AuthedTestCase):
f3.name = "file3.txt" f3.name = "file3.txt"
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/upload_file", {'file': f1}) result = self.client_post("/json/upload_file", {'file': f1})
json = ujson.loads(result.content) json = ujson.loads(result.content)
uri = json["uri"] uri = json["uri"]
f1_path_id = re.sub('/user_uploads/', '', uri) f1_path_id = re.sub('/user_uploads/', '', uri)
result = self.client.post("/json/upload_file", {'file': f2}) result = self.client_post("/json/upload_file", {'file': f2})
json = ujson.loads(result.content) json = ujson.loads(result.content)
uri = json["uri"] uri = json["uri"]
f2_path_id = re.sub('/user_uploads/', '', uri) f2_path_id = re.sub('/user_uploads/', '', uri)
@@ -214,14 +214,14 @@ class FileUploadTest(AuthedTestCase):
"[f2.txt](http://localhost:9991/user_uploads/" + f2_path_id + ")") "[f2.txt](http://localhost:9991/user_uploads/" + f2_path_id + ")")
msg_id = self.send_message("hamlet@zulip.com", "test", Recipient.STREAM, body, "test") msg_id = self.send_message("hamlet@zulip.com", "test", Recipient.STREAM, body, "test")
result = self.client.post("/json/upload_file", {'file': f3}) result = self.client_post("/json/upload_file", {'file': f3})
json = ujson.loads(result.content) json = ujson.loads(result.content)
uri = json["uri"] uri = json["uri"]
f3_path_id = re.sub('/user_uploads/', '', uri) f3_path_id = re.sub('/user_uploads/', '', uri)
new_body = ("[f3.txt](http://localhost:9991/user_uploads/" + f3_path_id + ")" new_body = ("[f3.txt](http://localhost:9991/user_uploads/" + f3_path_id + ")"
"[f2.txt](http://localhost:9991/user_uploads/" + f2_path_id + ")") "[f2.txt](http://localhost:9991/user_uploads/" + f2_path_id + ")")
result = self.client.post("/json/update_message", { result = self.client_post("/json/update_message", {
'message_id': msg_id, 'message_id': msg_id,
'content': new_body 'content': new_body
}) })
@@ -238,7 +238,7 @@ class FileUploadTest(AuthedTestCase):
# Delete all the attachments from the message # Delete all the attachments from the message
new_body = "(deleted)" new_body = "(deleted)"
result = self.client.post("/json/update_message", { result = self.client_post("/json/update_message", {
'message_id': msg_id, 'message_id': msg_id,
'content': new_body 'content': new_body
}) })
@@ -267,7 +267,7 @@ class AvatarTest(AuthedTestCase):
fp1 = open(os.path.join(TEST_AVATAR_DIR, 'img.png'), 'rb') fp1 = open(os.path.join(TEST_AVATAR_DIR, 'img.png'), 'rb')
fp2 = open(os.path.join(TEST_AVATAR_DIR, 'img.png'), 'rb') fp2 = open(os.path.join(TEST_AVATAR_DIR, 'img.png'), 'rb')
result = self.client.post("/json/set_avatar", {'f1': fp1, 'f2': fp2}) result = self.client_post("/json/set_avatar", {'f1': fp1, 'f2': fp2})
self.assert_json_error(result, "You must upload exactly one avatar.") self.assert_json_error(result, "You must upload exactly one avatar.")
def test_no_file_upload_failure(self): def test_no_file_upload_failure(self):
@@ -277,7 +277,7 @@ class AvatarTest(AuthedTestCase):
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/set_avatar") result = self.client_post("/json/set_avatar")
self.assert_json_error(result, "You must upload exactly one avatar.") self.assert_json_error(result, "You must upload exactly one avatar.")
correct_files = [ correct_files = [
@@ -350,7 +350,7 @@ class AvatarTest(AuthedTestCase):
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
fp = open(os.path.join(TEST_AVATAR_DIR, fname), 'rb') fp = open(os.path.join(TEST_AVATAR_DIR, fname), 'rb')
result = self.client.post("/json/set_avatar", {'file': fp}) result = self.client_post("/json/set_avatar", {'file': fp})
self.assert_json_success(result) self.assert_json_success(result)
json = ujson.loads(result.content) json = ujson.loads(result.content)
self.assertIn("avatar_url", json) self.assertIn("avatar_url", json)
@@ -374,7 +374,7 @@ class AvatarTest(AuthedTestCase):
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
fp = open(os.path.join(TEST_AVATAR_DIR, fname), 'rb') fp = open(os.path.join(TEST_AVATAR_DIR, fname), 'rb')
result = self.client.post("/json/set_avatar", {'file': fp}) result = self.client_post("/json/set_avatar", {'file': fp})
self.assert_json_error(result, "Could not decode avatar image; did you upload an image file?") self.assert_json_error(result, "Could not decode avatar image; did you upload an image file?")
def tearDown(self): def tearDown(self):
@@ -400,7 +400,7 @@ class LocalStorageTest(AuthedTestCase):
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
fp = StringIO("zulip!") fp = StringIO("zulip!")
fp.name = "zulip.txt" fp.name = "zulip.txt"
result = self.client.post("/json/upload_file", {'file': fp}) result = self.client_post("/json/upload_file", {'file': fp})
json = ujson.loads(result.content) json = ujson.loads(result.content)
uri = json["uri"] uri = json["uri"]
@@ -470,7 +470,7 @@ class S3Test(AuthedTestCase):
fp = StringIO("zulip!") fp = StringIO("zulip!")
fp.name = "zulip.txt" fp.name = "zulip.txt"
result = self.client.post("/json/upload_file", {'file': fp}) result = self.client_post("/json/upload_file", {'file': fp})
self.assert_json_success(result) self.assert_json_success(result)
json = ujson.loads(result.content) json = ujson.loads(result.content)
self.assertIn("uri", json) self.assertIn("uri", json)

View File

@@ -465,7 +465,7 @@ class UserChangesTest(AuthedTestCase):
self.login(email) self.login(email)
user = get_user_profile_by_email(email) user = get_user_profile_by_email(email)
old_api_key = user.api_key old_api_key = user.api_key
result = self.client.post('/json/users/me/api_key/regenerate') result = self.client_post('/json/users/me/api_key/regenerate')
self.assert_json_success(result) self.assert_json_success(result)
new_api_key = ujson.loads(result.content)['api_key'] new_api_key = ujson.loads(result.content)['api_key']
self.assertNotEqual(old_api_key, new_api_key) self.assertNotEqual(old_api_key, new_api_key)
@@ -495,7 +495,7 @@ class ActivateTest(AuthedTestCase):
user = get_user_profile_by_email('hamlet@zulip.com') user = get_user_profile_by_email('hamlet@zulip.com')
self.assertFalse(user.is_active) self.assertFalse(user.is_active)
result = self.client.post('/json/users/hamlet@zulip.com/reactivate') result = self.client_post('/json/users/hamlet@zulip.com/reactivate')
self.assert_json_success(result) self.assert_json_success(result)
user = get_user_profile_by_email('hamlet@zulip.com') user = get_user_profile_by_email('hamlet@zulip.com')
self.assertTrue(user.is_active) self.assertTrue(user.is_active)
@@ -515,7 +515,7 @@ class ActivateTest(AuthedTestCase):
self.assert_json_error(result, 'No such user') self.assert_json_error(result, 'No such user')
# Can not reactivate a nonexistent user. # Can not reactivate a nonexistent user.
result = self.client.post('/json/users/nonexistent@zulip.com/reactivate') result = self.client_post('/json/users/nonexistent@zulip.com/reactivate')
self.assert_json_error(result, 'No such user') self.assert_json_error(result, 'No such user')
def test_api_with_insufficient_permissions(self): def test_api_with_insufficient_permissions(self):
@@ -529,7 +529,7 @@ class ActivateTest(AuthedTestCase):
self.assert_json_error(result, 'Insufficient permission') self.assert_json_error(result, 'Insufficient permission')
# Can not reactivate a user # Can not reactivate a user
result = self.client.post('/json/users/hamlet@zulip.com/reactivate') result = self.client_post('/json/users/hamlet@zulip.com/reactivate')
self.assert_json_error(result, 'Insufficient permission') self.assert_json_error(result, 'Insufficient permission')
class BotTest(AuthedTestCase): class BotTest(AuthedTestCase):
@@ -547,7 +547,7 @@ class BotTest(AuthedTestCase):
'short_name': 'hambot', 'short_name': 'hambot',
} }
bot_info.update(extras) bot_info.update(extras)
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
return ujson.loads(result.content) return ujson.loads(result.content)
@@ -564,7 +564,7 @@ class BotTest(AuthedTestCase):
full_name='', full_name='',
short_name='', short_name='',
) )
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_error(result, 'Bad name or username') self.assert_json_error(result, 'Bad name or username')
self.assert_num_bots_equal(0) self.assert_num_bots_equal(0)
@@ -613,7 +613,7 @@ class BotTest(AuthedTestCase):
full_name='Duplicate', full_name='Duplicate',
short_name='hambot', short_name='hambot',
) )
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_error(result, 'Username already in use') self.assert_json_error(result, 'Username already in use')
def test_add_bot_with_user_avatar(self): def test_add_bot_with_user_avatar(self):
@@ -640,7 +640,7 @@ class BotTest(AuthedTestCase):
file1=fp1, file1=fp1,
file2=fp2, file2=fp2,
) )
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_error(result, 'You may only upload one file at a time') self.assert_json_error(result, 'You may only upload one file at a time')
self.assert_num_bots_equal(0) self.assert_num_bots_equal(0)
@@ -716,7 +716,7 @@ class BotTest(AuthedTestCase):
'short_name': 'hambot', 'short_name': 'hambot',
'default_sending_stream': 'Denmark', 'default_sending_stream': 'Denmark',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_error(result, 'Insufficient permission') self.assert_json_error(result, 'Insufficient permission')
def test_add_bot_with_default_events_register_stream(self): def test_add_bot_with_default_events_register_stream(self):
@@ -781,7 +781,7 @@ class BotTest(AuthedTestCase):
'short_name': 'hambot', 'short_name': 'hambot',
'default_events_register_stream': 'Denmark', 'default_events_register_stream': 'Denmark',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_error(result, 'Insufficient permission') self.assert_json_error(result, 'Insufficient permission')
def test_add_bot_with_default_all_public_streams(self): def test_add_bot_with_default_all_public_streams(self):
@@ -855,7 +855,7 @@ class BotTest(AuthedTestCase):
# Have Othello try to mess with Hamlet's bots. # Have Othello try to mess with Hamlet's bots.
self.login("othello@zulip.com") self.login("othello@zulip.com")
result = self.client.post("/json/bots/hambot-bot@zulip.com/api_key/regenerate") result = self.client_post("/json/bots/hambot-bot@zulip.com/api_key/regenerate")
self.assert_json_error(result, 'Insufficient permission') self.assert_json_error(result, 'Insufficient permission')
bot_info = { bot_info = {
@@ -876,7 +876,7 @@ class BotTest(AuthedTestCase):
self.create_bot() self.create_bot()
bot = self.get_bot() bot = self.get_bot()
old_api_key = bot['api_key'] old_api_key = bot['api_key']
result = self.client.post('/json/bots/hambot-bot@zulip.com/api_key/regenerate') result = self.client_post('/json/bots/hambot-bot@zulip.com/api_key/regenerate')
self.assert_json_success(result) self.assert_json_success(result)
new_api_key = ujson.loads(result.content)['api_key'] new_api_key = ujson.loads(result.content)['api_key']
self.assertNotEqual(old_api_key, new_api_key) self.assertNotEqual(old_api_key, new_api_key)
@@ -886,7 +886,7 @@ class BotTest(AuthedTestCase):
def test_update_api_key_for_invalid_user(self): def test_update_api_key_for_invalid_user(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post('/json/bots/nonexistentuser@zulip.com/api_key/regenerate') result = self.client_post('/json/bots/nonexistentuser@zulip.com/api_key/regenerate')
self.assert_json_error(result, 'No such user') self.assert_json_error(result, 'No such user')
def test_patch_bot_full_name(self): def test_patch_bot_full_name(self):
@@ -896,7 +896,7 @@ class BotTest(AuthedTestCase):
'full_name': 'The Bot of Hamlet', 'full_name': 'The Bot of Hamlet',
'short_name': 'hambot', 'short_name': 'hambot',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
bot_info = { bot_info = {
'full_name': 'Fred', 'full_name': 'Fred',
@@ -917,7 +917,7 @@ class BotTest(AuthedTestCase):
'full_name': 'The Bot of Hamlet', 'full_name': 'The Bot of Hamlet',
'short_name': 'hambot', 'short_name': 'hambot',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
profile = get_user_profile_by_email('hambot-bot@zulip.com') profile = get_user_profile_by_email('hambot-bot@zulip.com')
@@ -949,7 +949,7 @@ class BotTest(AuthedTestCase):
'full_name': 'The Bot of Hamlet', 'full_name': 'The Bot of Hamlet',
'short_name': 'hambot', 'short_name': 'hambot',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
bot_info = { bot_info = {
'default_sending_stream': 'Denmark', 'default_sending_stream': 'Denmark',
@@ -970,7 +970,7 @@ class BotTest(AuthedTestCase):
'full_name': 'The Bot of Hamlet', 'full_name': 'The Bot of Hamlet',
'short_name': 'hambot', 'short_name': 'hambot',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
bot_info = { bot_info = {
'default_sending_stream': 'Rome', 'default_sending_stream': 'Rome',
@@ -991,7 +991,7 @@ class BotTest(AuthedTestCase):
'full_name': 'The Bot of Hamlet', 'full_name': 'The Bot of Hamlet',
'short_name': 'hambot', 'short_name': 'hambot',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
bot_info = { bot_info = {
'default_sending_stream': '', 'default_sending_stream': '',
@@ -1017,7 +1017,7 @@ class BotTest(AuthedTestCase):
'full_name': 'The Bot of Hamlet', 'full_name': 'The Bot of Hamlet',
'short_name': 'hambot', 'short_name': 'hambot',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
bot_info = { bot_info = {
@@ -1044,7 +1044,7 @@ class BotTest(AuthedTestCase):
'full_name': 'The Bot of Hamlet', 'full_name': 'The Bot of Hamlet',
'short_name': 'hambot', 'short_name': 'hambot',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
bot_info = { bot_info = {
@@ -1060,7 +1060,7 @@ class BotTest(AuthedTestCase):
'full_name': 'The Bot of Hamlet', 'full_name': 'The Bot of Hamlet',
'short_name': 'hambot', 'short_name': 'hambot',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
bot_info = { bot_info = {
'default_sending_stream': 'missing', 'default_sending_stream': 'missing',
@@ -1075,7 +1075,7 @@ class BotTest(AuthedTestCase):
'full_name': 'The Bot of Hamlet', 'full_name': 'The Bot of Hamlet',
'short_name': 'hambot', 'short_name': 'hambot',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
bot_info = { bot_info = {
'default_events_register_stream': 'Denmark', 'default_events_register_stream': 'Denmark',
@@ -1101,7 +1101,7 @@ class BotTest(AuthedTestCase):
'full_name': 'The Bot of Hamlet', 'full_name': 'The Bot of Hamlet',
'short_name': 'hambot', 'short_name': 'hambot',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
bot_info = { bot_info = {
'default_events_register_stream': 'Denmark', 'default_events_register_stream': 'Denmark',
@@ -1127,7 +1127,7 @@ class BotTest(AuthedTestCase):
'full_name': 'The Bot of Hamlet', 'full_name': 'The Bot of Hamlet',
'short_name': 'hambot', 'short_name': 'hambot',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
bot_info = { bot_info = {
'default_events_register_stream': 'Denmark', 'default_events_register_stream': 'Denmark',
@@ -1142,7 +1142,7 @@ class BotTest(AuthedTestCase):
'full_name': 'The Bot of Hamlet', 'full_name': 'The Bot of Hamlet',
'short_name': 'hambot', 'short_name': 'hambot',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
bot_info = { bot_info = {
'default_events_register_stream': '', 'default_events_register_stream': '',
@@ -1163,7 +1163,7 @@ class BotTest(AuthedTestCase):
'full_name': 'The Bot of Hamlet', 'full_name': 'The Bot of Hamlet',
'short_name': 'hambot', 'short_name': 'hambot',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
bot_info = { bot_info = {
'default_events_register_stream': 'missing', 'default_events_register_stream': 'missing',
@@ -1178,7 +1178,7 @@ class BotTest(AuthedTestCase):
'full_name': 'The Bot of Hamlet', 'full_name': 'The Bot of Hamlet',
'short_name': 'hambot', 'short_name': 'hambot',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
bot_info = { bot_info = {
'default_all_public_streams': ujson.dumps(True), 'default_all_public_streams': ujson.dumps(True),
@@ -1199,7 +1199,7 @@ class BotTest(AuthedTestCase):
'full_name': 'The Bot of Hamlet', 'full_name': 'The Bot of Hamlet',
'short_name': 'hambot', 'short_name': 'hambot',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
bot_info = { bot_info = {
'default_all_public_streams': ujson.dumps(False), 'default_all_public_streams': ujson.dumps(False),
@@ -1220,13 +1220,13 @@ class BotTest(AuthedTestCase):
'full_name': 'The Bot of Hamlet', 'full_name': 'The Bot of Hamlet',
'short_name': 'hambot', 'short_name': 'hambot',
} }
result = self.client.post("/json/bots", bot_info) result = self.client_post("/json/bots", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
bot_info = { bot_info = {
'full_name': 'Fred', 'full_name': 'Fred',
'method': 'PATCH' 'method': 'PATCH'
} }
result = self.client.post("/json/bots/hambot-bot@zulip.com", bot_info) result = self.client_post("/json/bots/hambot-bot@zulip.com", bot_info)
self.assert_json_success(result) self.assert_json_success(result)
full_name = ujson.loads(result.content)['full_name'] full_name = ujson.loads(result.content)['full_name']
@@ -1257,14 +1257,14 @@ class ChangeSettingsTest(AuthedTestCase):
# type: (str, str) -> None # type: (str, str) -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = get_user_profile_by_email("hamlet@zulip.com")
json_result = self.client.post(pattern, json_result = self.client_post(pattern,
{param: ujson.dumps(True)}) {param: ujson.dumps(True)})
self.assert_json_success(json_result) self.assert_json_success(json_result)
# refetch user_profile object to correctly handle caching # refetch user_profile object to correctly handle caching
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = get_user_profile_by_email("hamlet@zulip.com")
self.assertEqual(getattr(user_profile, param), True) self.assertEqual(getattr(user_profile, param), True)
json_result = self.client.post(pattern, json_result = self.client_post(pattern,
{param: ujson.dumps(False)}) {param: ujson.dumps(False)})
self.assert_json_success(json_result) self.assert_json_success(json_result)
# refetch user_profile object to correctly handle caching # refetch user_profile object to correctly handle caching
@@ -1278,7 +1278,7 @@ class ChangeSettingsTest(AuthedTestCase):
settings correctly and returns correct values. settings correctly and returns correct values.
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
json_result = self.client.post("/json/settings/change", json_result = self.client_post("/json/settings/change",
dict( dict(
full_name='Foo Bar', full_name='Foo Bar',
old_password=initial_password('hamlet@zulip.com'), old_password=initial_password('hamlet@zulip.com'),
@@ -1291,7 +1291,7 @@ class ChangeSettingsTest(AuthedTestCase):
self.check_well_formed_change_settings_response(result) self.check_well_formed_change_settings_response(result)
self.assertEqual(get_user_profile_by_email("hamlet@zulip.com"). self.assertEqual(get_user_profile_by_email("hamlet@zulip.com").
full_name, "Foo Bar") full_name, "Foo Bar")
self.client.post('/accounts/logout/') self.client_post('/accounts/logout/')
self.login("hamlet@zulip.com", "foobar1") self.login("hamlet@zulip.com", "foobar1")
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = get_user_profile_by_email('hamlet@zulip.com')
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id) self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
@@ -1330,7 +1330,7 @@ class ChangeSettingsTest(AuthedTestCase):
new_password and confirm_password must match new_password and confirm_password must match
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/settings/change", result = self.client_post("/json/settings/change",
dict( dict(
new_password="mismatched_password", new_password="mismatched_password",
confirm_password="not_the_same", confirm_password="not_the_same",
@@ -1345,7 +1345,7 @@ class ChangeSettingsTest(AuthedTestCase):
new_password and confirm_password must match new_password and confirm_password must match
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/settings/change", result = self.client_post("/json/settings/change",
dict( dict(
old_password='bad_password', old_password='bad_password',
new_password="ignored", new_password="ignored",
@@ -1362,7 +1362,7 @@ class ChangeSettingsTest(AuthedTestCase):
probably use a patch interface for these changes.) probably use a patch interface for these changes.)
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/settings/change", result = self.client_post("/json/settings/change",
dict( dict(
old_password='ignored', old_password='ignored',
) )
@@ -1454,7 +1454,7 @@ class UserPresenceTests(AuthedTestCase):
def test_get_empty(self): def test_get_empty(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/get_active_statuses") result = self.client_post("/json/get_active_statuses")
self.assert_json_success(result) self.assert_json_success(result)
json = ujson.loads(result.content) json = ujson.loads(result.content)
@@ -1477,16 +1477,16 @@ class UserPresenceTests(AuthedTestCase):
self.assertEqual(list(json['presences'].keys()), ['hamlet@zulip.com']) self.assertEqual(list(json['presences'].keys()), ['hamlet@zulip.com'])
return json['presences'][email][client]['timestamp'] return json['presences'][email][client]['timestamp']
result = self.client.post("/json/users/me/presence", {'status': 'idle'}) result = self.client_post("/json/users/me/presence", {'status': 'idle'})
test_result(result) test_result(result)
result = self.client.post("/json/get_active_statuses", {}) result = self.client_post("/json/get_active_statuses", {})
timestamp = test_result(result) timestamp = test_result(result)
email = "othello@zulip.com" email = "othello@zulip.com"
self.login(email) self.login(email)
self.client.post("/json/users/me/presence", {'status': 'idle'}) self.client_post("/json/users/me/presence", {'status': 'idle'})
result = self.client.post("/json/get_active_statuses", {}) result = self.client_post("/json/get_active_statuses", {})
self.assert_json_success(result) self.assert_json_success(result)
json = ujson.loads(result.content) json = ujson.loads(result.content)
self.assertEqual(json['presences'][email][client]['status'], 'idle') self.assertEqual(json['presences'][email][client]['status'], 'idle')
@@ -1500,8 +1500,8 @@ class UserPresenceTests(AuthedTestCase):
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
client = 'website' client = 'website'
self.client.post("/json/users/me/presence", {'status': 'idle'}) self.client_post("/json/users/me/presence", {'status': 'idle'})
result = self.client.post("/json/get_active_statuses", {}) result = self.client_post("/json/get_active_statuses", {})
self.assert_json_success(result) self.assert_json_success(result)
json = ujson.loads(result.content) json = ujson.loads(result.content)
@@ -1509,15 +1509,15 @@ class UserPresenceTests(AuthedTestCase):
email = "othello@zulip.com" email = "othello@zulip.com"
self.login("othello@zulip.com") self.login("othello@zulip.com")
self.client.post("/json/users/me/presence", {'status': 'idle'}) self.client_post("/json/users/me/presence", {'status': 'idle'})
result = self.client.post("/json/get_active_statuses", {}) result = self.client_post("/json/get_active_statuses", {})
self.assert_json_success(result) self.assert_json_success(result)
json = ujson.loads(result.content) json = ujson.loads(result.content)
self.assertEqual(json['presences'][email][client]['status'], 'idle') self.assertEqual(json['presences'][email][client]['status'], 'idle')
self.assertEqual(json['presences']['hamlet@zulip.com'][client]['status'], 'idle') self.assertEqual(json['presences']['hamlet@zulip.com'][client]['status'], 'idle')
self.client.post("/json/users/me/presence", {'status': 'active'}) self.client_post("/json/users/me/presence", {'status': 'active'})
result = self.client.post("/json/get_active_statuses", {}) result = self.client_post("/json/get_active_statuses", {})
self.assert_json_success(result) self.assert_json_success(result)
json = ujson.loads(result.content) json = ujson.loads(result.content)
self.assertEqual(json['presences'][email][client]['status'], 'active') self.assertEqual(json['presences'][email][client]['status'], 'active')
@@ -1527,7 +1527,7 @@ class UserPresenceTests(AuthedTestCase):
# type: () -> None # type: () -> None
"""Zephyr mirror realms such as MIT never get a list of users""" """Zephyr mirror realms such as MIT never get a list of users"""
self.login("espuser@mit.edu") self.login("espuser@mit.edu")
result = self.client.post("/json/users/me/presence", {'status': 'idle'}) result = self.client_post("/json/users/me/presence", {'status': 'idle'})
self.assert_json_success(result) self.assert_json_success(result)
json = ujson.loads(result.content) json = ujson.loads(result.content)
self.assertEqual(json['presences'], {}) self.assertEqual(json['presences'], {})
@@ -1535,12 +1535,12 @@ class UserPresenceTests(AuthedTestCase):
def test_same_realm(self): def test_same_realm(self):
# type: () -> None # type: () -> None
self.login("espuser@mit.edu") self.login("espuser@mit.edu")
self.client.post("/json/users/me/presence", {'status': 'idle'}) self.client_post("/json/users/me/presence", {'status': 'idle'})
result = self.client.post("/accounts/logout/") result = self.client_post("/accounts/logout/")
# Ensure we don't see hamlet@zulip.com information leakage # Ensure we don't see hamlet@zulip.com information leakage
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client.post("/json/users/me/presence", {'status': 'idle'}) result = self.client_post("/json/users/me/presence", {'status': 'idle'})
self.assert_json_success(result) self.assert_json_success(result)
json = ujson.loads(result.content) json = ujson.loads(result.content)
self.assertEqual(json['presences']["hamlet@zulip.com"]["website"]['status'], 'idle') self.assertEqual(json['presences']["hamlet@zulip.com"]["website"]['status'], 'idle')
@@ -1559,7 +1559,7 @@ class AlertWordTests(AuthedTestCase):
params = { params = {
'alert_words': ujson.dumps(['milk', 'cookies']) 'alert_words': ujson.dumps(['milk', 'cookies'])
} }
result = self.client.post('/json/users/me/alert_words', params) result = self.client_post('/json/users/me/alert_words', params)
self.assert_json_success(result) self.assert_json_success(result)
user = get_user_profile_by_email(email) user = get_user_profile_by_email(email)
words = user_alert_words(user) words = user_alert_words(user)
@@ -1680,7 +1680,7 @@ class AlertWordTests(AuthedTestCase):
result = self.client_put('/json/users/me/alert_words', {'alert_words': ujson.dumps(['one', 'two', 'three'])}) result = self.client_put('/json/users/me/alert_words', {'alert_words': ujson.dumps(['one', 'two', 'three'])})
self.assert_json_success(result) self.assert_json_success(result)
result = self.client.post('/json/users/me/alert_words', {'alert_words': ujson.dumps(['a', 'b', 'c'])}) result = self.client_post('/json/users/me/alert_words', {'alert_words': ujson.dumps(['a', 'b', 'c'])})
self.assert_json_success(result) self.assert_json_success(result)
result = self.client.get('/json/users/me/alert_words') result = self.client.get('/json/users/me/alert_words')
@@ -1862,7 +1862,7 @@ class MutedTopicsTests(AuthedTestCase):
url = '/json/set_muted_topics' url = '/json/set_muted_topics'
data = {'muted_topics': '[["stream", "topic"]]'} data = {'muted_topics': '[["stream", "topic"]]'}
result = self.client.post(url, data) result = self.client_post(url, data)
self.assert_json_success(result) self.assert_json_success(result)
user = get_user_profile_by_email(email) user = get_user_profile_by_email(email)
@@ -1870,7 +1870,7 @@ class MutedTopicsTests(AuthedTestCase):
url = '/json/set_muted_topics' url = '/json/set_muted_topics'
data = {'muted_topics': '[["stream2", "topic2"]]'} data = {'muted_topics': '[["stream2", "topic2"]]'}
result = self.client.post(url, data) result = self.client_post(url, data)
self.assert_json_success(result) self.assert_json_success(result)
user = get_user_profile_by_email(email) user = get_user_profile_by_email(email)