Skip to content

Commit

Permalink
Improve coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Koen Van Daele committed Sep 27, 2015
1 parent f04f57a commit 9249d4f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ def handlerconfig():
'match': '^/bar/(?P<name>\w+)$',
'redirect': 'http://localhost:5555/bar/{name}'
} , {
'match': '^urn:x-barbar:(?P<namespace>:\w+):(?P<id>\d+)$',
'match': '^urn:x-barbar:(?P<namespace>\w+):(?P<id>\d+)$',
'mount': False,
'redirect': 'http://localhost:2222/{namespace}/{id}'
}, {
'match': 'override/(?P<namespace>\w+)/(?P<id>\d+)$',
'redirect': 'http://localhost:2222/{namespace}/{id}'
}
]
}
Expand Down
6 changes: 6 additions & 0 deletions tests/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def test_mounted_redirect(self, urihandler):
res = urihandler.handle('http://test.urihandler.org/foobar/18', req)
assert res == 'http://localhost:5555/foobar/18'

def test_unanchored_redirect(self, urihandler):
req = testing.DummyRequest()
req.host_url = 'http://test.urihandler.org'
res = urihandler.handle('http://test.urihandler.org/something/override/me/987', req)
assert res == 'http://localhost:2222/me/987'


class MockRegistry:

Expand Down
1 change: 0 additions & 1 deletion urihandler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def main(global_config, **settings):
config.add_directive('get_uri_handler', get_uri_handler)
config.add_request_method(get_uri_handler, 'uri_handler', reify=True)

config.add_route('home', '/')
config.add_route('handle', '/handle')
config.add_route('redirect', '/{uri:.*}')

Expand Down
2 changes: 1 addition & 1 deletion urihandler/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def handle(self, uri, request):
if u['match'].startswith('^'):
u['match'] = u['match'].replace('^', '^' + request.host_url)
else:
u['match'] = request.host + '.*' + u['match']
u['match'] = request.host_url + '/.*' + u['match']
log.debug('Matching {0} to {1}.'.format(uri, u['match']))
m = re.match(u['match'], uri)
if m:
Expand Down
7 changes: 1 addition & 6 deletions urihandler/views.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
from pyramid.view import view_config

from pyramid.response import Response

from pyramid.httpexceptions import (
HTTPSeeOther,
HTTPBadRequest,
HTTPNotFound
)


@view_config(route_name='home')
def my_view(request):
return Response(request.host_url)

@view_config(route_name='redirect')
def redirect(request):
uri = request.host_url + '/' + request.matchdict['uri']
Expand All @@ -21,6 +15,7 @@ def redirect(request):
raise HTTPNotFound()
return HTTPSeeOther(redirect)


@view_config(route_name='handle')
def handle(request):
uri = request.params.get('uri', None)
Expand Down

0 comments on commit 9249d4f

Please sign in to comment.