|
| 1 | +import unittest |
| 2 | + |
| 3 | +from mock import sentinel, patch, MagicMock |
| 4 | + |
| 5 | +from ubersmith_client.ubersmith_request_get import UbersmithRequestGet |
| 6 | +from ubersmith_client.ubersmith_request_post import UbersmithRequestPost |
| 7 | + |
| 8 | + |
| 9 | +class UbersmithRequestFormEncodingTest(unittest.TestCase): |
| 10 | + def setUp(self): |
| 11 | + self.ubersmith_constructor_params = (sentinel.url, sentinel.username, sentinel.password, |
| 12 | + sentinel.module, sentinel.timeout) |
| 13 | + self._standard_kwargs = dict(auth=(sentinel.username, sentinel.password), |
| 14 | + timeout=sentinel.timeout, |
| 15 | + url=sentinel.url) |
| 16 | + |
| 17 | + @patch('ubersmith_client.ubersmith_request_get.requests') |
| 18 | + def test_get_with_list(self, request_mock): |
| 19 | + request_mock.get.return_value = MagicMock(status_code=200) |
| 20 | + |
| 21 | + self.client = UbersmithRequestGet(*self.ubersmith_constructor_params) |
| 22 | + self.client.call(test=['a']) |
| 23 | + |
| 24 | + expected_args = self._standard_kwargs |
| 25 | + expected_args.update(dict(params={ |
| 26 | + 'method': 'sentinel.module.call', |
| 27 | + 'test[0]': 'a', |
| 28 | + })) |
| 29 | + request_mock.get.assert_called_with(**expected_args) |
| 30 | + |
| 31 | + @patch('ubersmith_client.ubersmith_request_post.requests') |
| 32 | + def test_post_with_list(self, request_mock): |
| 33 | + request_mock.post.return_value = MagicMock(status_code=200) |
| 34 | + |
| 35 | + self.client = UbersmithRequestPost(*self.ubersmith_constructor_params) |
| 36 | + self.client.call(test=['a']) |
| 37 | + |
| 38 | + expected_args = self._standard_kwargs |
| 39 | + expected_args.update(dict(data={ |
| 40 | + 'method': 'sentinel.module.call', |
| 41 | + 'test[0]': 'a', |
| 42 | + })) |
| 43 | + request_mock.post.assert_called_with(**expected_args) |
0 commit comments