def test_list_webhooks_filter(self, requests_mock): response_mock = Mock() response_mock.status_code = 200 response_mock.content = json.dumps([ { 'id': 47 }, ]) requests_mock.get.return_value = response_mock cli = APIClient('test_api_key', 'test user agent') w = WebhookResource(cli, '46') res = w.list(filters={'since_id': 47}, fields='id') self.assertEqual(bunchify([ { 'id': 47 }, ]), res) requests_mock.get.assert_called_with( url='https://api.tiendanube.com/v1/46/webhooks', headers={ 'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent' }, params={ 'since_id': 47, 'fields': 'id' })
def test_update_webhook(self, requests_mock): response_mock = Mock() response_mock.status_code = 200 response_mock.text = json.dumps( {'id': 991, 'name': 'test web'}, ) requests_mock.put.return_value = response_mock cli = APIClient('test_api_key', 'test user agent') w = WebhookResource(cli, '46') w.update({'id': 991, 'name': 'test web updated'}) requests_mock.put.assert_called_with( url='https://api.tiendanube.com/v1/46/webhooks/991', headers={'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent', 'Content-Type': 'application/json; charset=utf-8'}, data=json.dumps({'id': 991, 'name': 'test web updated'}) )
def test_get_webhook(self, requests_mock): response_mock = Mock() response_mock.status_code = 200 response_mock.content = json.dumps({'id': 991, 'name': 'test prod'}) requests_mock.get.return_value = response_mock cli = APIClient('test_api_key', 'test user agent') w = WebhookResource(cli, '46') res = w.get(991) self.assertEqual(991, res.id) requests_mock.get.assert_called_with( url='https://api.tiendanube.com/v1/46/webhooks/991', headers={'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent'}, params=None )
def test_add_webhook(self, requests_mock): response_mock = Mock() response_mock.status_code = 201 response_mock.text = json.dumps( {'id': 46, 'name': 'test webhook'}, ) requests_mock.post.return_value = response_mock cli = APIClient('test_api_key', 'test user agent') w = WebhookResource(cli, '46') res = w.add({'id': 46, 'name': 'test webhook'}) self.assertEqual(bunchify( {'id': 46, 'name': 'test webhook'} ), res) requests_mock.post.assert_called_with( url='https://api.tiendanube.com/v1/46/webhooks', headers={'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent', 'Content-Type': 'application/json; charset=utf-8'}, data=json.dumps({'id': 46, 'name': 'test webhook'}) )
def test_list_webhooks_filter(self, requests_mock): response_mock = Mock() response_mock.status_code = 200 response_mock.content = json.dumps([ {'id': 47}, ]) requests_mock.get.return_value = response_mock cli = APIClient('test_api_key', 'test user agent') w = WebhookResource(cli, '46') res = w.list(filters={'since_id': 47}, fields='id') self.assertEqual(bunchify([ {'id': 47}, ]), res) requests_mock.get.assert_called_with( url='https://api.tiendanube.com/v1/46/webhooks', headers={'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent'}, params={'since_id': 47, 'fields': 'id'} )