zulip_bots: Add test for create-plan
command of Baremetrics bot.
This commit is contained in:
parent
94f82dfe4c
commit
2f429fcb86
|
@ -2,7 +2,6 @@
|
|||
|
||||
from typing import Any, List
|
||||
import requests
|
||||
import logging
|
||||
|
||||
class BaremetricsHandler(object):
|
||||
def initialize(self, bot_handler: Any) -> None:
|
||||
|
@ -13,11 +12,14 @@ class BaremetricsHandler(object):
|
|||
'Authorization': 'Bearer ' + self.api_key
|
||||
}
|
||||
|
||||
self.commands = ['help', 'list-commands', 'account-info', 'list-sources', 'list-plans <source_id>',
|
||||
'list-customers <source_id>', 'list-subscriptions <source_id>', 'create-plan <source_id> '
|
||||
'<oid> <name> <currency> '
|
||||
'<amount> <interval> '
|
||||
'<interval_count>']
|
||||
self.commands = ['help',
|
||||
'list-commands',
|
||||
'account-info',
|
||||
'list-sources',
|
||||
'list-plans <source_id>',
|
||||
'list-customers <source_id>',
|
||||
'list-subscriptions <source_id>',
|
||||
'create-plan <source_id> <oid> <name> <currency> <amount> <interval> <interval_count>']
|
||||
|
||||
self.descriptions = ['Display bot info', 'Display the list of available commands', 'Display the account info',
|
||||
'List the sources', 'List the plans for the source', 'List the customers in the source',
|
||||
|
@ -199,7 +201,7 @@ class BaremetricsHandler(object):
|
|||
'amount': int(parameters[4]),
|
||||
'interval': parameters[5],
|
||||
'interval_count': int(parameters[6])
|
||||
}
|
||||
} # type: Any
|
||||
|
||||
url = 'https://api.baremetrics.com/v1/{}/plans'.format(parameters[0])
|
||||
create_plan_response = requests.post(url, data=data_header, headers=self.auth_header)
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
{
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"api_url": "https://api.baremetrics.com/v1/TEST/plans",
|
||||
"headers": {
|
||||
"Authorization": "Bearer TEST"
|
||||
},
|
||||
"data": {
|
||||
"oid": "1",
|
||||
"name": "TEST",
|
||||
"currency": "USD",
|
||||
"amount": 123,
|
||||
"interval": "TEST",
|
||||
"interval_count": 123
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"plan": {
|
||||
"oid": "1",
|
||||
"source_id": "TEST",
|
||||
"source": "TEST",
|
||||
"name": "TEST",
|
||||
"interval": "TEST",
|
||||
"interval_count": 123,
|
||||
"trial_duration": null,
|
||||
"trial_duration_unit": null,
|
||||
"created": null,
|
||||
"active": true,
|
||||
"setup_fees": 0,
|
||||
"amounts": [
|
||||
{
|
||||
"currency": "USD",
|
||||
"symbol": "$",
|
||||
"symbol_right": false,
|
||||
"amount": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"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"
|
||||
}
|
||||
}
|
|
@ -24,12 +24,17 @@ class TestBaremetricsBot(BotTestCase):
|
|||
def test_list_commands_command(self) -> None:
|
||||
with self.mock_config_info({'api_key': 'TEST'}), \
|
||||
patch('requests.get'):
|
||||
self.verify_reply('list-commands', '**Available Commands:** \n - help : Display bot info\n - list-commands '
|
||||
': Display the list of available commands\n - account-info : Display '
|
||||
'the account info\n - list-sources : List the sources\n - list-plans '
|
||||
'<source_id> : List the plans for the source\n - list-customers '
|
||||
'<source_id> : List the customers in the source\n - list-subscriptions '
|
||||
'<source_id> : List the subscriptions in the source\n')
|
||||
self.verify_reply('list-commands', '**Available Commands:** \n'
|
||||
' - help : Display bot info\n'
|
||||
' - list-commands : Display the list of available commands\n'
|
||||
' - account-info : Display the account info\n'
|
||||
' - list-sources : List the sources\n'
|
||||
' - list-plans <source_id> : List the plans for the source\n'
|
||||
' - list-customers <source_id> : List the customers in the source\n'
|
||||
' - list-subscriptions <source_id> : List the subscriptions in the '
|
||||
'source\n'
|
||||
' - create-plan <source_id> <oid> <name> <currency> <amount> <interval> '
|
||||
'<interval_count> : Create a plan in the given source\n')
|
||||
|
||||
def test_account_info_command(self) -> None:
|
||||
with self.mock_config_info({'api_key': 'TEST'}):
|
||||
|
@ -91,3 +96,9 @@ class TestBaremetricsBot(BotTestCase):
|
|||
patch('requests.get'):
|
||||
with self.mock_http_conversation('test_key_error'):
|
||||
self.verify_reply('list-plans TEST', 'Invalid Response From API.')
|
||||
|
||||
def test_create_plan_command(self) -> None:
|
||||
with self.mock_config_info({'api_key': 'TEST'}), \
|
||||
patch('requests.get'):
|
||||
with self.mock_http_conversation('create_plan'):
|
||||
self.verify_reply('create-plan TEST 1 TEST USD 123 TEST 123', 'Plan Created.')
|
||||
|
|
Loading…
Reference in a new issue