|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 | 15 | import unittest
|
16 |
| - |
17 | 16 | from hamcrest import assert_that, equal_to, calling, raises
|
18 | 17 | from mock import patch, MagicMock
|
19 |
| -import ubersmith_client |
20 | 18 |
|
| 19 | +import ubersmith_client |
21 | 20 | from tests.ubersmith_json.response_data_structure import a_response_data
|
22 | 21 |
|
23 | 22 |
|
@@ -77,13 +76,46 @@ def test_api_raises_exception_with_if_data_status_is_false(self, requests_mock):
|
77 | 76 | self.expect_a_ubersmith_call_post(requests_mock, method='client.miss', returning=data)
|
78 | 77 | assert_that(calling(ubersmith_api.client.miss), raises(ubersmith_client.exceptions.UbersmithException))
|
79 | 78 |
|
80 |
| - def expect_a_ubersmith_call_post(self, requests_mock, returning=None, status_code=200, **kwargs): |
81 |
| - response = MagicMock(status_code=status_code, headers={'content-type': 'application/json'}) |
| 79 | + @patch('ubersmith_client.ubersmith_request_post.requests') |
| 80 | + def test_api_post_support_ticket_submit_allow_file_upload(self, request_mock): |
| 81 | + expected_files = {'attach[0]': ('filename.pdf', b'filecontent')} |
| 82 | + expected_call = self.expect_a_ubersmith_call_post_with_files(requests_mock=request_mock, |
| 83 | + method='support.ticket_submit', |
| 84 | + subject='that I use to know', |
| 85 | + body='some body', |
| 86 | + returning=a_response_data(data='42'), |
| 87 | + files=expected_files) |
| 88 | + |
| 89 | + ubersmith_api = ubersmith_client.api.init(self.url, self.username, self.password) |
| 90 | + |
| 91 | + response = ubersmith_api.support.ticket_submit(subject='that I use to know', |
| 92 | + body='some body', |
| 93 | + files=expected_files) |
| 94 | + |
| 95 | + assert_that(response, equal_to('42')) |
| 96 | + |
| 97 | + expected_call() |
| 98 | + |
| 99 | + def expect_a_ubersmith_call_post(self, requests_mock, returning=None, **kwargs): |
| 100 | + response = MagicMock(status_code=200, headers={'content-type': 'application/json'}) |
| 101 | + requests_mock.post = MagicMock(return_value=response) |
| 102 | + response.json = MagicMock(return_value=returning) |
| 103 | + |
| 104 | + def assert_called_with(): |
| 105 | + requests_mock.post.assert_called_with(auth=self.auth, timeout=self.timeout, url=self.url, data=kwargs, |
| 106 | + headers={'user-agent': 'python-ubersmithclient'}) |
| 107 | + response.json.assert_called_with() |
| 108 | + |
| 109 | + return assert_called_with |
| 110 | + |
| 111 | + def expect_a_ubersmith_call_post_with_files(self, requests_mock, returning=None, files=None, **kwargs): |
| 112 | + response = MagicMock(status_code=200, headers={'content-type': 'application/json'}) |
82 | 113 | requests_mock.post = MagicMock(return_value=response)
|
83 | 114 | response.json = MagicMock(return_value=returning)
|
84 | 115 |
|
85 | 116 | def assert_called_with():
|
86 | 117 | requests_mock.post.assert_called_with(auth=self.auth, timeout=self.timeout, url=self.url, data=kwargs,
|
| 118 | + files=files, |
87 | 119 | headers={'user-agent': 'python-ubersmithclient'})
|
88 | 120 | response.json.assert_called_with()
|
89 | 121 |
|
|
0 commit comments