Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_directory.py
# Copyright (C) 2017-2019 The Software Heritage developers | # Copyright (C) 2017-2020 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 | ||||
import random | import random | ||||
from hypothesis import given | from hypothesis import given | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | def test_directory_uppercase(client, directory): | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 302 | assert resp.status_code == 302 | ||||
redirect_url = reverse('browse-directory', | redirect_url = reverse('browse-directory', | ||||
url_args={'sha1_git': directory}) | url_args={'sha1_git': directory}) | ||||
assert resp['location'] == redirect_url | assert resp['location'] == redirect_url | ||||
@given(directory()) | |||||
def test_permalink_box_context(client, tests_data, directory): | |||||
origin_url = random.choice(tests_data['origins'])['url'] | |||||
url = reverse('browse-directory', | |||||
url_args={'sha1_git': directory}, | |||||
query_params={'origin': origin_url}) | |||||
anlambert: The test looks good but let's try to avoid hardcoding directory sha1 and origin url.
You can… | |||||
resp = client.get(url) | |||||
assert resp.status_code == 200 | |||||
assert_contains(resp, 'id="swh-id-option-origin-directory"') | |||||
Not Done Inline ActionsI would rather you test swh-id-option-origin-directory, which checks the presence of the field instead of the form. For now it's the same thing, but we might add other fields in the future. vlorentz: I would rather you test `swh-id-option-origin-directory`, which checks the presence of the… | |||||
Not Done Inline ActionsI agree with @vlorentz anlambert: I agree with @vlorentz | |||||
def _directory_view(client, root_directory_sha1, directory_entries, | def _directory_view(client, 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 63 Lines • Show Last 20 Lines |
The test looks good but let's try to avoid hardcoding directory sha1 and origin url.
You can use the following to do so: