mirror of
https://github.com/zulip/zulip.git
synced 2025-11-19 14:08:23 +00:00
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:
@@ -230,11 +230,14 @@ class AuthedTestCase(TestCase):
|
||||
encoded = urllib.parse.urlencode(info)
|
||||
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):
|
||||
# type: (text_type, Optional[text_type]) -> HttpResponse
|
||||
if password is None:
|
||||
password = initial_password(email)
|
||||
return self.client.post('/accounts/login/',
|
||||
return self.client_post('/accounts/login/',
|
||||
{'username': email, 'password': password})
|
||||
|
||||
def login(self, email, password=None, fails=False):
|
||||
@@ -247,7 +250,7 @@ class AuthedTestCase(TestCase):
|
||||
|
||||
def register(self, username, password, domain="zulip.com"):
|
||||
# type: (text_type, text_type, text_type) -> HttpResponse
|
||||
self.client.post('/accounts/home/',
|
||||
self.client_post('/accounts/home/',
|
||||
{'email': username + "@" + 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
|
||||
registered after this call.
|
||||
"""
|
||||
return self.client.post('/accounts/register/',
|
||||
return self.client_post('/accounts/register/',
|
||||
{'full_name': username, 'password': password,
|
||||
'key': find_key_by_email(username + '@' + domain),
|
||||
'terms': True})
|
||||
@@ -397,7 +400,7 @@ class AuthedTestCase(TestCase):
|
||||
post_data = {'subscriptions': ujson.dumps([{"name": stream} for stream in streams]),
|
||||
'invite_only': ujson.dumps(invite_only)}
|
||||
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
|
||||
|
||||
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:
|
||||
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)
|
||||
|
||||
# Check the correct message was sent
|
||||
|
||||
@@ -160,14 +160,14 @@ class FetchAPIKeyTest(AuthedTestCase):
|
||||
|
||||
def test_success(self):
|
||||
# type: () -> None
|
||||
result = self.client.post("/api/v1/fetch_api_key",
|
||||
result = self.client_post("/api/v1/fetch_api_key",
|
||||
dict(username=self.email,
|
||||
password=initial_password(self.email)))
|
||||
self.assert_json_success(result)
|
||||
|
||||
def test_wrong_password(self):
|
||||
# type: () -> None
|
||||
result = self.client.post("/api/v1/fetch_api_key",
|
||||
result = self.client_post("/api/v1/fetch_api_key",
|
||||
dict(username=self.email,
|
||||
password="wrong"))
|
||||
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):
|
||||
# type: () -> None
|
||||
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,
|
||||
password=initial_password(self.email)))
|
||||
self.assert_json_error_contains(result, "Password auth is disabled", 403)
|
||||
@@ -183,7 +183,7 @@ class FetchAPIKeyTest(AuthedTestCase):
|
||||
def test_inactive_user(self):
|
||||
# type: () -> None
|
||||
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,
|
||||
password=initial_password(self.email)))
|
||||
self.assert_json_error_contains(result, "Your account has been disabled", 403)
|
||||
@@ -191,7 +191,7 @@ class FetchAPIKeyTest(AuthedTestCase):
|
||||
def test_deactivated_realm(self):
|
||||
# type: () -> None
|
||||
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,
|
||||
password=initial_password(self.email)))
|
||||
self.assert_json_error_contains(result, "Your realm has been deactivated", 403)
|
||||
@@ -204,7 +204,7 @@ class DevFetchAPIKeyTest(AuthedTestCase):
|
||||
|
||||
def test_success(self):
|
||||
# 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))
|
||||
self.assert_json_success(result)
|
||||
data = ujson.loads(result.content)
|
||||
@@ -214,21 +214,21 @@ class DevFetchAPIKeyTest(AuthedTestCase):
|
||||
def test_inactive_user(self):
|
||||
# type: () -> None
|
||||
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))
|
||||
self.assert_json_error_contains(result, "Your account has been disabled", 403)
|
||||
|
||||
def test_deactivated_realm(self):
|
||||
# type: () -> None
|
||||
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))
|
||||
self.assert_json_error_contains(result, "Your realm has been deactivated", 403)
|
||||
|
||||
def test_dev_auth_disabled(self):
|
||||
# type: () -> None
|
||||
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))
|
||||
self.assert_json_error_contains(result, "Dev environment not enabled.", 400)
|
||||
|
||||
|
||||
@@ -412,7 +412,7 @@ class DeactivatedRealmTest(AuthedTestCase):
|
||||
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",
|
||||
"client": "test suite",
|
||||
"to": "othello@zulip.com"})
|
||||
@@ -425,13 +425,13 @@ class DeactivatedRealmTest(AuthedTestCase):
|
||||
realm.deactivated = True
|
||||
realm.save()
|
||||
|
||||
result = self.client.post("/json/messages", {"type": "private",
|
||||
result = self.client_post("/json/messages", {"type": "private",
|
||||
"content": "Test message",
|
||||
"client": "test suite",
|
||||
"to": "othello@zulip.com"})
|
||||
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",
|
||||
"client": "test suite",
|
||||
"to": "othello@zulip.com"},
|
||||
@@ -452,7 +452,7 @@ class DeactivatedRealmTest(AuthedTestCase):
|
||||
self.login(email)
|
||||
realm.deactivated = True
|
||||
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)
|
||||
|
||||
def test_login_deactivated_realm(self):
|
||||
@@ -474,7 +474,7 @@ class DeactivatedRealmTest(AuthedTestCase):
|
||||
api_key = self.get_api_key(email)
|
||||
url = "/api/v1/external/jira?api_key=%s&stream=jira_custom" % (api_key,)
|
||||
data = self.fixture_data('jira', "created")
|
||||
result = self.client.post(url, data,
|
||||
result = self.client_post(url, data,
|
||||
content_type="application/json")
|
||||
self.assert_json_error_contains(result, "has been deactivated", status_code=400)
|
||||
|
||||
@@ -518,14 +518,14 @@ class FetchAPIKeyTest(AuthedTestCase):
|
||||
email = "cordelia@zulip.com"
|
||||
|
||||
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)
|
||||
|
||||
def test_fetch_api_key_wrong_password(self):
|
||||
email = "cordelia@zulip.com"
|
||||
|
||||
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")
|
||||
|
||||
class InactiveUserTest(AuthedTestCase):
|
||||
@@ -539,7 +539,7 @@ class InactiveUserTest(AuthedTestCase):
|
||||
self.login(email)
|
||||
do_deactivate_user(user_profile)
|
||||
|
||||
result = self.client.post("/json/messages", {"type": "private",
|
||||
result = self.client_post("/json/messages", {"type": "private",
|
||||
"content": "Test message",
|
||||
"client": "test suite",
|
||||
"to": "othello@zulip.com"})
|
||||
@@ -551,13 +551,13 @@ class InactiveUserTest(AuthedTestCase):
|
||||
user_profile.is_active = False
|
||||
user_profile.save()
|
||||
|
||||
result = self.client.post("/json/messages", {"type": "private",
|
||||
result = self.client_post("/json/messages", {"type": "private",
|
||||
"content": "Test message",
|
||||
"client": "test suite",
|
||||
"to": "othello@zulip.com"})
|
||||
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",
|
||||
"client": "test suite",
|
||||
"to": "othello@zulip.com"},
|
||||
@@ -577,7 +577,7 @@ class InactiveUserTest(AuthedTestCase):
|
||||
self.login(email)
|
||||
user_profile.is_active = False
|
||||
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)
|
||||
|
||||
def test_login_deactivated_user(self):
|
||||
@@ -604,7 +604,7 @@ class InactiveUserTest(AuthedTestCase):
|
||||
api_key = self.get_api_key(email)
|
||||
url = "/api/v1/external/jira?api_key=%s&stream=jira_custom" % (api_key,)
|
||||
data = self.fixture_data('jira', "created")
|
||||
result = self.client.post(url, data,
|
||||
result = self.client_post(url, data,
|
||||
content_type="application/json")
|
||||
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):
|
||||
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):
|
||||
if password:
|
||||
|
||||
@@ -109,7 +109,7 @@ class TestMissedPersonalMessageEmailMessages(AuthedTestCase):
|
||||
# have Hamlet send Othello a PM. Othello will reply via email
|
||||
# Hamlet will receive the message.
|
||||
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",
|
||||
"client": "test suite",
|
||||
"to": "othello@zulip.com"})
|
||||
@@ -148,7 +148,7 @@ class TestMissedHuddleMessageEmailMessages(AuthedTestCase):
|
||||
# have Othello send Iago and Cordelia a PM. Cordelia will reply via email
|
||||
# Iago and Othello will receive the message.
|
||||
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",
|
||||
"client": "test suite",
|
||||
"to": ujson.dumps(["cordelia@zulip.com",
|
||||
@@ -196,7 +196,7 @@ class TestDigestEmailMessages(AuthedTestCase):
|
||||
# have Hamlet send Othello a PM. Othello will reply via email
|
||||
# Hamlet will receive the message.
|
||||
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",
|
||||
"client": "test suite",
|
||||
"to": "othello@zulip.com"})
|
||||
|
||||
@@ -68,7 +68,7 @@ class RateLimitTests(AuthedTestCase):
|
||||
|
||||
def send_api_message(self, email, api_key, content):
|
||||
# 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",
|
||||
"client": "test suite",
|
||||
"content": content,
|
||||
@@ -133,7 +133,7 @@ class APNSTokenTests(AuthedTestCase):
|
||||
email = "cordelia@zulip.com"
|
||||
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)
|
||||
|
||||
def test_delete_token(self):
|
||||
@@ -142,7 +142,7 @@ class APNSTokenTests(AuthedTestCase):
|
||||
self.login(email)
|
||||
|
||||
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)
|
||||
|
||||
result = self.client_delete('/json/users/me/apns_device_token', {'token': token})
|
||||
@@ -154,7 +154,7 @@ class GCMTokenTests(AuthedTestCase):
|
||||
email = "cordelia@zulip.com"
|
||||
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)
|
||||
|
||||
def test_delete_token(self):
|
||||
@@ -163,7 +163,7 @@ class GCMTokenTests(AuthedTestCase):
|
||||
self.login(email)
|
||||
|
||||
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)
|
||||
|
||||
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"
|
||||
|
||||
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.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)
|
||||
|
||||
@@ -80,7 +80,7 @@ class JiraHookTests(WebhookTestCase):
|
||||
# type: () -> None
|
||||
url = self.build_webhook_url()
|
||||
|
||||
result = self.client.post(url,
|
||||
result = self.client_post(url,
|
||||
self.get_body('unknown'),
|
||||
stream_name="jira",
|
||||
content_type="application/json")
|
||||
@@ -301,7 +301,7 @@ class GithubV1HookTests(WebhookTestCase):
|
||||
|
||||
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)
|
||||
|
||||
after_count = Message.objects.count()
|
||||
@@ -433,7 +433,7 @@ class GithubV2HookTests(WebhookTestCase):
|
||||
|
||||
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)
|
||||
|
||||
after_count = Message.objects.count()
|
||||
@@ -1064,7 +1064,7 @@ class TeamcityHookTests(WebhookTestCase):
|
||||
# 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)"
|
||||
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()
|
||||
|
||||
self.assertEqual(msg.content, expected_message)
|
||||
@@ -1408,7 +1408,7 @@ class CrashlyticsHookTests(WebhookTestCase):
|
||||
last_message_before_request = self.get_last_message()
|
||||
payload = self.get_body('verification')
|
||||
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()
|
||||
self.assert_json_success(result)
|
||||
self.assertEqual(last_message_after_request.pk, last_message_before_request.pk)
|
||||
|
||||
@@ -19,7 +19,7 @@ class TranslationTestCase(AuthedTestCase):
|
||||
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):
|
||||
# type: (str, str, int, **Any) -> HttpResponse
|
||||
response = getattr(self.client, method)(url, **kwargs)
|
||||
@@ -75,7 +75,7 @@ class JsonTranslationTestCase(AuthedTestCase):
|
||||
mock_gettext.return_value = dummy_value
|
||||
|
||||
self.login("hamlet@zulip.com")
|
||||
result = self.client.post("/json/refer_friend",
|
||||
result = self.client_post("/json/refer_friend",
|
||||
HTTP_ACCEPT_LANGUAGE='de')
|
||||
|
||||
self.assert_json_error_contains(result,
|
||||
|
||||
@@ -78,7 +78,7 @@ class TestGenerateRealmCreationLink(AuthedTestCase):
|
||||
|
||||
# Create Realm with generated link
|
||||
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.assertTrue(result["Location"].endswith(
|
||||
"/accounts/send_confirm/%s@%s" % (username, domain)))
|
||||
|
||||
@@ -335,7 +335,7 @@ class StreamMessagesTest(AuthedTestCase):
|
||||
user_profile = get_user_profile_by_email("iago@zulip.com")
|
||||
|
||||
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",
|
||||
"sender": "cordelia@zulip.com",
|
||||
"client": "test suite",
|
||||
@@ -346,7 +346,7 @@ class StreamMessagesTest(AuthedTestCase):
|
||||
"api-key": user_profile.api_key})
|
||||
self.assert_json_success(result)
|
||||
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",
|
||||
"sender": "cordelia@zulip.com",
|
||||
"client": "test suite",
|
||||
@@ -460,7 +460,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
successful.
|
||||
"""
|
||||
self.login("hamlet@zulip.com")
|
||||
result = self.client.post("/json/messages", {"type": "stream",
|
||||
result = self.client_post("/json/messages", {"type": "stream",
|
||||
"to": "Verona",
|
||||
"client": "test suite",
|
||||
"content": "Test message",
|
||||
@@ -473,7 +473,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
"""
|
||||
email = "hamlet@zulip.com"
|
||||
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",
|
||||
"client": "test suite",
|
||||
"content": "Test message",
|
||||
@@ -492,7 +492,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
user_profile = get_user_profile_by_email("hamlet@zulip.com")
|
||||
user_profile.default_sending_stream = get_stream('Verona', user_profile.realm)
|
||||
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",
|
||||
"content": "Test message no to",
|
||||
"subject": "Test subject",
|
||||
@@ -509,7 +509,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
"""
|
||||
self.login("hamlet@zulip.com")
|
||||
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",
|
||||
"client": "test suite",
|
||||
"content": "Test message",
|
||||
@@ -521,7 +521,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
Sending a personal message to a valid username is successful.
|
||||
"""
|
||||
self.login("hamlet@zulip.com")
|
||||
result = self.client.post("/json/messages", {"type": "private",
|
||||
result = self.client_post("/json/messages", {"type": "private",
|
||||
"content": "Test message",
|
||||
"client": "test suite",
|
||||
"to": "othello@zulip.com"})
|
||||
@@ -532,7 +532,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
Sending a personal message to an invalid email returns error JSON.
|
||||
"""
|
||||
self.login("hamlet@zulip.com")
|
||||
result = self.client.post("/json/messages", {"type": "private",
|
||||
result = self.client_post("/json/messages", {"type": "private",
|
||||
"content": "Test message",
|
||||
"client": "test suite",
|
||||
"to": "nonexistent"})
|
||||
@@ -543,7 +543,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
Sending a message of unknown type returns error JSON.
|
||||
"""
|
||||
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",
|
||||
"client": "test suite",
|
||||
"to": "othello@zulip.com"})
|
||||
@@ -554,7 +554,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
Sending a message that is empty or only whitespace should fail
|
||||
"""
|
||||
self.login("hamlet@zulip.com")
|
||||
result = self.client.post("/json/messages", {"type": "private",
|
||||
result = self.client_post("/json/messages", {"type": "private",
|
||||
"content": " ",
|
||||
"client": "test suite",
|
||||
"to": "othello@zulip.com"})
|
||||
@@ -565,7 +565,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
Sending a mirrored huddle message works
|
||||
"""
|
||||
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",
|
||||
"content": "Test message",
|
||||
"client": "zephyr_mirror",
|
||||
@@ -578,7 +578,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
Sending a mirrored personal message works
|
||||
"""
|
||||
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",
|
||||
"content": "Test message",
|
||||
"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']]):
|
||||
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']]):
|
||||
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'],
|
||||
ujson.loads(result2.content)['id'])
|
||||
|
||||
@@ -614,7 +614,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
long_message = "A" * (MAX_MESSAGE_LENGTH + 1)
|
||||
post_data = {"type": "stream", "to": "Verona", "client": "test suite",
|
||||
"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)
|
||||
|
||||
sent_message = self.get_last_message()
|
||||
@@ -630,7 +630,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
long_topic = "A" * (MAX_SUBJECT_LENGTH + 1)
|
||||
post_data = {"type": "stream", "to": "Verona", "client": "test suite",
|
||||
"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)
|
||||
|
||||
sent_message = self.get_last_message()
|
||||
@@ -639,7 +639,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
|
||||
def test_send_forged_message_as_not_superuser(self):
|
||||
self.login("hamlet@zulip.com")
|
||||
result = self.client.post("/json/messages", {"type": "stream",
|
||||
result = self.client_post("/json/messages", {"type": "stream",
|
||||
"to": "Verona",
|
||||
"client": "test suite",
|
||||
"content": "Test message",
|
||||
@@ -649,7 +649,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
|
||||
def test_send_message_as_not_superuser_to_different_domain(self):
|
||||
self.login("hamlet@zulip.com")
|
||||
result = self.client.post("/json/messages", {"type": "stream",
|
||||
result = self.client_post("/json/messages", {"type": "stream",
|
||||
"to": "Verona",
|
||||
"client": "test suite",
|
||||
"content": "Test message",
|
||||
@@ -665,7 +665,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
user.is_api_super_user = True
|
||||
user.save()
|
||||
self.login(email, password)
|
||||
result = self.client.post("/json/messages", {"type": "stream",
|
||||
result = self.client_post("/json/messages", {"type": "stream",
|
||||
"to": "Verona",
|
||||
"client": "test suite",
|
||||
"content": "Test message",
|
||||
@@ -677,7 +677,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
|
||||
def test_send_message_when_sender_is_not_set(self):
|
||||
self.login("starnine@mit.edu")
|
||||
result = self.client.post("/json/messages", {"type": "private",
|
||||
result = self.client_post("/json/messages", {"type": "private",
|
||||
"content": "Test message",
|
||||
"client": "zephyr_mirror",
|
||||
"to": "starnine@mit.edu"})
|
||||
@@ -685,7 +685,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
|
||||
def test_send_message_as_not_superuser_when_type_is_not_private(self):
|
||||
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",
|
||||
"content": "Test message",
|
||||
"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):
|
||||
create_mirrored_message_users_mock.return_value = (False, True)
|
||||
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",
|
||||
"content": "Test message",
|
||||
"client": "zephyr_mirror",
|
||||
@@ -712,7 +712,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
user.realm.domain = 'not_mit.edu'
|
||||
user.realm.save()
|
||||
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",
|
||||
"content": "Test message",
|
||||
"client": "zephyr_mirror",
|
||||
@@ -739,14 +739,14 @@ class EditMessageTest(AuthedTestCase):
|
||||
self.login("hamlet@zulip.com")
|
||||
msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
|
||||
subject="editing", content="before edit")
|
||||
result = self.client.post("/json/update_message", {
|
||||
result = self.client_post("/json/update_message", {
|
||||
'message_id': msg_id,
|
||||
'content': 'after edit'
|
||||
})
|
||||
self.assert_json_success(result)
|
||||
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,
|
||||
'subject': 'edited'
|
||||
})
|
||||
@@ -757,7 +757,7 @@ class EditMessageTest(AuthedTestCase):
|
||||
self.login("hamlet@zulip.com")
|
||||
msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
|
||||
subject="editing", content="before edit")
|
||||
result = self.client.post("/json/update_message", {
|
||||
result = self.client_post("/json/update_message", {
|
||||
'message_id': msg_id,
|
||||
})
|
||||
self.assert_json_error(result, "Nothing to change")
|
||||
@@ -766,7 +766,7 @@ class EditMessageTest(AuthedTestCase):
|
||||
self.login("hamlet@zulip.com")
|
||||
msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
|
||||
subject="editing", content="before edit")
|
||||
result = self.client.post("/json/update_message", {
|
||||
result = self.client_post("/json/update_message", {
|
||||
'message_id': msg_id,
|
||||
'subject': ' '
|
||||
})
|
||||
@@ -776,7 +776,7 @@ class EditMessageTest(AuthedTestCase):
|
||||
self.login("hamlet@zulip.com")
|
||||
msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
|
||||
subject="editing", content="before edit")
|
||||
result = self.client.post("/json/update_message", {
|
||||
result = self.client_post("/json/update_message", {
|
||||
'message_id': msg_id,
|
||||
'content': ' '
|
||||
})
|
||||
@@ -797,7 +797,7 @@ class EditMessageTest(AuthedTestCase):
|
||||
params_dict = { 'message_id': id_, 'subject': new_subject }
|
||||
if not topic_only:
|
||||
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)
|
||||
if topic_only:
|
||||
self.check_message(id_, subject=new_subject)
|
||||
@@ -813,7 +813,7 @@ class EditMessageTest(AuthedTestCase):
|
||||
params_dict = { 'message_id': id_, 'subject': new_subject }
|
||||
if not topic_only:
|
||||
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_)
|
||||
self.assert_json_error(result, error)
|
||||
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,
|
||||
subject="topic1")
|
||||
|
||||
result = self.client.post("/json/update_message", {
|
||||
result = self.client_post("/json/update_message", {
|
||||
'message_id': id1,
|
||||
'subject': 'edited',
|
||||
'propagate_mode': 'change_later'
|
||||
@@ -889,7 +889,7 @@ class EditMessageTest(AuthedTestCase):
|
||||
id6 = self.send_message("iago@zulip.com", "Scotland", Recipient.STREAM,
|
||||
subject="topic3")
|
||||
|
||||
result = self.client.post("/json/update_message", {
|
||||
result = self.client_post("/json/update_message", {
|
||||
'message_id': id2,
|
||||
'subject': 'edited',
|
||||
'propagate_mode': 'change_all'
|
||||
@@ -1076,7 +1076,7 @@ class MirroredMessageUsersTest(TestCase):
|
||||
class StarTests(AuthedTestCase):
|
||||
|
||||
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),
|
||||
"op": "add" if add else "remove",
|
||||
"flag": "starred"})
|
||||
|
||||
@@ -40,7 +40,7 @@ class PublicURLTest(TestCase):
|
||||
def fetch(self, method, urls, expected_status):
|
||||
# type: (str, List[str], int) -> None
|
||||
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,
|
||||
msg="Expected %d, received %d for %s to %s" % (
|
||||
expected_status, response.status_code, method, url))
|
||||
@@ -177,7 +177,7 @@ class LoginTest(AuthedTestCase):
|
||||
def test_logout(self):
|
||||
# type: () -> None
|
||||
self.login("hamlet@zulip.com")
|
||||
self.client.post('/accounts/logout/')
|
||||
self.client_post('/accounts/logout/')
|
||||
self.assertIsNone(get_session_dict_user(self.client.session))
|
||||
|
||||
def test_non_ascii_login(self):
|
||||
@@ -192,11 +192,11 @@ class LoginTest(AuthedTestCase):
|
||||
self.register("test", password)
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
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))
|
||||
|
||||
# Logging in succeeds.
|
||||
self.client.post('/accounts/logout/')
|
||||
self.client_post('/accounts/logout/')
|
||||
self.login(email, password)
|
||||
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.")
|
||||
|
||||
# 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
|
||||
# link.
|
||||
@@ -256,7 +256,7 @@ class LoginTest(AuthedTestCase):
|
||||
params = {
|
||||
'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)
|
||||
|
||||
# We really did email these users, and they have PreregistrationUser
|
||||
@@ -284,7 +284,7 @@ class InviteUserTest(AuthedTestCase):
|
||||
streams should be a list of strings.
|
||||
"""
|
||||
|
||||
return self.client.post("/json/invite_users",
|
||||
return self.client_post("/json/invite_users",
|
||||
{"invitee_emails": users,
|
||||
"stream": streams})
|
||||
|
||||
@@ -303,7 +303,7 @@ class InviteUserTest(AuthedTestCase):
|
||||
params = {
|
||||
'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.check_sent_emails(invitees)
|
||||
|
||||
@@ -370,7 +370,7 @@ earl-test@zulip.com""", ["Denmark"]))
|
||||
"""
|
||||
self.login("hamlet@zulip.com")
|
||||
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.")
|
||||
|
||||
for address in ("noatsign.com", "outsideyourdomain@example.net"):
|
||||
@@ -396,7 +396,7 @@ earl-test@zulip.com""", ["Denmark"]))
|
||||
"""
|
||||
self.login("hamlet@zulip.com")
|
||||
self.assert_json_error(
|
||||
self.client.post("/json/invite_users",
|
||||
self.client_post("/json/invite_users",
|
||||
{"invitee_emails": "hamlet@zulip.com",
|
||||
"stream": ["Denmark"]}),
|
||||
"We weren't able to invite anyone.")
|
||||
@@ -415,7 +415,7 @@ earl-test@zulip.com""", ["Denmark"]))
|
||||
existing = ["hamlet@zulip.com", "othello@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),
|
||||
"stream": ["Denmark"]})
|
||||
self.assert_json_error(result,
|
||||
@@ -574,7 +574,7 @@ class RealmCreationTest(AuthedTestCase):
|
||||
|
||||
with self.settings(OPEN_REALM_CREATION=True):
|
||||
# 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.assertTrue(result["Location"].endswith(
|
||||
"/accounts/send_confirm/%s@%s" % (username, domain)))
|
||||
|
||||
@@ -52,7 +52,7 @@ class StreamAdminTest(AuthedTestCase):
|
||||
params = {
|
||||
'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.')
|
||||
|
||||
do_add_subscription(user_profile, stream)
|
||||
@@ -61,7 +61,7 @@ class StreamAdminTest(AuthedTestCase):
|
||||
params = {
|
||||
'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)
|
||||
stream = Stream.objects.get(name='private_stream', realm=realm)
|
||||
self.assertFalse(stream.invite_only)
|
||||
@@ -78,7 +78,7 @@ class StreamAdminTest(AuthedTestCase):
|
||||
params = {
|
||||
'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)
|
||||
stream = Stream.objects.get(name='public_stream', realm=realm)
|
||||
self.assertTrue(stream.invite_only)
|
||||
@@ -139,7 +139,7 @@ class StreamAdminTest(AuthedTestCase):
|
||||
|
||||
events = [] # type: List[Dict[str, Any]]
|
||||
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)
|
||||
|
||||
event = events[1]['event']
|
||||
@@ -172,7 +172,7 @@ class StreamAdminTest(AuthedTestCase):
|
||||
realm = user_profile.realm
|
||||
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')
|
||||
|
||||
def test_change_stream_description(self):
|
||||
@@ -288,7 +288,7 @@ class StreamAdminTest(AuthedTestCase):
|
||||
self.assertNotIn(deactivated_stream_name, public_streams)
|
||||
|
||||
# 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",
|
||||
{"subscriptions": ujson.dumps([{"name": deactivated_stream_name}])})
|
||||
self.assert_json_error(
|
||||
@@ -355,7 +355,7 @@ class StreamAdminTest(AuthedTestCase):
|
||||
if other_user_subbed:
|
||||
do_add_subscription(other_user_profile, stream, no_log=True)
|
||||
|
||||
result = self.client.post(
|
||||
result = self.client_post(
|
||||
"/json/subscriptions/remove",
|
||||
{"subscriptions": ujson.dumps([stream.name]),
|
||||
"principals": ujson.dumps([other_email])})
|
||||
@@ -465,7 +465,7 @@ class StreamAdminTest(AuthedTestCase):
|
||||
stream_name = u"hümbüǵ"
|
||||
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]),
|
||||
"principals": ujson.dumps(["baduser@zulip.com"])})
|
||||
self.assert_json_error(
|
||||
@@ -548,7 +548,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
sub = old_subs[0]
|
||||
stream_name = sub['name']
|
||||
new_color = "#ffffff" # TODO: ensure that this is different from old_color
|
||||
result = self.client.post(
|
||||
result = self.client_post(
|
||||
"/json/subscriptions/property",
|
||||
{"subscription_data": ujson.dumps([{"property": "color",
|
||||
"stream": stream_name,
|
||||
@@ -581,7 +581,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
"""
|
||||
test_email = "hamlet@zulip.com"
|
||||
self.login(test_email)
|
||||
result = self.client.post(
|
||||
result = self.client_post(
|
||||
"/json/subscriptions/property",
|
||||
{"subscription_data": ujson.dumps([{"property": "color",
|
||||
"value": "#ffffff"}])})
|
||||
@@ -614,7 +614,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
test_email = "hamlet@zulip.com"
|
||||
self.login(test_email)
|
||||
subs = gather_subscriptions(get_user_profile_by_email(test_email))[0]
|
||||
result = self.client.post(
|
||||
result = self.client_post(
|
||||
"/json/subscriptions/property",
|
||||
{"subscription_data": ujson.dumps([{"property": "color",
|
||||
"stream": subs[0]["name"]}])})
|
||||
@@ -636,7 +636,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
sub = old_subs[0]
|
||||
stream_name = sub['name']
|
||||
new_pin_to_top = not sub['pin_to_top']
|
||||
result = self.client.post(
|
||||
result = self.client_post(
|
||||
"/json/subscriptions/property",
|
||||
{"subscription_data": ujson.dumps([{"property": "pin_to_top",
|
||||
"stream": stream_name,
|
||||
@@ -659,7 +659,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
subs = gather_subscriptions(get_user_profile_by_email(test_email))[0]
|
||||
|
||||
property_name = "in_home_view"
|
||||
result = self.client.post(
|
||||
result = self.client_post(
|
||||
"/json/subscriptions/property",
|
||||
{"subscription_data": ujson.dumps([{"property": property_name,
|
||||
"value": "bad",
|
||||
@@ -669,7 +669,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
'%s is not a boolean' % (property_name,))
|
||||
|
||||
property_name = "desktop_notifications"
|
||||
result = self.client.post(
|
||||
result = self.client_post(
|
||||
"/json/subscriptions/property",
|
||||
{"subscription_data": ujson.dumps([{"property": property_name,
|
||||
"value": "bad",
|
||||
@@ -679,7 +679,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
'%s is not a boolean' % (property_name,))
|
||||
|
||||
property_name = "audible_notifications"
|
||||
result = self.client.post(
|
||||
result = self.client_post(
|
||||
"/json/subscriptions/property",
|
||||
{"subscription_data": ujson.dumps([{"property": property_name,
|
||||
"value": "bad",
|
||||
@@ -689,7 +689,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
'%s is not a boolean' % (property_name,))
|
||||
|
||||
property_name = "color"
|
||||
result = self.client.post(
|
||||
result = self.client_post(
|
||||
"/json/subscriptions/property",
|
||||
{"subscription_data": ujson.dumps([{"property": property_name,
|
||||
"value": False,
|
||||
@@ -704,7 +704,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
self.login(test_email)
|
||||
|
||||
stream_name = "invalid_stream"
|
||||
result = self.client.post(
|
||||
result = self.client_post(
|
||||
"/json/subscriptions/property",
|
||||
{"subscription_data": ujson.dumps([{"property": "in_home_view",
|
||||
"stream": stream_name,
|
||||
@@ -720,7 +720,7 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
test_email = "hamlet@zulip.com"
|
||||
self.login(test_email)
|
||||
subs = gather_subscriptions(get_user_profile_by_email(test_email))[0]
|
||||
result = self.client.post(
|
||||
result = self.client_post(
|
||||
"/json/subscriptions/property",
|
||||
{"subscription_data": ujson.dumps([{"property": "bad",
|
||||
"value": "bad",
|
||||
@@ -1379,7 +1379,7 @@ class SubscriptionAPITest(AuthedTestCase):
|
||||
"removed": ["Denmark", "Scotland", "Verona"],
|
||||
"not_subscribed": ["Rome"], "result": "success"}
|
||||
"""
|
||||
result = self.client.post("/json/subscriptions/remove",
|
||||
result = self.client_post("/json/subscriptions/remove",
|
||||
{"subscriptions": ujson.dumps(subscriptions)})
|
||||
self.assert_json_success(result)
|
||||
json = ujson.loads(result.content)
|
||||
@@ -1420,7 +1420,7 @@ class SubscriptionAPITest(AuthedTestCase):
|
||||
random_streams = self.make_random_stream_names(self.streams)
|
||||
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
|
||||
result = self.client.post("/json/subscriptions/remove",
|
||||
result = self.client_post("/json/subscriptions/remove",
|
||||
{"subscriptions": ujson.dumps(streams_to_remove)})
|
||||
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
|
||||
present, pass in None.)
|
||||
"""
|
||||
result = self.client.post("/json/subscriptions/exists",
|
||||
result = self.client_post("/json/subscriptions/exists",
|
||||
{"stream": stream})
|
||||
json = ujson.loads(result.content)
|
||||
self.assertIn("exists", json)
|
||||
@@ -1484,7 +1484,7 @@ class SubscriptionAPITest(AuthedTestCase):
|
||||
"""
|
||||
# currently, the only invalid stream name is the empty string
|
||||
invalid_stream_name = ""
|
||||
result = self.client.post("/json/subscriptions/exists",
|
||||
result = self.client_post("/json/subscriptions/exists",
|
||||
{"stream": invalid_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.
|
||||
"""
|
||||
stream_name = self.streams[0]
|
||||
result = self.client.post("/json/subscriptions/exists",
|
||||
result = self.client_post("/json/subscriptions/exists",
|
||||
{"stream": stream_name, "autosubscribe": True})
|
||||
self.assert_json_success(result)
|
||||
json = ujson.loads(result.content)
|
||||
@@ -1873,7 +1873,7 @@ class GetSubscribersTest(AuthedTestCase):
|
||||
json_get_subscribers also returns the list of subscribers for a 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,))
|
||||
|
||||
def test_json_get_subscribers(self):
|
||||
@@ -1884,7 +1884,7 @@ class GetSubscribersTest(AuthedTestCase):
|
||||
"""
|
||||
stream_name = gather_subscriptions(self.user_profile)[0][0]['name']
|
||||
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)
|
||||
result_dict = ujson.loads(result.content)
|
||||
self.assertIn('subscribers', result_dict)
|
||||
|
||||
@@ -99,7 +99,7 @@ class UnreadCountTests(AuthedTestCase):
|
||||
# type: () -> None
|
||||
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),
|
||||
"op": "add",
|
||||
"flag": "read"})
|
||||
@@ -113,7 +113,7 @@ class UnreadCountTests(AuthedTestCase):
|
||||
found += 1
|
||||
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]]),
|
||||
"op": "remove", "flag": "read"})
|
||||
self.assert_json_success(result)
|
||||
@@ -134,12 +134,12 @@ class UnreadCountTests(AuthedTestCase):
|
||||
self.send_message("hamlet@zulip.com", "cordelia@zulip.com",
|
||||
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",
|
||||
"flag": "read"})
|
||||
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",
|
||||
"flag": "read",
|
||||
"all": ujson.dumps(True)})
|
||||
@@ -159,7 +159,7 @@ class UnreadCountTests(AuthedTestCase):
|
||||
|
||||
events = [] # type: List[Dict[str, Any]]
|
||||
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",
|
||||
"flag": "read",
|
||||
"stream_name": "test_stream"})
|
||||
@@ -194,7 +194,7 @@ class UnreadCountTests(AuthedTestCase):
|
||||
# type: () -> None
|
||||
self.login("hamlet@zulip.com")
|
||||
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",
|
||||
"flag": "read",
|
||||
"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")
|
||||
events = [] # type: List[Dict[str, Any]]
|
||||
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",
|
||||
"flag": "read",
|
||||
"topic_name": "test_topic",
|
||||
@@ -244,7 +244,7 @@ class UnreadCountTests(AuthedTestCase):
|
||||
# type: () -> None
|
||||
self.login("hamlet@zulip.com")
|
||||
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",
|
||||
"flag": "read",
|
||||
"topic_name": invalid_topic_name,
|
||||
|
||||
@@ -52,7 +52,7 @@ class FileUploadTest(AuthedTestCase):
|
||||
|
||||
# Upload file via API
|
||||
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)
|
||||
self.assertIn("uri", json)
|
||||
uri = json["uri"]
|
||||
@@ -60,7 +60,7 @@ class FileUploadTest(AuthedTestCase):
|
||||
self.assertEquals(base, uri[:len(base)])
|
||||
|
||||
# Download file via API
|
||||
self.client.post('/accounts/logout/')
|
||||
self.client_post('/accounts/logout/')
|
||||
response = self.client.get(uri, **auth_headers)
|
||||
data = b"".join(response.streaming_content)
|
||||
self.assertEquals(b"zulip!", data)
|
||||
@@ -82,7 +82,7 @@ class FileUploadTest(AuthedTestCase):
|
||||
fp2 = StringIO("pshaw!")
|
||||
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")
|
||||
|
||||
def test_no_file_upload_failure(self):
|
||||
@@ -92,7 +92,7 @@ class FileUploadTest(AuthedTestCase):
|
||||
"""
|
||||
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")
|
||||
|
||||
# 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.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)
|
||||
json = ujson.loads(result.content)
|
||||
self.assertIn("uri", json)
|
||||
@@ -138,14 +138,14 @@ class FileUploadTest(AuthedTestCase):
|
||||
self.login("hamlet@zulip.com")
|
||||
d1 = StringIO("zulip!")
|
||||
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)
|
||||
uri = json["uri"]
|
||||
d1_path_id = re.sub('/user_uploads/', '', uri)
|
||||
|
||||
d2 = StringIO("zulip!")
|
||||
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)
|
||||
uri = json["uri"]
|
||||
d2_path_id = re.sub('/user_uploads/', '', uri)
|
||||
@@ -177,7 +177,7 @@ class FileUploadTest(AuthedTestCase):
|
||||
self.login("hamlet@zulip.com")
|
||||
d1 = StringIO("zulip!")
|
||||
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)
|
||||
uri = json["uri"]
|
||||
d1_path_id = re.sub('/user_uploads/', '', uri)
|
||||
@@ -199,12 +199,12 @@ class FileUploadTest(AuthedTestCase):
|
||||
f3.name = "file3.txt"
|
||||
|
||||
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)
|
||||
uri = json["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)
|
||||
uri = json["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 + ")")
|
||||
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)
|
||||
uri = json["uri"]
|
||||
f3_path_id = re.sub('/user_uploads/', '', uri)
|
||||
|
||||
new_body = ("[f3.txt](http://localhost:9991/user_uploads/" + f3_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,
|
||||
'content': new_body
|
||||
})
|
||||
@@ -238,7 +238,7 @@ class FileUploadTest(AuthedTestCase):
|
||||
|
||||
# Delete all the attachments from the message
|
||||
new_body = "(deleted)"
|
||||
result = self.client.post("/json/update_message", {
|
||||
result = self.client_post("/json/update_message", {
|
||||
'message_id': msg_id,
|
||||
'content': new_body
|
||||
})
|
||||
@@ -267,7 +267,7 @@ class AvatarTest(AuthedTestCase):
|
||||
fp1 = 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.")
|
||||
|
||||
def test_no_file_upload_failure(self):
|
||||
@@ -277,7 +277,7 @@ class AvatarTest(AuthedTestCase):
|
||||
"""
|
||||
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.")
|
||||
|
||||
correct_files = [
|
||||
@@ -350,7 +350,7 @@ class AvatarTest(AuthedTestCase):
|
||||
self.login("hamlet@zulip.com")
|
||||
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)
|
||||
json = ujson.loads(result.content)
|
||||
self.assertIn("avatar_url", json)
|
||||
@@ -374,7 +374,7 @@ class AvatarTest(AuthedTestCase):
|
||||
self.login("hamlet@zulip.com")
|
||||
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?")
|
||||
|
||||
def tearDown(self):
|
||||
@@ -400,7 +400,7 @@ class LocalStorageTest(AuthedTestCase):
|
||||
self.login("hamlet@zulip.com")
|
||||
fp = StringIO("zulip!")
|
||||
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)
|
||||
uri = json["uri"]
|
||||
@@ -470,7 +470,7 @@ class S3Test(AuthedTestCase):
|
||||
fp = StringIO("zulip!")
|
||||
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)
|
||||
json = ujson.loads(result.content)
|
||||
self.assertIn("uri", json)
|
||||
|
||||
@@ -465,7 +465,7 @@ class UserChangesTest(AuthedTestCase):
|
||||
self.login(email)
|
||||
user = get_user_profile_by_email(email)
|
||||
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)
|
||||
new_api_key = ujson.loads(result.content)['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')
|
||||
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)
|
||||
user = get_user_profile_by_email('hamlet@zulip.com')
|
||||
self.assertTrue(user.is_active)
|
||||
@@ -515,7 +515,7 @@ class ActivateTest(AuthedTestCase):
|
||||
self.assert_json_error(result, 'No such 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')
|
||||
|
||||
def test_api_with_insufficient_permissions(self):
|
||||
@@ -529,7 +529,7 @@ class ActivateTest(AuthedTestCase):
|
||||
self.assert_json_error(result, 'Insufficient permission')
|
||||
|
||||
# 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')
|
||||
|
||||
class BotTest(AuthedTestCase):
|
||||
@@ -547,7 +547,7 @@ class BotTest(AuthedTestCase):
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
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)
|
||||
return ujson.loads(result.content)
|
||||
|
||||
@@ -564,7 +564,7 @@ class BotTest(AuthedTestCase):
|
||||
full_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_num_bots_equal(0)
|
||||
|
||||
@@ -613,7 +613,7 @@ class BotTest(AuthedTestCase):
|
||||
full_name='Duplicate',
|
||||
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')
|
||||
|
||||
def test_add_bot_with_user_avatar(self):
|
||||
@@ -640,7 +640,7 @@ class BotTest(AuthedTestCase):
|
||||
file1=fp1,
|
||||
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_num_bots_equal(0)
|
||||
|
||||
@@ -716,7 +716,7 @@ class BotTest(AuthedTestCase):
|
||||
'short_name': 'hambot',
|
||||
'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')
|
||||
|
||||
def test_add_bot_with_default_events_register_stream(self):
|
||||
@@ -781,7 +781,7 @@ class BotTest(AuthedTestCase):
|
||||
'short_name': 'hambot',
|
||||
'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')
|
||||
|
||||
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.
|
||||
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')
|
||||
|
||||
bot_info = {
|
||||
@@ -876,7 +876,7 @@ class BotTest(AuthedTestCase):
|
||||
self.create_bot()
|
||||
bot = self.get_bot()
|
||||
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)
|
||||
new_api_key = ujson.loads(result.content)['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):
|
||||
# type: () -> None
|
||||
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')
|
||||
|
||||
def test_patch_bot_full_name(self):
|
||||
@@ -896,7 +896,7 @@ class BotTest(AuthedTestCase):
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/bots", bot_info)
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
bot_info = {
|
||||
'full_name': 'Fred',
|
||||
@@ -917,7 +917,7 @@ class BotTest(AuthedTestCase):
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/bots", bot_info)
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.com')
|
||||
@@ -949,7 +949,7 @@ class BotTest(AuthedTestCase):
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/bots", bot_info)
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
bot_info = {
|
||||
'default_sending_stream': 'Denmark',
|
||||
@@ -970,7 +970,7 @@ class BotTest(AuthedTestCase):
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/bots", bot_info)
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
bot_info = {
|
||||
'default_sending_stream': 'Rome',
|
||||
@@ -991,7 +991,7 @@ class BotTest(AuthedTestCase):
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/bots", bot_info)
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
bot_info = {
|
||||
'default_sending_stream': '',
|
||||
@@ -1017,7 +1017,7 @@ class BotTest(AuthedTestCase):
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/bots", bot_info)
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
bot_info = {
|
||||
@@ -1044,7 +1044,7 @@ class BotTest(AuthedTestCase):
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/bots", bot_info)
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
bot_info = {
|
||||
@@ -1060,7 +1060,7 @@ class BotTest(AuthedTestCase):
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/bots", bot_info)
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
bot_info = {
|
||||
'default_sending_stream': 'missing',
|
||||
@@ -1075,7 +1075,7 @@ class BotTest(AuthedTestCase):
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/bots", bot_info)
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
bot_info = {
|
||||
'default_events_register_stream': 'Denmark',
|
||||
@@ -1101,7 +1101,7 @@ class BotTest(AuthedTestCase):
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/bots", bot_info)
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
bot_info = {
|
||||
'default_events_register_stream': 'Denmark',
|
||||
@@ -1127,7 +1127,7 @@ class BotTest(AuthedTestCase):
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/bots", bot_info)
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
bot_info = {
|
||||
'default_events_register_stream': 'Denmark',
|
||||
@@ -1142,7 +1142,7 @@ class BotTest(AuthedTestCase):
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/bots", bot_info)
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
bot_info = {
|
||||
'default_events_register_stream': '',
|
||||
@@ -1163,7 +1163,7 @@ class BotTest(AuthedTestCase):
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/bots", bot_info)
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
bot_info = {
|
||||
'default_events_register_stream': 'missing',
|
||||
@@ -1178,7 +1178,7 @@ class BotTest(AuthedTestCase):
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/bots", bot_info)
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
bot_info = {
|
||||
'default_all_public_streams': ujson.dumps(True),
|
||||
@@ -1199,7 +1199,7 @@ class BotTest(AuthedTestCase):
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/bots", bot_info)
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
bot_info = {
|
||||
'default_all_public_streams': ujson.dumps(False),
|
||||
@@ -1220,13 +1220,13 @@ class BotTest(AuthedTestCase):
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/bots", bot_info)
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
bot_info = {
|
||||
'full_name': 'Fred',
|
||||
'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)
|
||||
|
||||
full_name = ujson.loads(result.content)['full_name']
|
||||
@@ -1257,14 +1257,14 @@ class ChangeSettingsTest(AuthedTestCase):
|
||||
# type: (str, str) -> None
|
||||
self.login("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)})
|
||||
self.assert_json_success(json_result)
|
||||
# refetch user_profile object to correctly handle caching
|
||||
user_profile = get_user_profile_by_email("hamlet@zulip.com")
|
||||
self.assertEqual(getattr(user_profile, param), True)
|
||||
|
||||
json_result = self.client.post(pattern,
|
||||
json_result = self.client_post(pattern,
|
||||
{param: ujson.dumps(False)})
|
||||
self.assert_json_success(json_result)
|
||||
# refetch user_profile object to correctly handle caching
|
||||
@@ -1278,7 +1278,7 @@ class ChangeSettingsTest(AuthedTestCase):
|
||||
settings correctly and returns correct values.
|
||||
"""
|
||||
self.login("hamlet@zulip.com")
|
||||
json_result = self.client.post("/json/settings/change",
|
||||
json_result = self.client_post("/json/settings/change",
|
||||
dict(
|
||||
full_name='Foo Bar',
|
||||
old_password=initial_password('hamlet@zulip.com'),
|
||||
@@ -1291,7 +1291,7 @@ class ChangeSettingsTest(AuthedTestCase):
|
||||
self.check_well_formed_change_settings_response(result)
|
||||
self.assertEqual(get_user_profile_by_email("hamlet@zulip.com").
|
||||
full_name, "Foo Bar")
|
||||
self.client.post('/accounts/logout/')
|
||||
self.client_post('/accounts/logout/')
|
||||
self.login("hamlet@zulip.com", "foobar1")
|
||||
user_profile = get_user_profile_by_email('hamlet@zulip.com')
|
||||
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
|
||||
"""
|
||||
self.login("hamlet@zulip.com")
|
||||
result = self.client.post("/json/settings/change",
|
||||
result = self.client_post("/json/settings/change",
|
||||
dict(
|
||||
new_password="mismatched_password",
|
||||
confirm_password="not_the_same",
|
||||
@@ -1345,7 +1345,7 @@ class ChangeSettingsTest(AuthedTestCase):
|
||||
new_password and confirm_password must match
|
||||
"""
|
||||
self.login("hamlet@zulip.com")
|
||||
result = self.client.post("/json/settings/change",
|
||||
result = self.client_post("/json/settings/change",
|
||||
dict(
|
||||
old_password='bad_password',
|
||||
new_password="ignored",
|
||||
@@ -1362,7 +1362,7 @@ class ChangeSettingsTest(AuthedTestCase):
|
||||
probably use a patch interface for these changes.)
|
||||
"""
|
||||
self.login("hamlet@zulip.com")
|
||||
result = self.client.post("/json/settings/change",
|
||||
result = self.client_post("/json/settings/change",
|
||||
dict(
|
||||
old_password='ignored',
|
||||
)
|
||||
@@ -1454,7 +1454,7 @@ class UserPresenceTests(AuthedTestCase):
|
||||
def test_get_empty(self):
|
||||
# type: () -> None
|
||||
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)
|
||||
json = ujson.loads(result.content)
|
||||
@@ -1477,16 +1477,16 @@ class UserPresenceTests(AuthedTestCase):
|
||||
self.assertEqual(list(json['presences'].keys()), ['hamlet@zulip.com'])
|
||||
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)
|
||||
|
||||
result = self.client.post("/json/get_active_statuses", {})
|
||||
result = self.client_post("/json/get_active_statuses", {})
|
||||
timestamp = test_result(result)
|
||||
|
||||
email = "othello@zulip.com"
|
||||
self.login(email)
|
||||
self.client.post("/json/users/me/presence", {'status': 'idle'})
|
||||
result = self.client.post("/json/get_active_statuses", {})
|
||||
self.client_post("/json/users/me/presence", {'status': 'idle'})
|
||||
result = self.client_post("/json/get_active_statuses", {})
|
||||
self.assert_json_success(result)
|
||||
json = ujson.loads(result.content)
|
||||
self.assertEqual(json['presences'][email][client]['status'], 'idle')
|
||||
@@ -1500,8 +1500,8 @@ class UserPresenceTests(AuthedTestCase):
|
||||
self.login("hamlet@zulip.com")
|
||||
client = 'website'
|
||||
|
||||
self.client.post("/json/users/me/presence", {'status': 'idle'})
|
||||
result = self.client.post("/json/get_active_statuses", {})
|
||||
self.client_post("/json/users/me/presence", {'status': 'idle'})
|
||||
result = self.client_post("/json/get_active_statuses", {})
|
||||
|
||||
self.assert_json_success(result)
|
||||
json = ujson.loads(result.content)
|
||||
@@ -1509,15 +1509,15 @@ class UserPresenceTests(AuthedTestCase):
|
||||
|
||||
email = "othello@zulip.com"
|
||||
self.login("othello@zulip.com")
|
||||
self.client.post("/json/users/me/presence", {'status': 'idle'})
|
||||
result = self.client.post("/json/get_active_statuses", {})
|
||||
self.client_post("/json/users/me/presence", {'status': 'idle'})
|
||||
result = self.client_post("/json/get_active_statuses", {})
|
||||
self.assert_json_success(result)
|
||||
json = ujson.loads(result.content)
|
||||
self.assertEqual(json['presences'][email][client]['status'], 'idle')
|
||||
self.assertEqual(json['presences']['hamlet@zulip.com'][client]['status'], 'idle')
|
||||
|
||||
self.client.post("/json/users/me/presence", {'status': 'active'})
|
||||
result = self.client.post("/json/get_active_statuses", {})
|
||||
self.client_post("/json/users/me/presence", {'status': 'active'})
|
||||
result = self.client_post("/json/get_active_statuses", {})
|
||||
self.assert_json_success(result)
|
||||
json = ujson.loads(result.content)
|
||||
self.assertEqual(json['presences'][email][client]['status'], 'active')
|
||||
@@ -1527,7 +1527,7 @@ class UserPresenceTests(AuthedTestCase):
|
||||
# type: () -> None
|
||||
"""Zephyr mirror realms such as MIT never get a list of users"""
|
||||
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)
|
||||
json = ujson.loads(result.content)
|
||||
self.assertEqual(json['presences'], {})
|
||||
@@ -1535,12 +1535,12 @@ class UserPresenceTests(AuthedTestCase):
|
||||
def test_same_realm(self):
|
||||
# type: () -> None
|
||||
self.login("espuser@mit.edu")
|
||||
self.client.post("/json/users/me/presence", {'status': 'idle'})
|
||||
result = self.client.post("/accounts/logout/")
|
||||
self.client_post("/json/users/me/presence", {'status': 'idle'})
|
||||
result = self.client_post("/accounts/logout/")
|
||||
|
||||
# Ensure we don't see hamlet@zulip.com information leakage
|
||||
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)
|
||||
json = ujson.loads(result.content)
|
||||
self.assertEqual(json['presences']["hamlet@zulip.com"]["website"]['status'], 'idle')
|
||||
@@ -1559,7 +1559,7 @@ class AlertWordTests(AuthedTestCase):
|
||||
params = {
|
||||
'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)
|
||||
user = get_user_profile_by_email(email)
|
||||
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'])})
|
||||
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)
|
||||
|
||||
result = self.client.get('/json/users/me/alert_words')
|
||||
@@ -1862,7 +1862,7 @@ class MutedTopicsTests(AuthedTestCase):
|
||||
|
||||
url = '/json/set_muted_topics'
|
||||
data = {'muted_topics': '[["stream", "topic"]]'}
|
||||
result = self.client.post(url, data)
|
||||
result = self.client_post(url, data)
|
||||
self.assert_json_success(result)
|
||||
|
||||
user = get_user_profile_by_email(email)
|
||||
@@ -1870,7 +1870,7 @@ class MutedTopicsTests(AuthedTestCase):
|
||||
|
||||
url = '/json/set_muted_topics'
|
||||
data = {'muted_topics': '[["stream2", "topic2"]]'}
|
||||
result = self.client.post(url, data)
|
||||
result = self.client_post(url, data)
|
||||
self.assert_json_success(result)
|
||||
|
||||
user = get_user_profile_by_email(email)
|
||||
|
||||
Reference in New Issue
Block a user