|
| 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 import constants |
| 11 | +from pybutton.resources import Transactions |
| 12 | + |
| 13 | +config = { |
| 14 | + 'hostname': 'api.usebutton.com', |
| 15 | + 'secure': True, |
| 16 | + 'port': 443, |
| 17 | + 'timeout': None, |
| 18 | +} |
| 19 | + |
| 20 | + |
| 21 | +class TransactionsTestCase(TestCase): |
| 22 | + |
| 23 | + def test_all(self): |
| 24 | + transactions = Transactions('sk-XXX', config) |
| 25 | + transaction_response = [{'a': 1}, {'b': 2}] |
| 26 | + |
| 27 | + api_get = Mock() |
| 28 | + api_get.return_value = transaction_response |
| 29 | + |
| 30 | + with patch.object(transactions, 'api_get', api_get): |
| 31 | + response = transactions.all( |
| 32 | + cursor='abc', |
| 33 | + start='2016-09-15T00:00:00.000Z', |
| 34 | + end='2016-09-30T00:00:00.000Z' |
| 35 | + ) |
| 36 | + self.assertEqual( |
| 37 | + api_get.call_args[0][0], |
| 38 | + '/v1/affiliation/transactions' |
| 39 | + ) |
| 40 | + self.assertEqual(response, transaction_response) |
| 41 | + query = api_get.call_args[1]['query'] |
| 42 | + self.assertEqual(query['cursor'], 'abc') |
| 43 | + self.assertEqual(query['start'], '2016-09-15T00:00:00.000Z') |
| 44 | + self.assertEqual(query['end'], '2016-09-30T00:00:00.000Z') |
| 45 | + |
| 46 | + response = transactions.all( |
| 47 | + cursor='abc', |
| 48 | + start='2016-09-15T00:00:00.000Z', |
| 49 | + end='2016-09-30T00:00:00.000Z', |
| 50 | + time_field=constants.TIME_FIELD_MODIFIED |
| 51 | + ) |
| 52 | + self.assertEqual(response, transaction_response) |
| 53 | + query = api_get.call_args[1]['query'] |
| 54 | + self.assertEqual(query['time_field'], 'modified_date') |
0 commit comments