Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_directory.py
# Copyright (C) 2017-2018 The Software Heritage developers | # Copyright (C) 2017-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 | ||||
from unittest.mock import patch | from unittest.mock import patch | ||||
from nose.tools import istest, nottest | |||||
from swh.web.common.exc import BadInputExc, NotFoundExc | from swh.web.common.exc import BadInputExc, NotFoundExc | ||||
from swh.web.common.utils import reverse, get_swh_persistent_id | from swh.web.common.utils import reverse, get_swh_persistent_id | ||||
from swh.web.common.utils import gen_path_info | from swh.web.common.utils import gen_path_info | ||||
from swh.web.tests.testcase import SWHWebTestCase | from swh.web.tests.testcase import SWHWebTestCase | ||||
from .data.directory_test_data import ( | from .data.directory_test_data import ( | ||||
stub_root_directory_sha1, stub_root_directory_data, | stub_root_directory_sha1, stub_root_directory_data, | ||||
stub_sub_directory_path, stub_sub_directory_data | stub_sub_directory_path, stub_sub_directory_data | ||||
) | ) | ||||
class SwhBrowseDirectoryTest(SWHWebTestCase): | class SwhBrowseDirectoryTest(SWHWebTestCase): | ||||
@nottest | |||||
def directory_view(self, root_directory_sha1, directory_entries, | def directory_view(self, root_directory_sha1, directory_entries, | ||||
path=None): | path=None): | ||||
dirs = [e for e in directory_entries if e['type'] in ('dir', 'rev')] | dirs = [e for e in directory_entries if e['type'] in ('dir', 'rev')] | ||||
files = [e for e in directory_entries if e['type'] == 'file'] | files = [e for e in directory_entries if e['type'] == 'file'] | ||||
url_args = {'sha1_git': root_directory_sha1} | url_args = {'sha1_git': root_directory_sha1} | ||||
if path: | if path: | ||||
url_args['path'] = path | url_args['path'] = path | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | def directory_view(self, root_directory_sha1, directory_entries, | ||||
swh_dir_id = get_swh_persistent_id('directory', directory_entries[0]['dir_id']) # noqa | swh_dir_id = get_swh_persistent_id('directory', directory_entries[0]['dir_id']) # noqa | ||||
swh_dir_id_url = reverse('browse-swh-id', | swh_dir_id_url = reverse('browse-swh-id', | ||||
kwargs={'swh_id': swh_dir_id}) | kwargs={'swh_id': swh_dir_id}) | ||||
self.assertContains(resp, swh_dir_id) | self.assertContains(resp, swh_dir_id) | ||||
self.assertContains(resp, swh_dir_id_url) | self.assertContains(resp, swh_dir_id_url) | ||||
@patch('swh.web.browse.utils.service') | @patch('swh.web.browse.utils.service') | ||||
@istest | def test_root_directory_view(self, mock_service): | ||||
def root_directory_view(self, mock_service): | |||||
mock_service.lookup_directory.return_value = \ | mock_service.lookup_directory.return_value = \ | ||||
stub_root_directory_data | stub_root_directory_data | ||||
self.directory_view(stub_root_directory_sha1, stub_root_directory_data) | self.directory_view(stub_root_directory_sha1, stub_root_directory_data) | ||||
@patch('swh.web.browse.utils.service') | @patch('swh.web.browse.utils.service') | ||||
@patch('swh.web.browse.views.directory.service') | @patch('swh.web.browse.views.directory.service') | ||||
@istest | def test_sub_directory_view(self, mock_directory_service, | ||||
def sub_directory_view(self, mock_directory_service, mock_utils_service): | mock_utils_service): | ||||
mock_utils_service.lookup_directory.return_value = \ | mock_utils_service.lookup_directory.return_value = \ | ||||
stub_sub_directory_data | stub_sub_directory_data | ||||
mock_directory_service.lookup_directory_with_path.return_value = \ | mock_directory_service.lookup_directory_with_path.return_value = \ | ||||
{'target': stub_sub_directory_data[0]['dir_id'], | {'target': stub_sub_directory_data[0]['dir_id'], | ||||
'type': 'dir'} | 'type': 'dir'} | ||||
self.directory_view(stub_root_directory_sha1, stub_sub_directory_data, | self.directory_view(stub_root_directory_sha1, stub_sub_directory_data, | ||||
stub_sub_directory_path) | stub_sub_directory_path) | ||||
@patch('swh.web.browse.utils.service') | @patch('swh.web.browse.utils.service') | ||||
@patch('swh.web.browse.views.directory.service') | @patch('swh.web.browse.views.directory.service') | ||||
@istest | def test_directory_request_errors(self, mock_directory_service, | ||||
def directory_request_errors(self, mock_directory_service, | |||||
mock_utils_service): | mock_utils_service): | ||||
mock_utils_service.lookup_directory.side_effect = \ | mock_utils_service.lookup_directory.side_effect = \ | ||||
BadInputExc('directory not found') | BadInputExc('directory not found') | ||||
dir_url = reverse('browse-directory', | dir_url = reverse('browse-directory', | ||||
kwargs={'sha1_git': '1253456'}) | kwargs={'sha1_git': '1253456'}) | ||||
resp = self.client.get(dir_url) | resp = self.client.get(dir_url) | ||||
Show All 12 Lines |