Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
test_bots: Combine invalid incoming webhook bot creation tests.
Niloth P0e2f387149bc
diff --git a/zerver/tests/test_bots.py b/zerver/tests/test_bots.pyindex c741a759fe9..5b9a65b0b3e 100644--- a/zerver/tests/test_bots.py+++ b/zerver/tests/test_bots.py@@ -2248,39 +2248,6 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):config_data = get_bot_config(new_bot)self.assertEqual(config_data, {"integration_id": "helloworld"})- @patch("zerver.lib.integrations.INCOMING_WEBHOOK_INTEGRATIONS", test_sample_config_options)- def test_create_incoming_webhook_bot_with_service_name_incorrect_keys(self) -> None:- self.login("hamlet")- bot_metadata = {- "full_name": "My Stripe Bot",- "short_name": "my-stripe",- "bot_type": UserProfile.INCOMING_WEBHOOK_BOT,- "service_name": "stripe",- "config_data": orjson.dumps({"stripe_api_key": "_invalid_key"}).decode(),- }- response = self.client_post("/json/bots", bot_metadata)- self.assertEqual(response.status_code, 400)- expected_error_message = 'Invalid stripe_api_key value _invalid_key (stripe_api_key starts with a "_" and is hence invalid.)'- self.assertEqual(orjson.loads(response.content)["msg"], expected_error_message)- with self.assertRaises(UserProfile.DoesNotExist):- UserProfile.objects.get(full_name="My Stripe Bot")-- @patch("zerver.lib.integrations.INCOMING_WEBHOOK_INTEGRATIONS", test_sample_config_options)- def test_create_incoming_webhook_bot_with_service_name_without_keys(self) -> None:- self.login("hamlet")- bot_metadata = {- "full_name": "My Stripe Bot",- "short_name": "my-stripe",- "bot_type": UserProfile.INCOMING_WEBHOOK_BOT,- "service_name": "stripe",- }- response = self.client_post("/json/bots", bot_metadata)- self.assertEqual(response.status_code, 400)- expected_error_message = "Missing configuration parameters: {'stripe_api_key'}"- self.assertEqual(orjson.loads(response.content)["msg"], expected_error_message)- with self.assertRaises(UserProfile.DoesNotExist):- UserProfile.objects.get(full_name="My Stripe Bot")-@patch("zerver.lib.integrations.INCOMING_WEBHOOK_INTEGRATIONS", test_sample_config_options)def test_create_incoming_webhook_bot_without_service_name(self) -> None:self.login("hamlet")@@ -2295,20 +2262,26 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):get_bot_config(new_bot)@patch("zerver.lib.integrations.INCOMING_WEBHOOK_INTEGRATIONS", test_sample_config_options)- def test_create_incoming_webhook_bot_with_incorrect_service_name(self) -> None:- self.login("hamlet")- bot_metadata = {- "full_name": "My Stripe Bot",- "short_name": "my-stripe",- "bot_type": UserProfile.INCOMING_WEBHOOK_BOT,- "service_name": "stripes",- }- response = self.client_post("/json/bots", bot_metadata)- self.assertEqual(response.status_code, 400)- expected_error_message = "Invalid integration 'stripes'."- self.assertEqual(orjson.loads(response.content)["msg"], expected_error_message)- with self.assertRaises(UserProfile.DoesNotExist):- UserProfile.objects.get(full_name="My Stripe Bot")+ def test_create_incoming_webhook_bot_with_invalid_service(self) -> None:+ self.login("hamlet")+ for service_config, expected_error_message in [+ (+ {+ "service_name": "stripe",+ "config_data": orjson.dumps({"stripe_api_key": "_invalid_key"}).decode(),+ },+ 'Invalid stripe_api_key value _invalid_key (stripe_api_key starts with a "_" and is hence invalid.)',+ ),+ ({"service_name": "stripe"}, "Missing configuration parameters: {'stripe_api_key'}"),+ ({"service_name": "stripes"}, "Invalid integration 'stripes'."),+ ]:+ with self.subTest(expected_error_message):+ bot_info = self.bot_creation_info(+ bot_type=UserProfile.INCOMING_WEBHOOK_BOT, **service_config+ )+ result = self.client_post("/json/bots", bot_info)+ self.assert_json_error(result, expected_error_message)+ self.assert_num_bots_equal(0)def test_get_bot_api_key(self) -> None:self.login("hamlet")