diff --git a/swh/web/api/views/directory.py b/swh/web/api/views/directory.py --- a/swh/web/api/views/directory.py +++ b/swh/web/api/views/directory.py @@ -10,8 +10,8 @@ from swh.web.api.views.utils import api_lookup -@api_route(r'/directory/(?P[0-9a-f]+)/', 'api-directory') -@api_route(r'/directory/(?P[0-9a-f]+)/(?P.+)/', +@api_route(r'/directory/(?P[0-9a-fA-F]+)/', 'api-directory') +@api_route(r'/directory/(?P[0-9a-fA-F]+)/(?P.+)/', 'api-directory') @api_doc('/directory/') def api_directory(request, sha1_git, path=None): @@ -60,6 +60,7 @@ :swh_web_api:`directory/977fc4b98c0e85816348cebd3b12026407c368b6/` """ # noqa + sha1_git = sha1_git.lower() if path: error_msg_path = ('Entry with path %s relative to directory ' 'with sha1_git %s not found.') % (path, sha1_git) diff --git a/swh/web/api/views/release.py b/swh/web/api/views/release.py --- a/swh/web/api/views/release.py +++ b/swh/web/api/views/release.py @@ -10,7 +10,7 @@ from swh.web.api.views.utils import api_lookup -@api_route(r'/release/(?P[0-9a-f]+)/', 'api-release') +@api_route(r'/release/(?P[0-9a-fA-F]+)/', 'api-release') @api_doc('/release/') def api_release(request, sha1_git): """ @@ -51,6 +51,7 @@ :swh_web_api:`release/208f61cc7a5dbc9879ae6e5c2f95891e270f09ef/` """ # noqa + sha1_git = sha1_git.lower() error_msg = 'Release with sha1_git %s not found.' % sha1_git return api_lookup( service.lookup_release, sha1_git, diff --git a/swh/web/api/views/snapshot.py b/swh/web/api/views/snapshot.py --- a/swh/web/api/views/snapshot.py +++ b/swh/web/api/views/snapshot.py @@ -12,7 +12,7 @@ from swh.web.api.views.utils import api_lookup -@api_route(r'/snapshot/(?P[0-9a-f]+)/', 'api-snapshot') +@api_route(r'/snapshot/(?P[0-9a-fA-F]+)/', 'api-snapshot') @api_doc('/snapshot/') def api_snapshot(request, snapshot_id): """ @@ -65,6 +65,7 @@ :swh_web_api:`snapshot/6a3a2cf0b2b90ce7ae1cf0a221ed68035b686f5a/` """ # noqa + snapshot_id = snapshot_id.lower() def _enrich_snapshot(snapshot): s = snapshot.copy() diff --git a/swh/web/browse/views/directory.py b/swh/web/browse/views/directory.py --- a/swh/web/browse/views/directory.py +++ b/swh/web/browse/views/directory.py @@ -21,8 +21,8 @@ from swh.web.browse.browseurls import browse_route -@browse_route(r'directory/(?P[0-9a-f]+)/', - r'directory/(?P[0-9a-f]+)/(?P.+)/', +@browse_route(r'directory/(?P[0-9a-fA-F]+)/', + r'directory/(?P[0-9a-fA-F]+)/(?P.+)/', view_name='browse-directory') def directory_browse(request, sha1_git, path=None): """Django view for browsing the content of a directory identified @@ -30,6 +30,7 @@ The url that points to it is :http:get:`/browse/directory/(sha1_git)/[(path)/]` """ # noqa + sha1_git = sha1_git.lower() root_sha1_git = sha1_git try: if path: diff --git a/swh/web/browse/views/release.py b/swh/web/browse/views/release.py --- a/swh/web/browse/views/release.py +++ b/swh/web/browse/views/release.py @@ -18,7 +18,7 @@ ) -@browse_route(r'release/(?P[0-9a-f]+)/', +@browse_route(r'release/(?P[0-9a-fA-F]+)/', view_name='browse-release') def release_browse(request, sha1_git): """ @@ -27,6 +27,7 @@ The url that points to it is :http:get:`/browse/release/(sha1_git)/`. """ + sha1_git = sha1_git.lower() try: release = service.lookup_release(sha1_git) snapshot_context = None diff --git a/swh/web/browse/views/snapshot.py b/swh/web/browse/views/snapshot.py --- a/swh/web/browse/views/snapshot.py +++ b/swh/web/browse/views/snapshot.py @@ -16,21 +16,22 @@ ) -@browse_route(r'snapshot/(?P[0-9a-f]+)/', +@browse_route(r'snapshot/(?P[0-9a-fA-F]+)/', view_name='browse-snapshot') def snapshot_browse(request, snapshot_id): """Django view for browsing the content of a snapshot. The url that points to it is :http:get:`/browse/snapshot/(snapshot_id)/` """ + snapshot_id = snapshot_id.lower() browse_snapshot_url = reverse('browse-snapshot-directory', url_args={'snapshot_id': snapshot_id}, query_params=request.GET) return redirect(browse_snapshot_url) -@browse_route(r'snapshot/(?P[0-9a-f]+)/directory/', - r'snapshot/(?P[0-9a-f]+)/directory/(?P.+)/', +@browse_route(r'snapshot/(?P[0-9a-fA-F]+)/directory/', + r'snapshot/(?P[0-9a-fA-F]+)/directory/(?P.+)/', # noqa view_name='browse-snapshot-directory') def snapshot_directory_browse(request, snapshot_id, path=None): """Django view for browsing the content of a directory collected @@ -38,6 +39,7 @@ The url that points to it is :http:get:`/browse/snapshot/(snapshot_id)/directory/[(path)/]` """ # noqa + snapshot_id = snapshot_id.lower() origin_type = request.GET.get('origin_type', None) origin_url = request.GET.get('origin_url', None) if not origin_url: @@ -47,7 +49,7 @@ origin_url=origin_url) -@browse_route(r'snapshot/(?P[0-9a-f]+)/content/(?P.+)/', +@browse_route(r'snapshot/(?P[0-9a-fA-F]+)/content/(?P.+)/', view_name='browse-snapshot-content') def snapshot_content_browse(request, snapshot_id, path): """Django view that produces an HTML display of a content @@ -55,10 +57,11 @@ The url that points to it is :http:get:`/browse/snapshot/(snapshot_id)/content/(path)/` """ # noqa + snapshot_id = snapshot_id.lower() return browse_snapshot_content(request, snapshot_id=snapshot_id, path=path) -@browse_route(r'snapshot/(?P[0-9a-f]+)/log/', +@browse_route(r'snapshot/(?P[0-9a-fA-F]+)/log/', view_name='browse-snapshot-log') def snapshot_log_browse(request, snapshot_id): """Django view that produces an HTML display of revisions history (aka @@ -66,10 +69,11 @@ The url that points to it is :http:get:`/browse/snapshot/(snapshot_id)/log/` """ # noqa + snapshot_id = snapshot_id.lower() return browse_snapshot_log(request, snapshot_id=snapshot_id) -@browse_route(r'snapshot/(?P[0-9a-f]+)/branches/', +@browse_route(r'snapshot/(?P[0-9a-fA-F]+)/branches/', view_name='browse-snapshot-branches') def snapshot_branches_browse(request, snapshot_id): """Django view that produces an HTML display of the list of releases @@ -77,10 +81,11 @@ The url that points to it is :http:get:`/browse/snapshot/(snapshot_id)/branches/` """ # noqa + snapshot_id = snapshot_id.lower() return browse_snapshot_branches(request, snapshot_id=snapshot_id) -@browse_route(r'snapshot/(?P[0-9a-f]+)/releases/', +@browse_route(r'snapshot/(?P[0-9a-fA-F]+)/releases/', view_name='browse-snapshot-releases') def snapshot_releases_browse(request, snapshot_id): """Django view that produces an HTML display of the list of releases @@ -88,4 +93,5 @@ The url that points to it is :http:get:`/browse/snapshot/(snapshot_id)/releases/` """ # noqa + snapshot_id = snapshot_id.lower() return browse_snapshot_releases(request, snapshot_id=snapshot_id) diff --git a/swh/web/tests/api/views/test_directory.py b/swh/web/tests/api/views/test_directory.py --- a/swh/web/tests/api/views/test_directory.py +++ b/swh/web/tests/api/views/test_directory.py @@ -29,6 +29,21 @@ self.assertEqual(rv.data, expected_data) + @given(directory()) + def test_api_directory_uppercase_sha1(self, directory): + + url = reverse('api-directory', url_args={ + 'sha1_git': directory.upper()}) + rv = self.client.get(url) + + self.assertEqual(rv.status_code, 200) + self.assertEqual(rv['Content-Type'], 'application/json') + + expected_data = list(map(self._enrich_dir_data, + self.directory_ls(directory))) + + self.assertEqual(rv.data, expected_data) + @given(unknown_directory()) def test_api_directory_not_found(self, unknown_directory): diff --git a/swh/web/tests/api/views/test_release.py b/swh/web/tests/api/views/test_release.py --- a/swh/web/tests/api/views/test_release.py +++ b/swh/web/tests/api/views/test_release.py @@ -38,6 +38,27 @@ self.assertEqual(rv['Content-Type'], 'application/json') self.assertEqual(rv.data, expected_release) + @given(release()) + def test_api_release_uppercase_sha1(self, release): + + url = reverse('api-release', url_args={'sha1_git': release.upper()}) + + rv = self.client.get(url) + + expected_release = self.release_get(release) + author_id = expected_release['author']['id'] + target_revision = expected_release['target'] + author_url = reverse('api-person', + url_args={'person_id': author_id}) + target_url = reverse('api-revision', + url_args={'sha1_git': target_revision}) + expected_release['author_url'] = author_url + expected_release['target_url'] = target_url + + self.assertEqual(rv.status_code, 200) + self.assertEqual(rv['Content-Type'], 'application/json') + self.assertEqual(rv.data, expected_release) + @given(sha1(), sha1(), sha1(), content(), directory(), release()) def test_api_release_target_type_not_a_revision(self, new_rel1, new_rel2, new_rel3, content, diff --git a/swh/web/tests/api/views/test_snapshot.py b/swh/web/tests/api/views/test_snapshot.py --- a/swh/web/tests/api/views/test_snapshot.py +++ b/swh/web/tests/api/views/test_snapshot.py @@ -114,6 +114,32 @@ self.assertEqual(rv['Content-Type'], 'application/json') self.assertEqual(rv.data, expected_data) + @given(snapshot()) + def test_api_snapshot_uppercase_sha1(self, snapshot): + snapshot_branches = [] + + for k, v in sorted(self.snapshot_get(snapshot)['branches'].items()): + snapshot_branches.append({ + 'name': k, + 'target_type': v['target_type'], + 'target': v['target'] + }) + + target_type = random.choice(snapshot_branches)['target_type'] + + url = reverse('api-snapshot', + url_args={'snapshot_id': snapshot.upper()}, + query_params={'target_types': target_type}) + rv = self.client.get(url) + + expected_data = self.snapshot_get_branches( + snapshot, target_types=target_type) + expected_data = self._enrich_snapshot(expected_data) + + self.assertEqual(rv.status_code, 200) + self.assertEqual(rv['Content-Type'], 'application/json') + self.assertEqual(rv.data, expected_data) + @given(unknown_snapshot()) def test_api_snapshot_errors(self, unknown_snapshot): diff --git a/swh/web/tests/browse/views/test_directory.py b/swh/web/tests/browse/views/test_directory.py --- a/swh/web/tests/browse/views/test_directory.py +++ b/swh/web/tests/browse/views/test_directory.py @@ -93,6 +93,15 @@ def test_root_directory_view(self, directory): self.directory_view(directory, self.directory_ls(directory)) + @given(directory()) + def test_directory_uppercase_sha1(self, directory): + url_args = {'sha1_git': directory.upper()} + url = reverse('browse-directory', + url_args=url_args) + resp = self.client.get(url) + + self.assertEqual(resp.status_code, 200) + @given(directory_with_subdirs()) def test_sub_directory_view(self, directory): dir_content = self.directory_ls(directory) diff --git a/swh/web/tests/browse/views/test_release.py b/swh/web/tests/browse/views/test_release.py --- a/swh/web/tests/browse/views/test_release.py +++ b/swh/web/tests/browse/views/test_release.py @@ -30,6 +30,18 @@ self._release_browse_checks(resp, release_data) + @given(release()) + def test_release_browse_with_uppercase_sha1(self, release): + + url = reverse('browse-release', + url_args={'sha1_git': release.upper()}) + + release_data = self.release_get(release) + + resp = self.client.get(url) + + self._release_browse_checks(resp, release_data) + @given(origin_with_release()) def test_release_browse_with_origin(self, origin): snapshot = self.snapshot_get_latest(origin['id'])