Improve test coverage for Baremetrics bot.
This commit is contained in:
parent
67cdb6f8f0
commit
bffb8d0e16
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"request": {
|
||||||
|
"api_url": "https://api.baremetrics.com/v1/TEST/plans",
|
||||||
|
"headers": {
|
||||||
|
"Authorization": "Bearer TEST"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": {
|
||||||
|
"test": "TEST"
|
||||||
|
},
|
||||||
|
"response-headers": {
|
||||||
|
"X-TokenExpires": "0",
|
||||||
|
"Server": "cloudflare-nginx",
|
||||||
|
"X-RateLimit-Remaining": "3593",
|
||||||
|
"X-Powered-By": "Phusion Passenger 5.0.30",
|
||||||
|
"Set-Cookie": "__cfduid=dd26464e3e6779b6a05b27d2681aea0851514374567; expires=Thu, 27-Dec-18 11:36:07 GMT; path=/; domain=.baremetrics.com; HttpOnly; Secure, LSW_WEB=\"LSW_WEB1\"; path=/",
|
||||||
|
"X-Runtime": "0.031730",
|
||||||
|
"Access-Control-Allow-Credentials": "false",
|
||||||
|
"Access-Control-Allow-Methods": "GET, OPTIONS, POST, PUT, DELETE",
|
||||||
|
"Content-Encoding": "gzip",
|
||||||
|
"Connection": "keep-alive",
|
||||||
|
"ETag": "W/\"110de39b319ed195bf1414ac4f3c9a01\"",
|
||||||
|
"Date": "Wed, 27 Dec 2017 11:36:08 GMT",
|
||||||
|
"X-RateLimit-Limit": "3600",
|
||||||
|
"X-Version": "721",
|
||||||
|
"X-Commit": "2dcec7190a2bd01c8d3d8527d386486c4bb5474c",
|
||||||
|
"Status": "200 OK",
|
||||||
|
"Content-Type": "application/json; charset=utf-8",
|
||||||
|
"Transfer-Encoding": "chunked",
|
||||||
|
"Access-Control-Allow-Headers": "Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type",
|
||||||
|
"Cache-Control": "max-age=0, private, must-revalidate",
|
||||||
|
"X-Request-Id": "0b292131-81bb-4df2-bdb9-089a50b17e63",
|
||||||
|
"CF-RAY": "3d3bfaf6feee2eff-DEL"
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
from zulip_bots.test_lib import BotTestCase
|
from zulip_bots.test_lib import BotTestCase
|
||||||
|
from zulip_bots.test_lib import StubBotHandler
|
||||||
|
from zulip_bots.bots.baremetrics.baremetrics import BaremetricsHandler
|
||||||
|
|
||||||
class TestBaremetricsBot(BotTestCase):
|
class TestBaremetricsBot(BotTestCase):
|
||||||
bot_name = "baremetrics"
|
bot_name = "baremetrics"
|
||||||
|
@ -66,3 +68,26 @@ class TestBaremetricsBot(BotTestCase):
|
||||||
with self.mock_config_info({'api_key': 'TEST'}):
|
with self.mock_config_info({'api_key': 'TEST'}):
|
||||||
with self.mock_http_conversation('list_subscriptions'):
|
with self.mock_http_conversation('list_subscriptions'):
|
||||||
self.verify_reply('list-subscriptions TEST', r)
|
self.verify_reply('list-subscriptions TEST', r)
|
||||||
|
|
||||||
|
def test_exception_when_api_key_is_invalid(self)-> None:
|
||||||
|
bot_test_instance = BaremetricsHandler()
|
||||||
|
|
||||||
|
with self.mock_config_info({'api_key': 'TEST'}):
|
||||||
|
with self.assertRaises(StubBotHandler.BotQuitException):
|
||||||
|
bot_test_instance.initialize(StubBotHandler())
|
||||||
|
|
||||||
|
def test_invalid_command(self) -> None:
|
||||||
|
with self.mock_config_info({'api_key': 'TEST'}), \
|
||||||
|
patch('requests.get'):
|
||||||
|
self.verify_reply('abcd', 'Invalid Command.')
|
||||||
|
|
||||||
|
def test_missing_params(self) -> None:
|
||||||
|
with self.mock_config_info({'api_key': 'TEST'}), \
|
||||||
|
patch('requests.get'):
|
||||||
|
self.verify_reply('list-plans', 'Missing Params.')
|
||||||
|
|
||||||
|
def test_key_error(self) -> None:
|
||||||
|
with self.mock_config_info({'api_key': 'TEST'}), \
|
||||||
|
patch('requests.get'):
|
||||||
|
with self.mock_http_conversation('test_key_error'):
|
||||||
|
self.verify_reply('list-plans TEST', 'Invalid Response From API.')
|
||||||
|
|
Loading…
Reference in a new issue