Skip to content

Commit

Permalink
Send custom user agent (issue #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric Guillot committed Apr 18, 2017
1 parent ae8ed0b commit 9ffe346
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Ubersmith API Client for Python

Usage
-----

.. code:: python
import ubersmith_client
Expand All @@ -20,7 +21,7 @@ Usage
>>> 1265
API
---------
---

**ubersmith_client.api.init(url, user, password, timeout, use_http_get)**
:url:
Expand Down
3 changes: 2 additions & 1 deletion tests/ubersmith_request_form_encoding_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def setUp(self):
sentinel.module, sentinel.timeout)
self._standard_kwargs = dict(auth=(sentinel.username, sentinel.password),
timeout=sentinel.timeout,
url=sentinel.url)
url=sentinel.url,
headers={'user-agent': 'python-ubersmithclient'})

@patch('ubersmith_client.ubersmith_request_get.requests')
def test_get_with_list(self, request_mock):
Expand Down
3 changes: 2 additions & 1 deletion tests/ubersmith_request_get_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def expect_a_ubersmith_call(self, requests_mock, returning=None, **kwargs):
response.json = MagicMock(return_value=returning)

def assert_called_with():
requests_mock.get.assert_called_with(auth=self.auth, params=kwargs, timeout=self.timeout, url=self.url)
requests_mock.get.assert_called_with(auth=self.auth, params=kwargs, timeout=self.timeout, url=self.url,
headers={'user-agent': 'python-ubersmithclient'})
response.json.assert_called_with()

return assert_called_with
3 changes: 2 additions & 1 deletion tests/ubersmith_request_post_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def expect_a_ubersmith_call_post(self, requests_mock, returning=None, status_cod
response.json = MagicMock(return_value=returning)

def assert_called_with():
requests_mock.post.assert_called_with(auth=self.auth, timeout=self.timeout, url=self.url, data=kwargs)
requests_mock.post.assert_called_with(auth=self.auth, timeout=self.timeout, url=self.url, data=kwargs,
headers={'user-agent': 'python-ubersmithclient'})
response.json.assert_called_with()

return assert_called_with
1 change: 0 additions & 1 deletion ubersmith_client/ubersmith_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def __call__(self, **kwargs):
def _process_request(self, method, **kwargs):
try:
return method(**kwargs)

except ConnectionError:
raise exceptions.UbersmithConnectionError(self.url)
except Timeout:
Expand Down
1 change: 1 addition & 0 deletions ubersmith_client/ubersmith_request_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __call__(self, **kwargs):
url=self.url,
auth=(self.user, self.password),
timeout=self.timeout,
headers={'user-agent': 'python-ubersmithclient'},
params=params)

return UbersmithRequest.process_ubersmith_response(response)
1 change: 1 addition & 0 deletions ubersmith_client/ubersmith_request_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __call__(self, **kwargs):
url=self.url,
auth=(self.user, self.password),
timeout=self.timeout,
headers={'user-agent': 'python-ubersmithclient'},
data=params)

return UbersmithRequest.process_ubersmith_response(response)

0 comments on commit 9ffe346

Please sign in to comment.