From 28120784ff52ed020ca040b88a2972f7ed719013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20H=C3=B6nig?= Date: Thu, 4 Jan 2018 15:12:07 +0100 Subject: [PATCH] google_translate bot: Add test for invalid api key. --- .../fixtures/test_invalid_api_key.json | 28 +++++++++++++++++++ .../google_translate/test_google_translate.py | 4 +++ 2 files changed, 32 insertions(+) create mode 100644 zulip_bots/zulip_bots/bots/google_translate/fixtures/test_invalid_api_key.json diff --git a/zulip_bots/zulip_bots/bots/google_translate/fixtures/test_invalid_api_key.json b/zulip_bots/zulip_bots/bots/google_translate/fixtures/test_invalid_api_key.json new file mode 100644 index 0000000..1d0d64b --- /dev/null +++ b/zulip_bots/zulip_bots/bots/google_translate/fixtures/test_invalid_api_key.json @@ -0,0 +1,28 @@ +{ + "request": { + "method": "GET", + "api_url": "https://translation.googleapis.com/language/translate/v2/languages", + "params": { + "key": "abcdefg", + "target": "en" + } + }, + "response": { + "error":{ + "status": "INVALID_ARGUMENT", + "message": "API key not valid. Please pass a valid API key.", + "code": 400, + "errors": [ + { + "domain":"global", + "message":"API key not valid. Please pass a valid API key.", + "reason":"badRequest" + } + ] + } + }, + "response-headers": { + "status": 400, + "content-type": "application/json; charset=utf-8" + } +} diff --git a/zulip_bots/zulip_bots/bots/google_translate/test_google_translate.py b/zulip_bots/zulip_bots/bots/google_translate/test_google_translate.py index fee52bf..b39997b 100644 --- a/zulip_bots/zulip_bots/bots/google_translate/test_google_translate.py +++ b/zulip_bots/zulip_bots/bots/google_translate/test_google_translate.py @@ -66,6 +66,10 @@ class TestGoogleTranslateBot(BotTestCase): side_effect=Exception): self._test('"hello" de', 'Error. .', 'test_languages') + def test_invalid_api_key(self): + with self.assertRaises(StubBotHandler.BotQuitException): + self._test(None, None, 'test_invalid_api_key') + def test_api_access_not_configured(self): with self.assertRaises(StubBotHandler.BotQuitException): self._test(None, None, 'test_api_access_not_configured')