Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_identifiers.py
# Copyright (C) 2018 The Software Heritage developers | # Copyright (C) 2018 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
# flake8: noqa | # flake8: noqa | ||||
from unittest.mock import patch | from unittest.mock import patch | ||||
from nose.tools import istest | |||||
from swh.web.common.exc import BadInputExc | from swh.web.common.exc import BadInputExc | ||||
from swh.web.common.utils import reverse | from swh.web.common.utils import reverse | ||||
from swh.web.tests.testcase import SWHWebTestCase | from swh.web.tests.testcase import SWHWebTestCase | ||||
from .data.content_test_data import stub_content_text_data | from .data.content_test_data import stub_content_text_data | ||||
from .data.directory_test_data import stub_root_directory_sha1 | from .data.directory_test_data import stub_root_directory_sha1 | ||||
from .data.revision_test_data import revision_id_test | from .data.revision_test_data import revision_id_test | ||||
from .data.release_test_data import stub_release | from .data.release_test_data import stub_release | ||||
swh_id_prefix = 'swh:1:' | swh_id_prefix = 'swh:1:' | ||||
class SwhBrowseIdTest(SWHWebTestCase): | class SwhBrowseIdTest(SWHWebTestCase): | ||||
@istest | def test_content_id_browse(self): | ||||
def content_id_browse(self): | |||||
cnt_sha1_git = stub_content_text_data['checksums']['sha1_git'] | cnt_sha1_git = stub_content_text_data['checksums']['sha1_git'] | ||||
swh_id = swh_id_prefix + 'cnt:' + cnt_sha1_git | swh_id = swh_id_prefix + 'cnt:' + cnt_sha1_git | ||||
url = reverse('browse-swh-id', | url = reverse('browse-swh-id', | ||||
kwargs={'swh_id': swh_id}) | kwargs={'swh_id': swh_id}) | ||||
query_string = 'sha1_git:' + cnt_sha1_git | query_string = 'sha1_git:' + cnt_sha1_git | ||||
content_browse_url = reverse('browse-content', | content_browse_url = reverse('browse-content', | ||||
kwargs={'query_string': query_string}) | kwargs={'query_string': query_string}) | ||||
resp = self.client.get(url) | resp = self.client.get(url) | ||||
self.assertEquals(resp.status_code, 302) | self.assertEquals(resp.status_code, 302) | ||||
self.assertEqual(resp['location'], content_browse_url) | self.assertEqual(resp['location'], content_browse_url) | ||||
@istest | def test_directory_id_browse(self): | ||||
def directory_id_browse(self): | |||||
swh_id = swh_id_prefix + 'dir:' + stub_root_directory_sha1 | swh_id = swh_id_prefix + 'dir:' + stub_root_directory_sha1 | ||||
url = reverse('browse-swh-id', | url = reverse('browse-swh-id', | ||||
kwargs={'swh_id': swh_id}) | kwargs={'swh_id': swh_id}) | ||||
directory_browse_url = reverse('browse-directory', | directory_browse_url = reverse('browse-directory', | ||||
kwargs={'sha1_git': stub_root_directory_sha1}) | kwargs={'sha1_git': stub_root_directory_sha1}) | ||||
resp = self.client.get(url) | resp = self.client.get(url) | ||||
self.assertEquals(resp.status_code, 302) | self.assertEquals(resp.status_code, 302) | ||||
self.assertEqual(resp['location'], directory_browse_url) | self.assertEqual(resp['location'], directory_browse_url) | ||||
@istest | def test_revision_id_browse(self): | ||||
def revision_id_browse(self): | |||||
swh_id = swh_id_prefix + 'rev:' + revision_id_test | swh_id = swh_id_prefix + 'rev:' + revision_id_test | ||||
url = reverse('browse-swh-id', | url = reverse('browse-swh-id', | ||||
kwargs={'swh_id': swh_id}) | kwargs={'swh_id': swh_id}) | ||||
revision_browse_url = reverse('browse-revision', | revision_browse_url = reverse('browse-revision', | ||||
kwargs={'sha1_git': revision_id_test}) | kwargs={'sha1_git': revision_id_test}) | ||||
resp = self.client.get(url) | resp = self.client.get(url) | ||||
Show All 11 Lines | def test_revision_id_browse(self): | ||||
revision_browse_url = reverse('browse-revision', | revision_browse_url = reverse('browse-revision', | ||||
kwargs={'sha1_git': revision_id_test}, | kwargs={'sha1_git': revision_id_test}, | ||||
query_params=query_params) | query_params=query_params) | ||||
resp = self.client.get(url) | resp = self.client.get(url) | ||||
self.assertEquals(resp.status_code, 302) | self.assertEquals(resp.status_code, 302) | ||||
self.assertEqual(resp['location'], revision_browse_url) | self.assertEqual(resp['location'], revision_browse_url) | ||||
@istest | def test_release_id_browse(self): | ||||
def release_id_browse(self): | |||||
swh_id = swh_id_prefix + 'rel:' + stub_release['id'] | swh_id = swh_id_prefix + 'rel:' + stub_release['id'] | ||||
url = reverse('browse-swh-id', | url = reverse('browse-swh-id', | ||||
kwargs={'swh_id': swh_id}) | kwargs={'swh_id': swh_id}) | ||||
release_browse_url = reverse('browse-release', | release_browse_url = reverse('browse-release', | ||||
kwargs={'sha1_git': stub_release['id']}) | kwargs={'sha1_git': stub_release['id']}) | ||||
resp = self.client.get(url) | resp = self.client.get(url) | ||||
Show All 11 Lines | def test_release_id_browse(self): | ||||
release_browse_url = reverse('browse-release', | release_browse_url = reverse('browse-release', | ||||
kwargs={'sha1_git': stub_release['id']}, | kwargs={'sha1_git': stub_release['id']}, | ||||
query_params=query_params) | query_params=query_params) | ||||
resp = self.client.get(url) | resp = self.client.get(url) | ||||
self.assertEquals(resp.status_code, 302) | self.assertEquals(resp.status_code, 302) | ||||
self.assertEqual(resp['location'], release_browse_url) | self.assertEqual(resp['location'], release_browse_url) | ||||
@istest | def test_bad_id_browse(self): | ||||
def bad_id_browse(self): | |||||
swh_id = swh_id_prefix + 'foo:' + stub_release['id'] | swh_id = swh_id_prefix + 'foo:' + stub_release['id'] | ||||
url = reverse('browse-swh-id', | url = reverse('browse-swh-id', | ||||
kwargs={'swh_id': swh_id}) | kwargs={'swh_id': swh_id}) | ||||
resp = self.client.get(url) | resp = self.client.get(url) | ||||
self.assertEquals(resp.status_code, 400) | self.assertEquals(resp.status_code, 400) | ||||
@istest | def test_content_id_optional_parts_browse(self): | ||||
def content_id_optional_parts_browse(self): | |||||
cnt_sha1_git = stub_content_text_data['checksums']['sha1_git'] | cnt_sha1_git = stub_content_text_data['checksums']['sha1_git'] | ||||
optional_parts = ';lines=4-20;origin=https://github.com/user/repo' | optional_parts = ';lines=4-20;origin=https://github.com/user/repo' | ||||
swh_id = swh_id_prefix + 'cnt:' + cnt_sha1_git + optional_parts | swh_id = swh_id_prefix + 'cnt:' + cnt_sha1_git + optional_parts | ||||
url = reverse('browse-swh-id', | url = reverse('browse-swh-id', | ||||
kwargs={'swh_id': swh_id}) | kwargs={'swh_id': swh_id}) | ||||
query_string = 'sha1_git:' + cnt_sha1_git | query_string = 'sha1_git:' + cnt_sha1_git | ||||
content_browse_url = reverse('browse-content', | content_browse_url = reverse('browse-content', | ||||
Show All 9 Lines |