diff --git a/zulip_bots/zulip_bots/bots/front/fixtures/archive_error.json b/zulip_bots/zulip_bots/bots/front/fixtures/archive_error.json new file mode 100644 index 0000000..7833a20 --- /dev/null +++ b/zulip_bots/zulip_bots/bots/front/fixtures/archive_error.json @@ -0,0 +1,21 @@ +{ + "request": { + "method": "PATCH", + "api_url": "https://api2.frontapp.com/conversations/cnv_kqatm2", + "headers": { + "Authorization": "Bearer TEST" + }, + "json": { + "status": "archived" + } + }, + "response": { + "error": { + "title": "Unauthenticated", + "message": "Provided token is not a JSON Web Token" + } + }, + "response-headers": { + "status": 401 + } +} diff --git a/zulip_bots/zulip_bots/bots/front/fixtures/comment_error.json b/zulip_bots/zulip_bots/bots/front/fixtures/comment_error.json new file mode 100644 index 0000000..23ffa03 --- /dev/null +++ b/zulip_bots/zulip_bots/bots/front/fixtures/comment_error.json @@ -0,0 +1,22 @@ +{ + "request": { + "method": "POST", + "api_url": "https://api2.frontapp.com/conversations/cnv_kqatm2/comments", + "headers": { + "Authorization": "Bearer TEST" + }, + "json": { + "author_id": "alt:email:leela@planet-express.com", + "body": "@bender, I thought you were supposed to be cooking for this party." + } + }, + "response": { + "error": { + "title": "Unauthenticated", + "message": "Provided token is not a JSON Web Token" + } + }, + "response-headers": { + "status": 401 + } +} diff --git a/zulip_bots/zulip_bots/bots/front/fixtures/delete_error.json b/zulip_bots/zulip_bots/bots/front/fixtures/delete_error.json new file mode 100644 index 0000000..e726777 --- /dev/null +++ b/zulip_bots/zulip_bots/bots/front/fixtures/delete_error.json @@ -0,0 +1,21 @@ +{ + "request": { + "method": "PATCH", + "api_url": "https://api2.frontapp.com/conversations/cnv_kqatm2", + "headers": { + "Authorization": "Bearer TEST" + }, + "json": { + "status": "deleted" + } + }, + "response": { + "error": { + "title": "Unauthenticated", + "message": "Provided token is not a JSON Web Token" + } + }, + "response-headers": { + "status": 401 + } +} diff --git a/zulip_bots/zulip_bots/bots/front/fixtures/open_error.json b/zulip_bots/zulip_bots/bots/front/fixtures/open_error.json new file mode 100644 index 0000000..0bfcc2c --- /dev/null +++ b/zulip_bots/zulip_bots/bots/front/fixtures/open_error.json @@ -0,0 +1,21 @@ +{ + "request": { + "method": "PATCH", + "api_url": "https://api2.frontapp.com/conversations/cnv_kqatm2", + "headers": { + "Authorization": "Bearer TEST" + }, + "json": { + "status": "open" + } + }, + "response": { + "error": { + "title": "Unauthenticated", + "message": "Provided token is not a JSON Web Token" + } + }, + "response-headers": { + "status": 401 + } +} diff --git a/zulip_bots/zulip_bots/bots/front/fixtures/spam_error.json b/zulip_bots/zulip_bots/bots/front/fixtures/spam_error.json new file mode 100644 index 0000000..6b578d6 --- /dev/null +++ b/zulip_bots/zulip_bots/bots/front/fixtures/spam_error.json @@ -0,0 +1,21 @@ +{ + "request": { + "method": "PATCH", + "api_url": "https://api2.frontapp.com/conversations/cnv_kqatm2", + "headers": { + "Authorization": "Bearer TEST" + }, + "json": { + "status": "spam" + } + }, + "response": { + "error": { + "title": "Unauthenticated", + "message": "Provided token is not a JSON Web Token" + } + }, + "response-headers": { + "status": 401 + } +} diff --git a/zulip_bots/zulip_bots/bots/front/test_front.py b/zulip_bots/zulip_bots/bots/front/test_front.py index 4f8efa1..97c9c65 100644 --- a/zulip_bots/zulip_bots/bots/front/test_front.py +++ b/zulip_bots/zulip_bots/bots/front/test_front.py @@ -11,6 +11,12 @@ class TestFrontBot(BotTestCase, DefaultTests): message['sender_email'] = "leela@planet-express.com" return message + def test_bot_invalid_api_key(self) -> None: + invalid_api_key = '' + with self.mock_config_info({'api_key': invalid_api_key}): + with self.assertRaises(KeyError): + bot, bot_handler = self._get_handlers() + def test_bot_responds_to_empty_message(self) -> None: with self.mock_config_info({'api_key': "TEST"}): self.verify_reply("", "Unknown command. Use `help` for instructions.") @@ -28,27 +34,53 @@ class TestFrontBot(BotTestCase, DefaultTests): with self.mock_http_conversation('archive'): self.verify_reply('archive', "Conversation was archived.") + def test_archive_error(self) -> None: + with self.mock_config_info({'api_key': "TEST"}): + with self.mock_http_conversation('archive_error'): + self.verify_reply('archive', 'Something went wrong.') + def test_delete(self) -> None: with self.mock_config_info({'api_key': "TEST"}): with self.mock_http_conversation('delete'): self.verify_reply('delete', "Conversation was deleted.") + def test_delete_error(self) -> None: + with self.mock_config_info({'api_key': "TEST"}): + with self.mock_http_conversation('delete_error'): + self.verify_reply('delete', 'Something went wrong.') + def test_spam(self) -> None: with self.mock_config_info({'api_key': "TEST"}): with self.mock_http_conversation('spam'): self.verify_reply('spam', "Conversation was marked as spam.") + def test_spam_error(self) -> None: + with self.mock_config_info({'api_key': "TEST"}): + with self.mock_http_conversation('spam_error'): + self.verify_reply('spam', 'Something went wrong.') + def test_restore(self) -> None: with self.mock_config_info({'api_key': "TEST"}): with self.mock_http_conversation('open'): self.verify_reply('open', "Conversation was restored.") + def test_restore_error(self) -> None: + with self.mock_config_info({'api_key': "TEST"}): + with self.mock_http_conversation('open_error'): + self.verify_reply('open', 'Something went wrong.') + def test_comment(self) -> None: body = "@bender, I thought you were supposed to be cooking for this party." with self.mock_config_info({'api_key': "TEST"}): with self.mock_http_conversation('comment'): self.verify_reply("comment " + body, "Comment was sent.") + def test_comment_error(self) -> None: + body = "@bender, I thought you were supposed to be cooking for this party." + with self.mock_config_info({'api_key': "TEST"}): + with self.mock_http_conversation('comment_error'): + self.verify_reply('comment ' + body, 'Something went wrong.') + class TestFrontBotWrongTopic(BotTestCase, DefaultTests): bot_name = 'front'