diff options
Diffstat (limited to 'license_protected_downloads')
-rw-r--r-- | license_protected_downloads/tests/test_views.py | 11 | ||||
-rw-r--r-- | license_protected_downloads/views.py | 6 |
2 files changed, 17 insertions, 0 deletions
diff --git a/license_protected_downloads/tests/test_views.py b/license_protected_downloads/tests/test_views.py index c635609..0074595 100644 --- a/license_protected_downloads/tests/test_views.py +++ b/license_protected_downloads/tests/test_views.py @@ -353,6 +353,17 @@ class ViewTests(BaseServeViewTest): self.assertEqual(302, response.status_code) self.assertEqual(url + '/', response['Location']) + def test_parent_dir(self): + '''Ensure the listing has the correct parent directory link''' + url = 'http://testserver/~linaro-android/' + response = self.client.get(url) + self.assertEqual(200, response.status_code) + self.assertIn('"/">Parent Directory', response.content) + + url = 'http://testserver/~linaro-android/staging-panda/' + response = self.client.get(url, follow_redirect=True) + self.assertIn('"/~linaro-android/">Parent Directory', response.content) + def test_not_found_file(self): target_file = "12qwaszx" url = urlparse.urljoin("http://testserver/", target_file) diff --git a/license_protected_downloads/views.py b/license_protected_downloads/views.py index a8d5be5..e350e7e 100644 --- a/license_protected_downloads/views.py +++ b/license_protected_downloads/views.py @@ -160,7 +160,13 @@ def _handle_dir_list(request, artifact): # Generate a link to the parent directory (if one exists) url = artifact.url() if url != '/': + if url[-1] == '/': + # we must remove trailing slash to find parent + url = url[:-1] up_dir = os.path.split(url)[0] + if up_dir[-1] != '/': + # now we need the trailing slash + up_dir += '/' else: up_dir = None |