Skip to content

Commit

Permalink
Merge pull request #5 from dave-shawley/support-url-kwarg
Browse files Browse the repository at this point in the history
Support url kwarg
  • Loading branch information
dave-shawley committed Jan 11, 2017
2 parents 4e75a3c + 39d938a commit e0d1955
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
8 changes: 7 additions & 1 deletion docs/index.rst
Expand Up @@ -16,6 +16,11 @@ Configuration Related
Release History
===============

`0.2.0`_ (10-Jan-2017)
----------------------
- Added ``url`` keyword to
:meth:`vetoes.service.HTTPServiceMixin.call_http_service`

`0.1.1`_ (06-Jan-2017)
----------------------
- Replaced readthedocs with pythonhosted.org.
Expand All @@ -26,6 +31,7 @@ Release History
:class:`vetoes.config.FeatureFlagMixin`, and
:class:`vetoes.config.TimeoutConfigurationMixin`

.. _Next Release: https://github.aweber.io/edeliv/vetoes/compare/0.1.1...HEAD
.. _Next Release: https://github.aweber.io/edeliv/vetoes/compare/0.2.0...HEAD
.. _0.2.0: https://github.aweber.io/edeliv/vetoes/compare/0.1.1...0.2.0
.. _0.1.1: https://github.aweber.io/edeliv/vetoes/compare/0.1.0...0.1.1
.. _0.1.0: https://github.aweber.io/edeliv/vetoes/compare/0.0.0...0.1.0
11 changes: 11 additions & 0 deletions tests/service_mixin_tests.py
Expand Up @@ -147,3 +147,14 @@ def test_that_raise_error_can_be_overridden(self):
self.consumer.get_service_url('fetch-stats'),
method='GET', raise_error=False)
self.assertIs(response, self.http_response)

@testing.gen_test
def test_that_url_kwarg_skips_service_lookup(self):
response = yield self.consumer.call_http_service(
'frobinicate', 'GET', url='https://google.com')

self.http.fetch.assert_called_once_with(
'https://google.com', method='GET', raise_error=False)
self.assertIs(response, self.http_response)
self.sentry_client.tags_context.assert_called_once_with(
{'service_invoked': 'frobinicate'})
2 changes: 1 addition & 1 deletion vetoes/__init__.py
@@ -1,2 +1,2 @@
version_info = (0, 1, 1)
version_info = (0, 2, 0)
version = '.'.join(str(v) for v in version_info)
13 changes: 10 additions & 3 deletions vetoes/service.py
Expand Up @@ -72,6 +72,8 @@ def call_http_service(self, function, method, *path, **kwargs):
:keyword bool raise_error: if this keyword is included and
set to :data:`False`, then HTTP errors will be returned
instead of raised as exceptions.
:keyword str url: if this keyword is included then it is used
as-is instead of doing a service lookup.
:param kwargs: additional keyword arguments are passed to
:meth:`tornado.httpclient.AsyncHTTPClient.fetch`.
Expand Down Expand Up @@ -99,10 +101,15 @@ def call_http_service(self, function, method, *path, **kwargs):
if headers:
kwargs['headers'] = headers

service = self.__service_map[function]
if 'url' in kwargs:
url = kwargs.pop('url')
service = function
else:
service = self.__service_map[function]
url = self.get_service_url(
service, *path, query_args=kwargs.pop('query_args', None))

self.sentry_client.tags_context({'service_invoked': service})
url = self.get_service_url(service, *path,
query_args=kwargs.pop('query_args', None))

self.logger.debug('sending %s request to %s', method, url)
raise_error = kwargs.pop('raise_error', True)
Expand Down

0 comments on commit e0d1955

Please sign in to comment.