diff --git a/analytics/tests/test_stats_views.py b/analytics/tests/test_stats_views.py index 8c8d93a1f5..863b5124e8 100644 --- a/analytics/tests/test_stats_views.py +++ b/analytics/tests/test_stats_views.py @@ -124,8 +124,7 @@ class TestGetChartData(ZulipTestCase): stat = COUNT_STATS["active_users_audit:is_bot:day"] self.insert_data(stat, ["false"], []) result = self.client_get("/json/analytics/chart_data", {"chart_name": "number_of_humans"}) - self.assert_json_success(result) - data = result.json() + data = self.assert_json_success(result) self.assertEqual( data, { @@ -148,8 +147,7 @@ class TestGetChartData(ZulipTestCase): result = self.client_get( "/json/analytics/chart_data", {"chart_name": "messages_sent_over_time"} ) - self.assert_json_success(result) - data = result.json() + data = self.assert_json_success(result) self.assertEqual( data, { @@ -171,8 +169,7 @@ class TestGetChartData(ZulipTestCase): result = self.client_get( "/json/analytics/chart_data", {"chart_name": "messages_sent_by_message_type"} ) - self.assert_json_success(result) - data = result.json() + data = self.assert_json_success(result) self.assertEqual( data, { @@ -215,8 +212,7 @@ class TestGetChartData(ZulipTestCase): result = self.client_get( "/json/analytics/chart_data", {"chart_name": "messages_sent_by_client"} ) - self.assert_json_success(result) - data = result.json() + data = self.assert_json_success(result) self.assertEqual( data, { @@ -240,8 +236,7 @@ class TestGetChartData(ZulipTestCase): result = self.client_get( "/json/analytics/chart_data", {"chart_name": "messages_read_over_time"} ) - self.assert_json_success(result) - data = result.json() + data = self.assert_json_success(result) self.assertEqual( data, { @@ -262,8 +257,7 @@ class TestGetChartData(ZulipTestCase): state=FillState.DONE, ) result = self.client_get("/json/analytics/chart_data", {"chart_name": "number_of_humans"}) - self.assert_json_success(result) - data = result.json() + data = self.assert_json_success(result) self.assertEqual(data["everyone"], {"_1day": [0], "_15day": [0], "all_time": [0]}) self.assertFalse("user" in data) @@ -275,8 +269,7 @@ class TestGetChartData(ZulipTestCase): result = self.client_get( "/json/analytics/chart_data", {"chart_name": "messages_sent_over_time"} ) - self.assert_json_success(result) - data = result.json() + data = self.assert_json_success(result) self.assertEqual(data["everyone"], {"human": [0], "bot": [0]}) self.assertEqual(data["user"], {"human": [0], "bot": [0]}) @@ -288,8 +281,7 @@ class TestGetChartData(ZulipTestCase): result = self.client_get( "/json/analytics/chart_data", {"chart_name": "messages_sent_by_message_type"} ) - self.assert_json_success(result) - data = result.json() + data = self.assert_json_success(result) self.assertEqual( data["everyone"], { @@ -317,8 +309,7 @@ class TestGetChartData(ZulipTestCase): result = self.client_get( "/json/analytics/chart_data", {"chart_name": "messages_sent_by_client"} ) - self.assert_json_success(result) - data = result.json() + data = self.assert_json_success(result) self.assertEqual(data["everyone"], {}) self.assertEqual(data["user"], {}) @@ -340,8 +331,7 @@ class TestGetChartData(ZulipTestCase): "end": end_time_timestamps[2], }, ) - self.assert_json_success(result) - data = result.json() + data = self.assert_json_success(result) self.assertEqual(data["end_times"], end_time_timestamps[1:3]) self.assertEqual( data["everyone"], {"_1day": [0, 100], "_15day": [0, 100], "all_time": [0, 100]} @@ -369,8 +359,7 @@ class TestGetChartData(ZulipTestCase): result = self.client_get( "/json/analytics/chart_data", {"chart_name": "number_of_humans", "min_length": 2} ) - self.assert_json_success(result) - data = result.json() + data = self.assert_json_success(result) self.assertEqual( data["end_times"], [datetime_to_timestamp(dt) for dt in self.end_times_day] ) @@ -382,8 +371,7 @@ class TestGetChartData(ZulipTestCase): result = self.client_get( "/json/analytics/chart_data", {"chart_name": "number_of_humans", "min_length": 5} ) - self.assert_json_success(result) - data = result.json() + data = self.assert_json_success(result) end_times = [ ceiling_to_day(self.realm.date_created) + timedelta(days=i) for i in range(-1, 4) ] diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py index aa85c08a16..b660eb98e7 100644 --- a/corporate/tests/test_stripe.py +++ b/corporate/tests/test_stripe.py @@ -458,8 +458,8 @@ class StripeTestCase(ZulipTestCase): "stripe_session_id": stripe_session_id, }, ) - self.assert_json_success(json_response) - self.assertEqual(json_response.json()["session"], expected_details) + response_dict = self.assert_json_success(json_response) + self.assertEqual(response_dict["session"], expected_details) def assert_details_of_valid_payment_intent_from_event_status_endpoint( self, @@ -472,8 +472,8 @@ class StripeTestCase(ZulipTestCase): "stripe_payment_intent_id": stripe_payment_intent_id, }, ) - self.assert_json_success(json_response) - self.assertEqual(json_response.json()["payment_intent"], expected_details) + response_dict = self.assert_json_success(json_response) + self.assertEqual(response_dict["payment_intent"], expected_details) def trigger_stripe_checkout_session_completed_webhook( self, @@ -590,8 +590,9 @@ class StripeTestCase(ZulipTestCase): "stripe_payment_intent_id" ] = last_stripe_payment_intent.stripe_payment_intent_id + response_dict = self.assert_json_success(upgrade_json_response) self.assert_details_of_valid_session_from_event_status_endpoint( - upgrade_json_response.json()["stripe_session_id"], expected_session_details + response_dict["stripe_session_id"], expected_session_details ) if payment_method is None: payment_method = create_payment_method( @@ -695,8 +696,10 @@ class StripeTest(StripeTestCase): response = self.upgrade() [payment_intent] = PaymentIntent.objects.all() assert payment_intent.stripe_payment_intent_id is not None + + response_dict = self.assert_json_success(response) self.assert_details_of_valid_session_from_event_status_endpoint( - response.json()["stripe_session_id"], + response_dict["stripe_session_id"], { "type": "upgrade_from_billing_page", "status": "completed", @@ -1017,8 +1020,10 @@ class StripeTest(StripeTestCase): with patch("corporate.lib.stripe.timezone_now", return_value=self.now): response = self.upgrade() self.assertEqual(PaymentIntent.objects.count(), 0) + + response_dict = self.assert_json_success(response) self.assert_details_of_valid_session_from_event_status_endpoint( - response.json()["stripe_session_id"], + response_dict["stripe_session_id"], { "type": "free_trial_upgrade_from_billing_page", "status": "completed", @@ -1233,8 +1238,10 @@ class StripeTest(StripeTestCase): with patch("corporate.lib.stripe.timezone_now", return_value=self.now): response = self.upgrade(onboarding=True) self.assertEqual(PaymentIntent.objects.all().count(), 0) + + response_dict = self.assert_json_success(response) self.assert_details_of_valid_session_from_event_status_endpoint( - response.json()["stripe_session_id"], + response_dict["stripe_session_id"], { "type": "free_trial_upgrade_from_onboarding_page", "status": "completed", @@ -1488,8 +1495,9 @@ class StripeTest(StripeTestCase): ) [payment_intent] = PaymentIntent.objects.all() + response_dict = self.assert_json_success(response) self.assert_details_of_valid_session_from_event_status_endpoint( - response.json()["stripe_session_id"], + response_dict["stripe_session_id"], { "type": "upgrade_from_billing_page", "status": "completed", @@ -1547,8 +1555,9 @@ class StripeTest(StripeTestCase): ) self.assert_json_success(retry_payment_intent_json_response) [payment_intent] = PaymentIntent.objects.all() + response_dict = self.assert_json_success(retry_payment_intent_json_response) self.assert_details_of_valid_session_from_event_status_endpoint( - retry_payment_intent_json_response.json()["stripe_session_id"], + response_dict["stripe_session_id"], { "type": "retry_upgrade_with_another_payment_method", "status": "created", @@ -1568,8 +1577,9 @@ class StripeTest(StripeTestCase): ) self.send_stripe_webhook_events(last_event) + response_dict = self.assert_json_success(retry_payment_intent_json_response) self.assert_details_of_valid_session_from_event_status_endpoint( - retry_payment_intent_json_response.json()["stripe_session_id"], + response_dict["stripe_session_id"], { "type": "retry_upgrade_with_another_payment_method", "status": "completed", @@ -1654,8 +1664,9 @@ class StripeTest(StripeTestCase): [payment_intent] = PaymentIntent.objects.all() assert payment_intent.stripe_payment_intent_id is not None + response_dict = self.assert_json_success(response) self.assert_details_of_valid_session_from_event_status_endpoint( - response.json()["stripe_session_id"], + response_dict["stripe_session_id"], { "type": "upgrade_from_billing_page", "status": "completed", @@ -1712,8 +1723,9 @@ class StripeTest(StripeTestCase): response = self.upgrade() [second_payment_intent, _] = PaymentIntent.objects.all().order_by("-id") assert second_payment_intent.stripe_payment_intent_id is not None + response_dict = self.assert_json_success(response) self.assert_details_of_valid_session_from_event_status_endpoint( - response.json()["stripe_session_id"], + response_dict["stripe_session_id"], { "type": "upgrade_from_billing_page", "status": "completed", @@ -2068,8 +2080,9 @@ class StripeTest(StripeTestCase): ), self.assertLogs("corporate.stripe", "WARNING"): response = self.upgrade() + response_dict = self.assert_json_success(response) self.assert_details_of_valid_session_from_event_status_endpoint( - response.json()["stripe_session_id"], + response_dict["stripe_session_id"], { "type": "upgrade_from_billing_page", "status": "completed", @@ -2095,8 +2108,9 @@ class StripeTest(StripeTestCase): response = self.upgrade() [payment_intent] = PaymentIntent.objects.all().order_by("-id") + response_dict = self.assert_json_success(response) self.assert_details_of_valid_session_from_event_status_endpoint( - response.json()["stripe_session_id"], + response_dict["stripe_session_id"], { "type": "upgrade_from_billing_page", "status": "completed", @@ -2548,8 +2562,9 @@ class StripeTest(StripeTestCase): start_session_json_response = self.client_post( "/json/billing/session/start_card_update_session" ) + response_dict = self.assert_json_success(start_session_json_response) self.assert_details_of_valid_session_from_event_status_endpoint( - start_session_json_response.json()["stripe_session_id"], + response_dict["stripe_session_id"], { "type": "card_update_from_billing_page", "status": "created", @@ -2567,8 +2582,9 @@ class StripeTest(StripeTestCase): start_session_json_response = self.client_post( "/json/billing/session/start_card_update_session" ) + response_dict = self.assert_json_success(start_session_json_response) self.assert_details_of_valid_session_from_event_status_endpoint( - start_session_json_response.json()["stripe_session_id"], + response_dict["stripe_session_id"], { "type": "card_update_from_billing_page", "status": "created", @@ -2584,8 +2600,9 @@ class StripeTest(StripeTestCase): m.output[0], "INFO:corporate.stripe:Stripe card error: 402 card_error card_declined None", ) + response_dict = self.assert_json_success(start_session_json_response) self.assert_details_of_valid_session_from_event_status_endpoint( - start_session_json_response.json()["stripe_session_id"], + response_dict["stripe_session_id"], { "type": "card_update_from_billing_page", "status": "completed", @@ -2620,8 +2637,9 @@ class StripeTest(StripeTestCase): ) ) ) + response_dict = self.assert_json_success(start_session_json_response) self.assert_details_of_valid_session_from_event_status_endpoint( - start_session_json_response.json()["stripe_session_id"], + response_dict["stripe_session_id"], { "type": "card_update_from_billing_page", "status": "completed", @@ -2632,7 +2650,7 @@ class StripeTest(StripeTestCase): self.login_user(self.example_user("iago")) response = self.client_get( "/json/billing/event/status", - {"stripe_session_id": start_session_json_response.json()["stripe_session_id"]}, + {"stripe_session_id": response_dict["stripe_session_id"]}, ) self.assert_json_error_contains( response, "Must be a billing administrator or an organization owner" diff --git a/zerver/tests/test_alert_words.py b/zerver/tests/test_alert_words.py index 204ceda749..3094cb9024 100644 --- a/zerver/tests/test_alert_words.py +++ b/zerver/tests/test_alert_words.py @@ -116,8 +116,8 @@ class AlertWordTests(ZulipTestCase): self.login_user(user) result = self.client_get("/json/users/me/alert_words") - self.assert_json_success(result) - self.assertEqual(result.json()["alert_words"], []) + response_dict = self.assert_json_success(result) + self.assertEqual(response_dict["alert_words"], []) def test_json_list_nonempty(self) -> None: user = self.get_user() @@ -125,8 +125,8 @@ class AlertWordTests(ZulipTestCase): self.login_user(user) result = self.client_get("/json/users/me/alert_words") - self.assert_json_success(result) - self.assertEqual(set(result.json()["alert_words"]), {"one", "two", "three"}) + response_dict = self.assert_json_success(result) + self.assertEqual(set(response_dict["alert_words"]), {"one", "two", "three"}) def test_json_list_add(self) -> None: user = self.get_user() @@ -136,8 +136,8 @@ class AlertWordTests(ZulipTestCase): "/json/users/me/alert_words", {"alert_words": orjson.dumps(["one ", "\n two", "three"]).decode()}, ) - self.assert_json_success(result) - self.assertEqual(set(result.json()["alert_words"]), {"one", "two", "three"}) + response_dict = self.assert_json_success(result) + self.assertEqual(set(response_dict["alert_words"]), {"one", "two", "three"}) def test_json_list_remove(self) -> None: user = self.get_user() @@ -147,14 +147,14 @@ class AlertWordTests(ZulipTestCase): "/json/users/me/alert_words", {"alert_words": orjson.dumps(["one", "two", "three"]).decode()}, ) - self.assert_json_success(result) - self.assertEqual(set(result.json()["alert_words"]), {"one", "two", "three"}) + response_dict = self.assert_json_success(result) + self.assertEqual(set(response_dict["alert_words"]), {"one", "two", "three"}) result = self.client_delete( "/json/users/me/alert_words", {"alert_words": orjson.dumps(["one"]).decode()} ) - self.assert_json_success(result) - self.assertEqual(set(result.json()["alert_words"]), {"two", "three"}) + response_dict = self.assert_json_success(result) + self.assertEqual(set(response_dict["alert_words"]), {"two", "three"}) def message_does_alert(self, user: UserProfile, message: str) -> bool: """Send a bunch of messages as othello, so our user is notified""" @@ -170,8 +170,8 @@ class AlertWordTests(ZulipTestCase): "/json/users/me/alert_words", {"alert_words": orjson.dumps(["one", "two", "three"]).decode()}, ) - self.assert_json_success(result) - self.assertEqual(set(result.json()["alert_words"]), {"one", "two", "three"}) + response_dict = self.assert_json_success(result) + self.assertEqual(set(response_dict["alert_words"]), {"one", "two", "three"}) # Alerts in the middle of messages work. self.assertTrue(self.message_does_alert(user, "Normal alert one time")) diff --git a/zerver/tests/test_attachments.py b/zerver/tests/test_attachments.py index 32d9f9f5c2..872143af27 100644 --- a/zerver/tests/test_attachments.py +++ b/zerver/tests/test_attachments.py @@ -22,9 +22,9 @@ class AttachmentsTests(ZulipTestCase): user_profile = self.example_user("cordelia") self.login_user(user_profile) result = self.client_get("/json/attachments") - self.assert_json_success(result) + response_dict = self.assert_json_success(result) attachments = user_attachments(user_profile) - self.assertEqual(result.json()["attachments"], attachments) + self.assertEqual(response_dict["attachments"], attachments) def test_remove_attachment_exception(self) -> None: user_profile = self.example_user("cordelia") @@ -48,8 +48,8 @@ class AttachmentsTests(ZulipTestCase): user_profile = self.example_user("iago") self.login_user(user_profile) result = self.client_get("/json/attachments") - self.assert_json_success(result) - self.assertEqual(result.json()["attachments"], []) + response_dict = self.assert_json_success(result) + self.assertEqual(response_dict["attachments"], []) def test_remove_another_user(self) -> None: user_profile = self.example_user("iago") diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index e48a430d9a..65b174a88e 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -4638,8 +4638,7 @@ class DevFetchAPIKeyTest(ZulipTestCase): def test_success(self) -> None: result = self.client_post("/api/v1/dev_fetch_api_key", dict(username=self.email)) - self.assert_json_success(result) - data = result.json() + data = self.assert_json_success(result) self.assertEqual(data["email"], self.email) user_api_keys = get_all_api_keys(self.user_profile) self.assertIn(data["api_key"], user_api_keys) @@ -4812,7 +4811,7 @@ class FetchAuthBackends(ZulipTestCase): authentication_methods_list.append((backend_name_with_case.lower(), check_bool)) external_auth_methods = get_external_method_dicts() - self.assert_json_success(result) + response_dict = self.assert_json_success(result) checker = check_dict_only( [ ("authentication_methods", check_dict_only(authentication_methods_list)), @@ -4845,18 +4844,20 @@ class FetchAuthBackends(ZulipTestCase): *extra_fields, ] ) - checker("data", result.json()) + checker("data", response_dict) result = self.client_get("/api/v1/server_settings", subdomain="", HTTP_USER_AGENT="") check_result(result) + response_dict = self.assert_json_success(result) self.assertEqual( - result.json()["external_authentication_methods"], get_external_method_dicts() + response_dict["external_authentication_methods"], get_external_method_dicts() ) result = self.client_get( "/api/v1/server_settings", subdomain="", HTTP_USER_AGENT="ZulipInvalid" ) - self.assertTrue(result.json()["is_incompatible"]) + response_dict = self.assert_json_success(result) + self.assertTrue(response_dict["is_incompatible"]) with self.settings(ROOT_DOMAIN_LANDING_PAGE=False): result = self.client_get("/api/v1/server_settings", subdomain="", HTTP_USER_AGENT="") diff --git a/zerver/tests/test_bots.py b/zerver/tests/test_bots.py index 054fbc9ef7..f6be2329bd 100644 --- a/zerver/tests/test_bots.py +++ b/zerver/tests/test_bots.py @@ -53,8 +53,8 @@ class BotTest(ZulipTestCase, UploadSerializeMixin): def assert_num_bots_equal(self, count: int) -> None: result = self.client_get("/json/bots") - self.assert_json_success(result) - self.assert_length(result.json()["bots"], count) + response_dict = self.assert_json_success(result) + self.assert_length(response_dict["bots"], count) def create_bot(self, **extras: Any) -> Dict[str, Any]: bot_info = { @@ -64,8 +64,8 @@ class BotTest(ZulipTestCase, UploadSerializeMixin): } bot_info.update(extras) result = self.client_post("/json/bots", bot_info) - self.assert_json_success(result) - return result.json() + response_dict = self.assert_json_success(result) + return response_dict def test_bot_domain(self) -> None: self.login("hamlet") @@ -625,7 +625,8 @@ class BotTest(ZulipTestCase, UploadSerializeMixin): result = self.client_post("/json/bots", bot_info, subdomain="zephyr") self.assert_json_success(result) result = self.client_get("/json/bots", subdomain="zephyr") - bot_email = result.json()["bots"][0]["username"] + response_dict = self.assert_json_success(result) + bot_email = response_dict["bots"][0]["username"] bot = get_user(bot_email, user.realm) self.login("iago") result = self.client_delete(f"/json/bots/{bot.id}") @@ -680,8 +681,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin): def get_bot(self) -> Dict[str, Any]: result = self.client_get("/json/bots") - bots = result.json()["bots"] - return bots[0] + return self.assert_json_success(result)["bots"][0] def test_update_api_key(self) -> None: self.login("hamlet") @@ -690,8 +690,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin): old_api_key = bot["api_key"] email = "hambot-bot@zulip.testserver" result = self.client_post(f"/json/bots/{self.get_bot_user(email).id}/api_key/regenerate") - self.assert_json_success(result) - new_api_key = result.json()["api_key"] + new_api_key = self.assert_json_success(result)["api_key"] self.assertNotEqual(old_api_key, new_api_key) bot = self.get_bot() self.assertEqual(new_api_key, bot["api_key"]) @@ -848,9 +847,9 @@ class BotTest(ZulipTestCase, UploadSerializeMixin): } email = "hambot-bot@zulip.testserver" result = self.client_patch(f"/json/bots/{self.get_bot_user(email).id}", bot_info) - self.assert_json_success(result) + response_dict = self.assert_json_success(result) - self.assertEqual("Fred", result.json()["full_name"]) + self.assertEqual("Fred", response_dict["full_name"]) bot = self.get_bot() self.assertEqual("Fred", bot["full_name"]) @@ -928,10 +927,10 @@ class BotTest(ZulipTestCase, UploadSerializeMixin): } email = "hambot-bot@zulip.testserver" result = self.client_patch(f"/json/bots/{self.get_bot_user(email).id}", bot_info) - self.assert_json_success(result) + response_dict = self.assert_json_success(result) # Test bot's owner has been changed successfully. - self.assertEqual(result.json()["bot_owner"], othello.email) + self.assertEqual(response_dict["bot_owner"], othello.email) self.login("othello") bot = self.get_bot() @@ -1119,9 +1118,9 @@ class BotTest(ZulipTestCase, UploadSerializeMixin): } email = "hambot-bot@zulip.testserver" result = self.client_patch(f"/json/bots/{self.get_bot_user(email).id}", bot_info) - self.assert_json_success(result) + response_dict = self.assert_json_success(result) - self.assertEqual("Denmark", result.json()["default_sending_stream"]) + self.assertEqual("Denmark", response_dict["default_sending_stream"]) bot = self.get_bot() self.assertEqual("Denmark", bot["default_sending_stream"]) @@ -1139,9 +1138,9 @@ class BotTest(ZulipTestCase, UploadSerializeMixin): } email = "hambot-bot@zulip.testserver" result = self.client_patch(f"/json/bots/{self.get_bot_user(email).id}", bot_info) - self.assert_json_success(result) + response_dict = self.assert_json_success(result) - self.assertEqual("Rome", result.json()["default_sending_stream"]) + self.assertEqual("Rome", response_dict["default_sending_stream"]) bot = self.get_bot() self.assertEqual("Rome", bot["default_sending_stream"]) @@ -1212,9 +1211,9 @@ class BotTest(ZulipTestCase, UploadSerializeMixin): } email = "hambot-bot@zulip.testserver" result = self.client_patch(f"/json/bots/{self.get_bot_user(email).id}", bot_info) - self.assert_json_success(result) + response_dict = self.assert_json_success(result) - self.assertEqual("Denmark", result.json()["default_sending_stream"]) + self.assertEqual("Denmark", response_dict["default_sending_stream"]) bot = self.get_bot() self.assertEqual("Denmark", bot["default_sending_stream"]) @@ -1275,9 +1274,9 @@ class BotTest(ZulipTestCase, UploadSerializeMixin): stream_name = "Denmark" bot_info = dict(default_events_register_stream=stream_name) result = self.client_patch(url, bot_info) - self.assert_json_success(result) + response_dict = self.assert_json_success(result) - self.assertEqual(stream_name, result.json()["default_events_register_stream"]) + self.assertEqual(stream_name, response_dict["default_events_register_stream"]) bot = self.get_bot() self.assertEqual(stream_name, bot["default_events_register_stream"]) @@ -1320,9 +1319,9 @@ class BotTest(ZulipTestCase, UploadSerializeMixin): } email = "hambot-bot@zulip.testserver" result = self.client_patch(f"/json/bots/{self.get_bot_user(email).id}", bot_info) - self.assert_json_success(result) + response_dict = self.assert_json_success(result) - self.assertEqual("Denmark", result.json()["default_events_register_stream"]) + self.assertEqual("Denmark", response_dict["default_events_register_stream"]) bot = self.get_bot() self.assertEqual("Denmark", bot["default_events_register_stream"]) @@ -1402,9 +1401,9 @@ class BotTest(ZulipTestCase, UploadSerializeMixin): } email = "hambot-bot@zulip.testserver" result = self.client_patch(f"/json/bots/{self.get_bot_user(email).id}", bot_info) - self.assert_json_success(result) + response_dict = self.assert_json_success(result) - self.assertEqual(result.json()["default_all_public_streams"], True) + self.assertEqual(response_dict["default_all_public_streams"], True) bot = self.get_bot() self.assertEqual(bot["default_all_public_streams"], True) @@ -1422,9 +1421,9 @@ class BotTest(ZulipTestCase, UploadSerializeMixin): } email = "hambot-bot@zulip.testserver" result = self.client_patch(f"/json/bots/{self.get_bot_user(email).id}", bot_info) - self.assert_json_success(result) + response_dict = self.assert_json_success(result) - self.assertEqual(result.json()["default_all_public_streams"], False) + self.assertEqual(response_dict["default_all_public_streams"], False) bot = self.get_bot() self.assertEqual(bot["default_all_public_streams"], False) @@ -1444,9 +1443,9 @@ class BotTest(ZulipTestCase, UploadSerializeMixin): email = "hambot-bot@zulip.testserver" # Important: We intentionally use the wrong method, post, here. result = self.client_post(f"/json/bots/{self.get_bot_user(email).id}", bot_info) - self.assert_json_success(result) + response_dict = self.assert_json_success(result) - self.assertEqual("Fred", result.json()["full_name"]) + self.assertEqual("Fred", response_dict["full_name"]) bot = self.get_bot() self.assertEqual("Fred", bot["full_name"]) diff --git a/zerver/tests/test_create_video_call.py b/zerver/tests/test_create_video_call.py index 8f3efb7f6b..4eae085cce 100644 --- a/zerver/tests/test_create_video_call.py +++ b/zerver/tests/test_create_video_call.py @@ -184,9 +184,9 @@ class TestVideoCall(ZulipTestCase): response = self.client_get( "/json/calls/bigbluebutton/create?meeting_name=general > meeting" ) - self.assert_json_success(response) + response_dict = self.assert_json_success(response) self.assertEqual( - response.json()["url"], + response_dict["url"], append_url_query_string( "/calls/bigbluebutton/join", "bigbluebutton=" diff --git a/zerver/tests/test_custom_profile_data.py b/zerver/tests/test_custom_profile_data.py index b76cf92cf3..ac701cbb4a 100644 --- a/zerver/tests/test_custom_profile_data.py +++ b/zerver/tests/test_custom_profile_data.py @@ -731,9 +731,8 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase): def test_list(self) -> None: self.login("iago") result = self.client_get("/json/realm/profile_fields") - self.assert_json_success(result) + content = self.assert_json_success(result) self.assertEqual(200, result.status_code) - content = result.json() self.assert_length(content["custom_fields"], self.original_count) def test_list_order(self) -> None: @@ -746,7 +745,7 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase): ) try_reorder_realm_custom_profile_fields(realm, order) result = self.client_get("/json/realm/profile_fields") - content = result.json() + content = self.assert_json_success(result) self.assertListEqual( content["custom_fields"], sorted(content["custom_fields"], key=lambda x: -x["id"]) ) @@ -764,8 +763,7 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase): self.assert_length(queries, 4) - self.assertEqual(response.status_code, 200) - raw_users_data = response.json()["members"] + raw_users_data = self.assert_json_success(response)["members"] iago_raw_data = None test_bot_raw_data = None @@ -826,8 +824,7 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase): self.assertEqual(test_bot_raw_data["bot_owner_id"], iago_raw_data["user_id"]) response = self.client_get("/json/users", {"client_gravatar": "false"}) - self.assertEqual(response.status_code, 200) - raw_users_data = response.json()["members"] + raw_users_data = self.assert_json_success(response)["members"] for user_dict in raw_users_data: with self.assertRaises(KeyError): user_dict["profile_data"] @@ -858,8 +855,7 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase): url = "/json/users/me" response = self.client_get(url) - self.assertEqual(response.status_code, 200) - raw_user_data = response.json() + raw_user_data = self.assert_json_success(response) self.assertEqual(set(raw_user_data.keys()), expected_keys) diff --git a/zerver/tests/test_email_change.py b/zerver/tests/test_email_change.py index 142ec3350b..1530008f18 100644 --- a/zerver/tests/test_email_change.py +++ b/zerver/tests/test_email_change.py @@ -238,8 +238,9 @@ class EmailChangeTestCase(ZulipTestCase): self.login("hamlet") url = "/json/settings" result = self.client_patch(url, data) - self.assertEqual("success", result.json()["result"]) - self.assertEqual("", result.json()["msg"]) + response_dict = self.assert_json_success(result) + self.assertEqual("success", response_dict["result"]) + self.assertEqual("", response_dict["msg"]) def test_change_delivery_email_end_to_end_with_admins_visibility(self) -> None: user_profile = self.example_user("hamlet") diff --git a/zerver/tests/test_event_queue.py b/zerver/tests/test_event_queue.py index bbb2320bde..0b374dc98e 100644 --- a/zerver/tests/test_event_queue.py +++ b/zerver/tests/test_event_queue.py @@ -583,8 +583,8 @@ class MissedMessageNotificationsTest(ZulipTestCase): "bot_type": "1", } result = self.client_post("/json/bots", bot_info) - self.assert_json_success(result) - hambot = UserProfile.objects.get(id=result.json()["user_id"]) + response_dict = self.assert_json_success(result) + hambot = UserProfile.objects.get(id=response_dict["user_id"]) client_descriptor = allocate_event_queue(hambot) self.assertTrue(client_descriptor.event_queue.empty()) msg_id = self.send_personal_message(iago, hambot) diff --git a/zerver/tests/test_event_system.py b/zerver/tests/test_event_system.py index ebf8c412c9..c27d8afa85 100644 --- a/zerver/tests/test_event_system.py +++ b/zerver/tests/test_event_system.py @@ -79,8 +79,7 @@ class EventsEndpointTest(ZulipTestCase): user, "/json/register", dict(event_types=orjson.dumps([event_type]).decode()) ) - self.assert_json_success(result) - result_dict = result.json() + result_dict = self.assert_json_success(result) self.assertEqual(result_dict["last_event_id"], -1) self.assertEqual(result_dict["queue_id"], "15:11") @@ -93,8 +92,7 @@ class EventsEndpointTest(ZulipTestCase): user, "/json/register", dict(event_types=orjson.dumps([event_type]).decode()) ) - self.assert_json_success(result) - result_dict = result.json() + result_dict = self.assert_json_success(result) self.assertEqual(result_dict["last_event_id"], 6) self.assertEqual(result_dict["queue_id"], "15:12") @@ -112,8 +110,7 @@ class EventsEndpointTest(ZulipTestCase): fetch_event_types=orjson.dumps(["message"]).decode(), ), ) - self.assert_json_success(result) - result_dict = result.json() + result_dict = self.assert_json_success(result) self.assertEqual(result_dict["last_event_id"], 6) # Check that the message event types data is in there self.assertIn("max_message_id", result_dict) @@ -132,8 +129,7 @@ class EventsEndpointTest(ZulipTestCase): event_types=orjson.dumps(["message"]).decode(), ), ) - self.assert_json_success(result) - result_dict = result.json() + result_dict = self.assert_json_success(result) self.assertEqual(result_dict["last_event_id"], 6) # Check that we didn't fetch the messages data self.assertNotIn("max_message_id", result_dict) @@ -155,8 +151,7 @@ class EventsEndpointTest(ZulipTestCase): ) result = self.client_post("/json/register", dict()) - self.assert_json_success(result) - result_dict = result.json() + result_dict = self.assert_json_success(result) self.assertEqual(result_dict["queue_id"], None) self.assertEqual(result_dict["realm_uri"], "http://zulip.testserver") diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index 7596107aef..8a8830597c 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -2213,9 +2213,9 @@ class NormalActionsTest(BaseAction): nonlocal uri result = self.client_post("/json/user_uploads", {"file": fp}) - self.assert_json_success(result) - self.assertIn("uri", result.json()) - uri = result.json()["uri"] + response_dict = self.assert_json_success(result) + self.assertIn("uri", response_dict) + uri = response_dict["uri"] base = "/user_uploads/" self.assertEqual(base, uri[: len(base)]) diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.py index 3c920bf94c..aa90b09d05 100644 --- a/zerver/tests/test_markdown.py +++ b/zerver/tests/test_markdown.py @@ -2815,9 +2815,9 @@ class MarkdownApiTests(ZulipTestCase): "/api/v1/messages/render", dict(content=content), ) - self.assert_json_success(result) + response_dict = self.assert_json_success(result) self.assertEqual( - result.json()["rendered"], "
That is a bold statement
" + response_dict["rendered"], "That is a bold statement
" ) def test_render_mention_stream_api(self) -> None: @@ -2828,11 +2828,11 @@ class MarkdownApiTests(ZulipTestCase): "/api/v1/messages/render", dict(content=content), ) - self.assert_json_success(result) + response_dict = self.assert_json_success(result) user_id = self.example_user("hamlet").id stream_id = get_stream("Denmark", get_realm("zulip")).id self.assertEqual( - result.json()["rendered"], + response_dict["rendered"], f'This mentions #Denmark and @King Hamlet.
', ) diff --git a/zerver/tests/test_message_edit.py b/zerver/tests/test_message_edit.py index 1c9f294574..8ec6a49d44 100644 --- a/zerver/tests/test_message_edit.py +++ b/zerver/tests/test_message_edit.py @@ -317,10 +317,10 @@ class EditMessageTest(EditMessageTestCase): content="Personal message", ) result = self.client_get("/json/messages/" + str(msg_id)) - self.assert_json_success(result) - self.assertEqual(result.json()["raw_content"], "Personal message") - self.assertEqual(result.json()["message"]["id"], msg_id) - self.assertEqual(result.json()["message"]["flags"], []) + response_dict = self.assert_json_success(result) + self.assertEqual(response_dict["raw_content"], "Personal message") + self.assertEqual(response_dict["message"]["id"], msg_id) + self.assertEqual(response_dict["message"]["flags"], []) # Send message to web-public stream where hamlet is not subscribed. # This will test case of user having no `UserMessage` but having access @@ -331,28 +331,28 @@ class EditMessageTest(EditMessageTestCase): self.example_user("cordelia"), web_public_stream.name, content="web-public message" ) result = self.client_get("/json/messages/" + str(web_public_stream_msg_id)) - self.assert_json_success(result) - self.assertEqual(result.json()["raw_content"], "web-public message") - self.assertEqual(result.json()["message"]["id"], web_public_stream_msg_id) - self.assertEqual(result.json()["message"]["flags"], ["read", "historical"]) + response_dict = self.assert_json_success(result) + self.assertEqual(response_dict["raw_content"], "web-public message") + self.assertEqual(response_dict["message"]["id"], web_public_stream_msg_id) + self.assertEqual(response_dict["message"]["flags"], ["read", "historical"]) # Spectator should be able to fetch message in web-public stream. self.logout() result = self.client_get("/json/messages/" + str(web_public_stream_msg_id)) - self.assert_json_success(result) - self.assertEqual(result.json()["raw_content"], "web-public message") - self.assertEqual(result.json()["message"]["id"], web_public_stream_msg_id) + response_dict = self.assert_json_success(result) + self.assertEqual(response_dict["raw_content"], "web-public message") + self.assertEqual(response_dict["message"]["id"], web_public_stream_msg_id) # Verify default is apply_markdown=True - self.assertEqual(result.json()["message"]["content"], "web-public message
") + self.assertEqual(response_dict["message"]["content"], "web-public message
") # Verify apply_markdown=False works correctly. result = self.client_get( "/json/messages/" + str(web_public_stream_msg_id), {"apply_markdown": "false"} ) - self.assert_json_success(result) - self.assertEqual(result.json()["raw_content"], "web-public message") - self.assertEqual(result.json()["message"]["content"], "web-public message") + response_dict = self.assert_json_success(result) + self.assertEqual(response_dict["raw_content"], "web-public message") + self.assertEqual(response_dict["message"]["content"], "web-public message") with self.settings(WEB_PUBLIC_STREAMS_ENABLED=False): result = self.client_get("/json/messages/" + str(web_public_stream_msg_id)) @@ -414,9 +414,9 @@ class EditMessageTest(EditMessageTestCase): # Verify success with web-public stream and default SELF_HOSTED plan type. result = self.client_get("/json/messages/" + str(web_public_stream_msg_id)) - self.assert_json_success(result) - self.assertEqual(result.json()["raw_content"], "web-public message") - self.assertEqual(result.json()["message"]["flags"], ["read"]) + response_dict = self.assert_json_success(result) + self.assertEqual(response_dict["raw_content"], "web-public message") + self.assertEqual(response_dict["message"]["flags"], ["read"]) # Verify LIMITED plan type does not allow web-public access. do_change_realm_plan_type(user_profile.realm, Realm.PLAN_TYPE_LIMITED, acting_user=None) @@ -430,8 +430,8 @@ class EditMessageTest(EditMessageTestCase): user_profile.realm, Realm.PLAN_TYPE_STANDARD_FREE, acting_user=None ) result = self.client_get("/json/messages/" + str(web_public_stream_msg_id)) - self.assert_json_success(result) - self.assertEqual(result.json()["raw_content"], "web-public message") + response_dict = self.assert_json_success(result) + self.assertEqual(response_dict["raw_content"], "web-public message") # Verify private messages are rejected. result = self.client_get("/json/messages/" + str(private_message_id)) @@ -726,9 +726,7 @@ class EditMessageTest(EditMessageTestCase): result = self.client_get(f"/json/messages/{msg_id}/history") - self.assert_json_success(result) - - message_history = result.json()["message_history"] + message_history = self.assert_json_success(result)["message_history"] self.assert_length(message_history, 1) def test_mentions_for_message_updates(self) -> None: diff --git a/zerver/tests/test_message_fetch.py b/zerver/tests/test_message_fetch.py index 3c1c3b9d1c..2e8e604c93 100644 --- a/zerver/tests/test_message_fetch.py +++ b/zerver/tests/test_message_fetch.py @@ -2091,8 +2091,7 @@ class GetOldMessagesTest(ZulipTestCase): raw_params = dict(msg_ids=msg_ids, narrow=narrow) params = {k: orjson.dumps(v).decode() for k, v in raw_params.items()} result = self.client_get("/json/messages/matches_narrow", params) - self.assert_json_success(result) - messages = result.json()["messages"] + messages = self.assert_json_success(result)["messages"] self.assert_length(list(messages.keys()), 1) message = messages[str(good_id)] self.assertEqual( @@ -2486,8 +2485,7 @@ class GetOldMessagesTest(ZulipTestCase): raw_params = dict(msg_ids=msg_ids, narrow=narrow) params = {k: orjson.dumps(v).decode() for k, v in raw_params.items()} result = self.client_get("/json/messages/matches_narrow", params) - self.assert_json_success(result) - messages = result.json()["messages"] + messages = self.assert_json_success(result)["messages"] self.assert_length(list(messages.keys()), 1) message = messages[str(good_id)] self.assertIn("a href=", message["match_content"]) diff --git a/zerver/tests/test_message_topics.py b/zerver/tests/test_message_topics.py index f2b87fa76a..db6eed9bf3 100644 --- a/zerver/tests/test_message_topics.py +++ b/zerver/tests/test_message_topics.py @@ -21,8 +21,7 @@ class TopicHistoryTest(ZulipTestCase): self.subscribe(user_profile, stream_name) endpoint = f"/json/users/me/{stream.id}/topics" result = self.client_get(endpoint, {}, subdomain="zephyr") - self.assert_json_success(result) - history = result.json()["topics"] + history = self.assert_json_success(result)["topics"] self.assertEqual(history, []) def test_topics_history(self) -> None: @@ -75,8 +74,7 @@ class TopicHistoryTest(ZulipTestCase): endpoint = f"/json/users/me/{stream.id}/topics" result = self.client_get(endpoint, {}) - self.assert_json_success(result) - history = result.json()["topics"] + history = self.assert_json_success(result)["topics"] # We only look at the most recent three topics, because # the prior fixture data may be unreliable. @@ -105,8 +103,7 @@ class TopicHistoryTest(ZulipTestCase): # same results for a public stream. self.login("cordelia") result = self.client_get(endpoint, {}) - self.assert_json_success(result) - history = result.json()["topics"] + history = self.assert_json_success(result)["topics"] # We only look at the most recent three topics, because # the prior fixture data may be unreliable. @@ -138,8 +135,7 @@ class TopicHistoryTest(ZulipTestCase): self.subscribe(self.example_user("cordelia"), stream.name) result = self.client_get(endpoint, {}) - self.assert_json_success(result) - history = result.json()["topics"] + history = self.assert_json_success(result)["topics"] history = history[:3] # Cordelia doesn't have these recent history items when we @@ -184,8 +180,7 @@ class TopicHistoryTest(ZulipTestCase): endpoint = f"/json/users/me/{stream.id}/topics" result = self.client_get(endpoint) - self.assert_json_success(result) - history = result.json()["topics"] + history = self.assert_json_success(result)["topics"] self.assertEqual( [topic["name"] for topic in history], [ diff --git a/zerver/tests/test_muting_users.py b/zerver/tests/test_muting_users.py index d6f1565f8c..a1914bfcff 100644 --- a/zerver/tests/test_muting_users.py +++ b/zerver/tests/test_muting_users.py @@ -55,8 +55,7 @@ class MutedUsersTests(ZulipTestCase): "bot_type": "1", } result = self.client_post("/json/bots", bot_info) - self.assert_json_success(result) - muted_id = result.json()["user_id"] + muted_id = self.assert_json_success(result)["user_id"] url = f"/api/v1/users/me/muted_users/{muted_id}" result = self.api_post(hamlet, url) diff --git a/zerver/tests/test_presence.py b/zerver/tests/test_presence.py index 64fc5cd641..d2115c512f 100644 --- a/zerver/tests/test_presence.py +++ b/zerver/tests/test_presence.py @@ -113,8 +113,7 @@ class UserPresenceTests(ZulipTestCase): params = dict(status="idle") result = self.client_post("/json/users/me/presence", params) - self.assert_json_success(result) - json = result.json() + json = self.assert_json_success(result) self.assertEqual(json["presences"][hamlet.email][client]["status"], "idle") self.assertIn("timestamp", json["presences"][hamlet.email][client]) self.assertIsInstance(json["presences"][hamlet.email][client]["timestamp"], int) @@ -123,7 +122,7 @@ class UserPresenceTests(ZulipTestCase): self.login_user(othello) params = dict(status="idle", slim_presence="true") result = self.client_post("/json/users/me/presence", params) - json = result.json() + json = self.assert_json_success(result) presences = json["presences"] self.assertEqual( set(presences.keys()), @@ -149,23 +148,21 @@ class UserPresenceTests(ZulipTestCase): params = dict(status="idle") result = self.client_post("/json/users/me/presence", params) - self.assert_json_success(result) + response_dict = self.assert_json_success(result) - self.assertEqual(result.json()["presences"][hamlet.email][client]["status"], "idle") + self.assertEqual(response_dict["presences"][hamlet.email][client]["status"], "idle") self.login("othello") params = dict(status="idle") result = self.client_post("/json/users/me/presence", params) - self.assert_json_success(result) - json = result.json() + json = self.assert_json_success(result) self.assertEqual(json["presences"][othello.email][client]["status"], "idle") self.assertEqual(json["presences"][hamlet.email][client]["status"], "idle") params = dict(status="active") result = self.client_post("/json/users/me/presence", params) - self.assert_json_success(result) - json = result.json() + json = self.assert_json_success(result) self.assertEqual(json["presences"][othello.email][client]["status"], "active") self.assertEqual(json["presences"][hamlet.email][client]["status"], "idle") @@ -173,8 +170,7 @@ class UserPresenceTests(ZulipTestCase): self.login_user(hamlet) params = dict(status="active", slim_presence="true") result = self.client_post("/json/users/me/presence", params) - self.assert_json_success(result) - json = result.json() + json = self.assert_json_success(result) presences = json["presences"] self.assertEqual( @@ -276,8 +272,8 @@ class UserPresenceTests(ZulipTestCase): user = self.mit_user("espuser") self.login_user(user) result = self.client_post("/json/users/me/presence", {"status": "idle"}, subdomain="zephyr") - self.assert_json_success(result) - self.assertEqual(result.json()["presences"], {}) + response_dict = self.assert_json_success(result) + self.assertEqual(response_dict["presences"], {}) def test_mirror_presence(self) -> None: """Zephyr mirror realms find out the status of their mirror bot""" @@ -288,8 +284,7 @@ class UserPresenceTests(ZulipTestCase): result = self.client_post( "/json/users/me/presence", {"status": "idle"}, subdomain="zephyr" ) - self.assert_json_success(result) - json = result.json() + json = self.assert_json_success(result) return json json = post_presence() @@ -321,8 +316,7 @@ class UserPresenceTests(ZulipTestCase): hamlet = self.example_user("hamlet") self.login_user(hamlet) result = self.client_post("/json/users/me/presence", {"status": "idle"}) - self.assert_json_success(result) - json = result.json() + json = self.assert_json_success(result) self.assertEqual(json["presences"][hamlet.email]["website"]["status"], "idle") self.assertEqual( json["presences"].keys(), @@ -402,14 +396,14 @@ class SingleUserPresenceTests(ZulipTestCase): # Then, we check everything works self.login("hamlet") result = self.client_get("/json/users/othello@zulip.com/presence") - result_dict = result.json() + result_dict = self.assert_json_success(result) self.assertEqual( set(result_dict["presence"].keys()), {"ZulipAndroid", "website", "aggregated"} ) self.assertEqual(set(result_dict["presence"]["website"].keys()), {"status", "timestamp"}) result = self.client_get(f"/json/users/{othello.id}/presence") - result_dict = result.json() + result_dict = self.assert_json_success(result) self.assertEqual( set(result_dict["presence"].keys()), {"ZulipAndroid", "website", "aggregated"} ) @@ -423,7 +417,7 @@ class SingleUserPresenceTests(ZulipTestCase): ping_only="true", ) result = self.client_post("/json/users/me/presence", req) - self.assertEqual(result.json()["msg"], "") + self.assertEqual(self.assert_json_success(result)["msg"], "") class UserPresenceAggregationTests(ZulipTestCase): @@ -448,7 +442,7 @@ class UserPresenceAggregationTests(ZulipTestCase): {"status": status}, HTTP_USER_AGENT="ZulipIOS/1.0", ) - latest_result_dict = latest_result.json() + latest_result_dict = self.assert_json_success(latest_result) self.assertDictEqual( latest_result_dict["presences"][user.email]["aggregated"], { @@ -459,7 +453,7 @@ class UserPresenceAggregationTests(ZulipTestCase): ) result = self.client_get(f"/json/users/{user.email}/presence") - return result.json() + return self.assert_json_success(result) def test_aggregated_info(self) -> None: user = self.example_user("othello") @@ -475,7 +469,7 @@ class UserPresenceAggregationTests(ZulipTestCase): {"status": "active"}, HTTP_USER_AGENT="ZulipTestDev/1.0", ) - result_dict = result.json() + result_dict = self.assert_json_success(result) self.assertDictEqual( result_dict["presences"][user.email]["aggregated"], { @@ -566,8 +560,7 @@ class GetRealmStatusesTest(ZulipTestCase): dict(status="idle"), HTTP_USER_AGENT="ZulipDesktop/1.0", ) - self.assert_json_success(result) - json = result.json() + json = self.assert_json_success(result) self.assertEqual(set(json["presences"].keys()), {hamlet.email, othello.email}) result = self.api_post( @@ -576,14 +569,12 @@ class GetRealmStatusesTest(ZulipTestCase): dict(status="active", slim_presence="true"), HTTP_USER_AGENT="ZulipDesktop/1.0", ) - self.assert_json_success(result) - json = result.json() + json = self.assert_json_success(result) self.assertEqual(set(json["presences"].keys()), {str(hamlet.id), str(othello.id)}) # Check that a bot can fetch the presence data for the realm. result = self.api_get(self.example_user("default_bot"), "/api/v1/realm/presence") - self.assert_json_success(result) - json = result.json() + json = self.assert_json_success(result) self.assertEqual(set(json["presences"].keys()), {hamlet.email, othello.email}) def test_presence_disabled(self) -> None: @@ -609,8 +600,7 @@ class GetRealmStatusesTest(ZulipTestCase): dict(status="idle"), HTTP_USER_AGENT="ZulipDesktop/1.0", ) - self.assert_json_success(result) - json = result.json() + json = self.assert_json_success(result) # Othello's presence status is disabled so it won't be reported. self.assertEqual(set(json["presences"].keys()), {hamlet.email}) @@ -621,6 +611,5 @@ class GetRealmStatusesTest(ZulipTestCase): dict(status="active", slim_presence="true"), HTTP_USER_AGENT="ZulipDesktop/1.0", ) - self.assert_json_success(result) - json = result.json() + json = self.assert_json_success(result) self.assertEqual(set(json["presences"].keys()), {str(hamlet.id)}) diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py index ae404bed8d..51f806e0c4 100644 --- a/zerver/tests/test_push_notifications.py +++ b/zerver/tests/test_push_notifications.py @@ -362,8 +362,7 @@ class PushBouncerNotificationTest(BouncerTestCase): payload, content_type="application/json", ) - self.assert_json_success(result) - data = result.json() + data = self.assert_json_success(result) self.assertEqual( {"result": "success", "msg": "", "total_android_devices": 2, "total_apple_devices": 1}, data, diff --git a/zerver/tests/test_reactions.py b/zerver/tests/test_reactions.py index 79b049cd4f..1d2e75405f 100644 --- a/zerver/tests/test_reactions.py +++ b/zerver/tests/test_reactions.py @@ -281,8 +281,7 @@ class ReactionMessageIDTest(ZulipTestCase): "/api/v1/messages", {"type": "private", "content": "Test message", "to": pm_recipient.email}, ) - self.assert_json_success(result) - pm_id = result.json()["id"] + pm_id = self.assert_json_success(result)["id"] reaction_info = { "emoji_name": "smile", } @@ -418,8 +417,7 @@ class ReactionEventTest(ZulipTestCase): "/api/v1/messages", {"type": "private", "content": "Test message", "to": pm_recipient.email}, ) - self.assert_json_success(result) - pm_id = result.json()["id"] + pm_id = self.assert_json_success(result)["id"] expected_recipient_ids = {pm_sender.id, pm_recipient.id} @@ -458,8 +456,7 @@ class ReactionEventTest(ZulipTestCase): "/api/v1/messages", {"type": "private", "content": "Test message", "to": pm_recipient.email}, ) - self.assert_json_success(result) - content = result.json() + content = self.assert_json_success(result) pm_id = content["id"] expected_recipient_ids = {pm_sender.id, pm_recipient.id} diff --git a/zerver/tests/test_realm_domains.py b/zerver/tests/test_realm_domains.py index d3a3a16f6d..0b0ee06f41 100644 --- a/zerver/tests/test_realm_domains.py +++ b/zerver/tests/test_realm_domains.py @@ -22,8 +22,7 @@ class RealmDomainTest(ZulipTestCase): realm = get_realm("zulip") RealmDomain.objects.create(realm=realm, domain="acme.com", allow_subdomains=True) result = self.client_get("/json/realm/domains") - self.assert_json_success(result) - received = result.json()["domains"] + received = self.assert_json_success(result)["domains"] expected = [ {"domain": "zulip.com", "allow_subdomains": False}, {"domain": "acme.com", "allow_subdomains": True}, diff --git a/zerver/tests/test_realm_emoji.py b/zerver/tests/test_realm_emoji.py index d06611eee4..6e553e73d2 100644 --- a/zerver/tests/test_realm_emoji.py +++ b/zerver/tests/test_realm_emoji.py @@ -32,9 +32,8 @@ class RealmEmojiTest(ZulipTestCase): self.create_test_emoji("my_emoji", emoji_author) result = self.client_get("/json/realm/emoji") - self.assert_json_success(result) - self.assertEqual(200, result.status_code) - self.assert_length(result.json()["emoji"], 2) + response_dict = self.assert_json_success(result) + self.assert_length(response_dict["emoji"], 2) def test_list_no_author(self) -> None: self.login("iago") @@ -42,8 +41,7 @@ class RealmEmojiTest(ZulipTestCase): realm_emoji = self.create_test_emoji_with_no_author("my_emoji", realm) result = self.client_get("/json/realm/emoji") - self.assert_json_success(result) - content = result.json() + content = self.assert_json_success(result) self.assert_length(content["emoji"], 2) test_emoji = content["emoji"][str(realm_emoji.id)] self.assertIsNone(test_emoji["author_id"]) @@ -58,8 +56,7 @@ class RealmEmojiTest(ZulipTestCase): realm_emoji = self.create_test_emoji_with_no_author("my_emoji", realm) result = self.client_get("/json/realm/emoji") - self.assert_json_success(result) - content = result.json() + content = self.assert_json_success(result) self.assert_length(content["emoji"], 2) test_emoji = content["emoji"][str(realm_emoji.id)] self.assertIsNone(test_emoji["author_id"]) @@ -78,8 +75,7 @@ class RealmEmojiTest(ZulipTestCase): self.assertEqual(realm_emoji.author.email, email) result = self.client_get("/json/realm/emoji") - content = result.json() - self.assert_json_success(result) + content = self.assert_json_success(result) self.assert_length(content["emoji"], 2) test_emoji = content["emoji"][str(realm_emoji.id)] self.assertIn("author_id", test_emoji) @@ -222,8 +218,7 @@ class RealmEmojiTest(ZulipTestCase): self.assert_json_success(result) result = self.client_get("/json/realm/emoji") - emojis = result.json()["emoji"] - self.assert_json_success(result) + emojis = self.assert_json_success(result)["emoji"] # We only mark an emoji as deactivated instead of # removing it from the database. self.assert_length(emojis, 2) @@ -313,8 +308,7 @@ class RealmEmojiTest(ZulipTestCase): self.assert_json_success(result) result = self.client_get("/json/realm/emoji") - emojis = result.json()["emoji"] - self.assert_json_success(result) + emojis = self.assert_json_success(result)["emoji"] self.assert_length(emojis, 3) def test_failed_file_upload(self) -> None: diff --git a/zerver/tests/test_realm_export.py b/zerver/tests/test_realm_export.py index 4c26cfd8a7..02b0711dab 100644 --- a/zerver/tests/test_realm_export.py +++ b/zerver/tests/test_realm_export.py @@ -74,10 +74,10 @@ class RealmExportTest(ZulipTestCase): self.assertEqual(bucket.Object(path_id).get()["Body"].read(), b"zulip!") result = self.client_get("/json/export/realm") - self.assert_json_success(result) + response_dict = self.assert_json_success(result) # Test that the export we have is the export we created. - export_dict = result.json()["exports"] + export_dict = response_dict["exports"] self.assertEqual(export_dict[0]["id"], audit_log_entry.id) self.assertEqual( export_dict[0]["export_url"], @@ -144,10 +144,10 @@ class RealmExportTest(ZulipTestCase): self.assert_streaming_content(response, b"zulip!") result = self.client_get("/json/export/realm") - self.assert_json_success(result) + response_dict = self.assert_json_success(result) # Test that the export we have is the export we created. - export_dict = result.json()["exports"] + export_dict = response_dict["exports"] self.assertEqual(export_dict[0]["id"], audit_log_entry.id) self.assertEqual(export_dict[0]["export_url"], admin.realm.uri + export_path) self.assertEqual(export_dict[0]["acting_user_id"], admin.id) diff --git a/zerver/tests/test_realm_linkifiers.py b/zerver/tests/test_realm_linkifiers.py index 534163d850..b0b44cb29b 100644 --- a/zerver/tests/test_realm_linkifiers.py +++ b/zerver/tests/test_realm_linkifiers.py @@ -17,8 +17,7 @@ class RealmFilterTest(ZulipTestCase): self.assert_json_success(result) result = self.client_get("/json/realm/linkifiers") - self.assert_json_success(result) - linkifiers = result.json()["linkifiers"] + linkifiers = self.assert_json_success(result)["linkifiers"] self.assert_length(linkifiers, 1) self.assertEqual(linkifiers[0]["pattern"], "#(?P