Skip to content

Commit

Permalink
Allow plugins to change whole url
Browse files Browse the repository at this point in the history
  • Loading branch information
alfred82santa committed Apr 29, 2016
1 parent 509cee5 commit 7f41a88
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions service_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,18 @@ def prepare_session(self, service_desc, request_params):
@coroutine
def generate_path(self, service_desc, session, request_params):
path = service_desc.get('path', '')
url = list(urlparse(self.base_path))
url[2] = '/'.join([url[2].rstrip('/'), path.lstrip('/')])
url.pop()
path = urlunsplit(url)
hooks = [getattr(plugin, 'prepare_path') for plugin in self._plugins
if hasattr(plugin, 'prepare_path')]
self.logger.debug("Calling {0} plugin hooks...".format('prepare_path'))
for func in hooks:
path = yield from func(service_desc=service_desc, session=session,
request_params=request_params, path=path)

path = path or ''
url = list(urlparse(self.base_path))
url[2] = '/'.join([url[2].rstrip('/'), path.lstrip('/')])
url.pop()
return urlunsplit(url)
return path

@coroutine
def prepare_request_params(self, service_desc, session, request_params):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name='aio-service-client',
url='https://github.com/alfred82santa/aio-service-client',
author='alfred82santa',
version='0.1.0',
version='0.1.1',
author_email='alfred82santa@gmail.com',
classifiers=[
'Intended Audience :: Developers',
Expand Down
8 changes: 4 additions & 4 deletions tests/tests_service_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_workflow_get(self):
'session': self.mock_session,
'request_params': {'method': 'GET',
'url': 'http://foo.com/sdsd/path/to/service1'},
'path': '/path/to/service1'})
'path': 'http://foo.com/sdsd/path/to/service1'})

self.assertIn('prepare_request_params', self.plugin.calls, "Prepare request params call")
self.assertEqual(self.plugin.calls['prepare_request_params']['args'], ())
Expand Down Expand Up @@ -228,7 +228,7 @@ def test_workflow_post(self):
'request_params': {'method': 'POST',
'url': 'http://foo.com/sdsd/path/to/service2',
'data': 'aaaa'},
'path': '/path/to/service2'})
'path': 'http://foo.com/sdsd/path/to/service2'})

self.assertIn('prepare_request_params', self.plugin.calls, "Prepare request params call")
self.assertEqual(self.plugin.calls['prepare_request_params']['args'], ())
Expand Down Expand Up @@ -336,7 +336,7 @@ def request(*args, **kwargs):
'request_params': {'method': 'POST',
'url': 'http://foo.com/sdsd/path/to/service2',
'data': 'aaaa'},
'path': '/path/to/service2'})
'path': 'http://foo.com/sdsd/path/to/service2'})

self.assertIn('prepare_request_params', self.plugin.calls, "Prepare request params call")
self.assertEqual(self.plugin.calls['prepare_request_params']['args'], ())
Expand Down Expand Up @@ -428,7 +428,7 @@ def parse(data, *args, **kwargs):
'request_params': {'method': 'POST',
'url': 'http://foo.com/sdsd/path/to/service2',
'data': 'aaaa'},
'path': '/path/to/service2'})
'path': 'http://foo.com/sdsd/path/to/service2'})

self.assertIn('prepare_request_params', self.plugin.calls, "Prepare request params call")
self.assertEqual(self.plugin.calls['prepare_request_params']['args'], ())
Expand Down

0 comments on commit 7f41a88

Please sign in to comment.