diff options
author | Andy Doan <andy.doan@linaro.org> | 2015-07-31 09:52:03 -0500 |
---|---|---|
committer | Andy Doan <andy.doan@linaro.org> | 2015-07-31 09:52:03 -0500 |
commit | a16b5d76e6a37f1ddc945c12389a4c29a5226bca (patch) | |
tree | a3a00561443f11a5a15d437460e5fcd090a2ca6a | |
parent | 65cd78e65b1bfb7836f170bc3b4af58a02a5b075 (diff) | |
download | linaro-license-protection-2015.07.1.tar.gz |
bug #1732: fix parent directory link2015.07.1
The previous commit, 65cd78e65b1bfb7836f170bc3b4af58a02a5b075, broke a
fragile assumption made on parent directory logic.
Ultimately we should probably think look around the code base and see if
we might be in need of some utility functions to help with this class of
problems.
Change-Id: Id2e22502fb6319596b20b9b2f693bdfa91f15f2b
-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 |