|
| 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 Links |
| 11 | + |
| 12 | +config = { |
| 13 | + 'hostname': 'api.usebutton.com', |
| 14 | + 'secure': True, |
| 15 | + 'port': 443, |
| 16 | + 'timeout': None, |
| 17 | +} |
| 18 | + |
| 19 | + |
| 20 | +class LinksTestCase(TestCase): |
| 21 | + |
| 22 | + def test_create(self): |
| 23 | + link = Links('https://test.com', config) |
| 24 | + link_payload = {'b': 2} |
| 25 | + link_response = {'a': 1} |
| 26 | + |
| 27 | + api_post = Mock() |
| 28 | + api_post.return_value = link_response |
| 29 | + |
| 30 | + with patch.object(link, 'api_post', api_post): |
| 31 | + response = link.create(link_payload) |
| 32 | + |
| 33 | + self.assertEqual(response, link_response) |
| 34 | + api_post.assert_called_with('/v1/links', link_payload) |
| 35 | + |
| 36 | + def test_get_info(self): |
| 37 | + link = Links('https://test.com', config) |
| 38 | + link_payload = {'b': 2} |
| 39 | + link_response = {'a': 1} |
| 40 | + |
| 41 | + api_post = Mock() |
| 42 | + api_post.return_value = link_response |
| 43 | + |
| 44 | + with patch.object(link, 'api_post', api_post): |
| 45 | + response = link.get_info(link_payload) |
| 46 | + |
| 47 | + self.assertEqual(response, link_response) |
| 48 | + api_post.assert_called_with('/v1/links/info', link_payload) |
0 commit comments