|
| 1 | +from __future__ import absolute_import |
| 2 | +from __future__ import division |
| 3 | +from __future__ import print_function |
| 4 | +from __future__ import unicode_literals |
| 5 | + |
| 6 | +from unittest import TestCase |
| 7 | +from mock import Mock |
| 8 | +from mock import patch |
| 9 | + |
| 10 | +from pybutton.resources import Customers |
| 11 | + |
| 12 | +config = { |
| 13 | + 'hostname': 'api.usebutton.com', |
| 14 | + 'secure': True, |
| 15 | + 'port': 443, |
| 16 | + 'timeout': None, |
| 17 | +} |
| 18 | + |
| 19 | + |
| 20 | +class CustomersTestCase(TestCase): |
| 21 | + |
| 22 | + def test_path(self): |
| 23 | + customer = Customers('sk-XXX', config) |
| 24 | + self.assertEqual(customer._path(), '/v1/customers') |
| 25 | + self.assertEqual( |
| 26 | + customer._path('customer-1'), |
| 27 | + '/v1/customers/customer-1' |
| 28 | + ) |
| 29 | + |
| 30 | + def test_get(self): |
| 31 | + customer = Customers('sk-XXX', config) |
| 32 | + customer_response = {'a': 1} |
| 33 | + |
| 34 | + api_get = Mock() |
| 35 | + api_get.return_value = customer_response |
| 36 | + |
| 37 | + with patch.object(customer, 'api_get', api_get): |
| 38 | + response = customer.get('customer-XXX') |
| 39 | + |
| 40 | + self.assertEqual(response, customer_response) |
| 41 | + api_get.assert_called_with('/v1/customers/customer-XXX') |
| 42 | + |
| 43 | + def test_create(self): |
| 44 | + customer = Customers('sk-XXX', config) |
| 45 | + customer_payload = {'b': 2} |
| 46 | + customer_response = {'a': 1} |
| 47 | + |
| 48 | + api_post = Mock() |
| 49 | + api_post.return_value = customer_response |
| 50 | + |
| 51 | + with patch.object(customer, 'api_post', api_post): |
| 52 | + response = customer.create(customer_payload) |
| 53 | + |
| 54 | + self.assertEqual(response, customer_response) |
| 55 | + api_post.assert_called_with('/v1/customers', customer_payload) |
0 commit comments