tests: Update `assert_json_success` to check for ignored parameters.

Updates `assert_json_success` so that it checks for an array of
ignored parameters in the success response.
This commit is contained in:
Lauryn Menard 2022-08-25 18:31:21 +02:00 committed by Tim Abbott
parent b8197e06bc
commit 0f2472ed14
4 changed files with 18 additions and 18 deletions

View File

@ -1088,7 +1088,10 @@ Output:
self.assertEqual(result, data)
def assert_json_success(
self, result: Union["TestHttpResponse", HttpResponse]
self,
result: Union["TestHttpResponse", HttpResponse],
*,
ignored_parameters: Optional[List[str]] = None,
) -> Dict[str, Any]:
"""
Successful POSTs return a 200 and JSON of the form {"result": "success",
@ -1104,6 +1107,14 @@ Output:
# empty value.
self.assertIn("msg", json)
self.assertNotEqual(json["msg"], "Error parsing JSON in response!")
# Check ignored parameters.
if ignored_parameters is None:
self.assertNotIn("ignored_parameters_unsupported", json)
else:
self.assertIn("ignored_parameters_unsupported", json)
self.assert_length(json["ignored_parameters_unsupported"], len(ignored_parameters))
for param in ignored_parameters:
self.assertTrue(param in json["ignored_parameters_unsupported"])
return json
def get_json_error(self, result: "TestHttpResponse", status_code: int = 400) -> str:

View File

@ -1308,17 +1308,13 @@ class RealmAPITest(ZulipTestCase):
def test_ignored_parameters_in_realm_default_endpoint(self) -> None:
params = {"starred_message_counts": orjson.dumps(False).decode(), "emoji_set": "twitter"}
json_result = self.client_patch("/json/realm/user_settings_defaults", params)
self.assert_json_success(json_result)
result = self.client_patch("/json/realm/user_settings_defaults", params)
self.assert_json_success(result, ignored_parameters=["emoji_set"])
realm = get_realm("zulip")
realm_user_default = RealmUserDefault.objects.get(realm=realm)
self.assertEqual(realm_user_default.starred_message_counts, False)
result = orjson.loads(json_result.content)
self.assertIn("ignored_parameters_unsupported", result)
self.assertEqual(result["ignored_parameters_unsupported"], ["emoji_set"])
def test_update_realm_move_messages_within_stream_limit_seconds_unlimited_value(self) -> None:
realm = get_realm("zulip")
self.login("iago")

View File

@ -455,12 +455,8 @@ class ChangeSettingsTest(ZulipTestCase):
self.login("hamlet")
# Now try an invalid setting name
json_result = self.client_patch("/json/settings", dict(invalid_setting="value"))
self.assert_json_success(json_result)
result = orjson.loads(json_result.content)
self.assertIn("ignored_parameters_unsupported", result)
self.assertEqual(result["ignored_parameters_unsupported"], ["invalid_setting"])
result = self.client_patch("/json/settings", dict(invalid_setting="value"))
self.assert_json_success(result, ignored_parameters=["invalid_setting"])
def test_changing_setting_using_display_setting_endpoint(self) -> None:
"""

View File

@ -3494,7 +3494,7 @@ class SubscriptionPropertiesTest(ZulipTestCase):
subs = gather_subscriptions(test_user)[0]
sub = subs[0]
json_result = self.api_post(
result = self.api_post(
test_user,
"/api/v1/users/me/subscriptions/properties",
{
@ -3513,10 +3513,7 @@ class SubscriptionPropertiesTest(ZulipTestCase):
},
)
self.assert_json_success(json_result)
result = orjson.loads(json_result.content)
self.assertIn("ignored_parameters_unsupported", result)
self.assertEqual(result["ignored_parameters_unsupported"], ["invalid_parameter"])
self.assert_json_success(result, ignored_parameters=["invalid_parameter"])
class SubscriptionRestApiTest(ZulipTestCase):