diff --git a/swh/web/tests/api/views/test_content.py b/swh/web/tests/api/views/test_content.py --- a/swh/web/tests/api/views/test_content.py +++ b/swh/web/tests/api/views/test_content.py @@ -9,8 +9,9 @@ from rest_framework.test import APITestCase from swh.web.common.utils import reverse +from swh.web.tests.data import random_content from swh.web.tests.strategies import ( - content, unknown_content, contents_with_ctags + content, contents_with_ctags ) from swh.web.tests.testcase import ( WebTestCase, ctags_json_missing, fossology_missing @@ -35,11 +36,11 @@ expected_data['content_url'] = content_url self.assertEqual(rv.data, expected_data) - @given(unknown_content()) - def test_api_content_filetype_sha_not_found(self, unknown_content): + def test_api_content_filetype_sha_not_found(self): + unknown_content_ = random_content() url = reverse('api-content-filetype', - url_args={'q': 'sha1:%s' % unknown_content['sha1']}) + url_args={'q': 'sha1:%s' % unknown_content_['sha1']}) rv = self.client.get(url) self.assertEqual(rv.status_code, 404) @@ -47,7 +48,7 @@ self.assertEqual(rv.data, { 'exception': 'NotFoundExc', 'reason': 'No filetype information found for content ' - 'sha1:%s.' % unknown_content['sha1'] + 'sha1:%s.' % unknown_content_['sha1'] }) @pytest.mark.xfail # Language indexer is disabled @@ -67,11 +68,11 @@ expected_data['content_url'] = content_url self.assertEqual(rv.data, expected_data) - @given(unknown_content()) - def test_api_content_language_sha_not_found(self, unknown_content): + def test_api_content_language_sha_not_found(self): + unknown_content_ = random_content() url = reverse('api-content-language', - url_args={'q': 'sha1:%s' % unknown_content['sha1']}) + url_args={'q': 'sha1:%s' % unknown_content_['sha1']}) rv = self.client.get(url) self.assertEqual(rv.status_code, 404) @@ -79,7 +80,7 @@ self.assertEqual(rv.data, { 'exception': 'NotFoundExc', 'reason': 'No language information found for content ' - 'sha1:%s.' % unknown_content['sha1'] + 'sha1:%s.' % unknown_content_['sha1'] }) @pytest.mark.xfail # Language indexer is disabled @@ -179,11 +180,11 @@ expected_data['content_url'] = content_url self.assertEqual(rv.data, expected_data) - @given(unknown_content()) - def test_api_content_license_sha_not_found(self, unknown_content): + def test_api_content_license_sha_not_found(self): + unknown_content_ = random_content() url = reverse('api-content-license', - url_args={'q': 'sha1:%s' % unknown_content['sha1']}) + url_args={'q': 'sha1:%s' % unknown_content_['sha1']}) rv = self.client.get(url) self.assertEqual(rv.status_code, 404) @@ -191,7 +192,7 @@ self.assertEqual(rv.data, { 'exception': 'NotFoundExc', 'reason': 'No license information found for content ' - 'sha1:%s.' % unknown_content['sha1'] + 'sha1:%s.' % unknown_content_['sha1'] }) @given(content()) @@ -212,25 +213,25 @@ content['sha1']}) self.assertEqual(rv.data, expected_data) - @given(unknown_content()) - def test_api_content_not_found_as_json(self, unknown_content): + def test_api_content_not_found_as_json(self): + unknown_content_ = random_content() url = reverse('api-content', - url_args={'q': 'sha1:%s' % unknown_content['sha1']}) + url_args={'q': 'sha1:%s' % unknown_content_['sha1']}) rv = self.client.get(url) self.assertEqual(rv.status_code, 404) self.assertEqual(rv['Content-Type'], 'application/json') self.assertEqual(rv.data, { 'exception': 'NotFoundExc', 'reason': 'Content with sha1 checksum equals to %s not found!' - % unknown_content['sha1'] + % unknown_content_['sha1'] }) - @given(unknown_content()) - def test_api_content_not_found_as_yaml(self, unknown_content): + def test_api_content_not_found_as_yaml(self): + unknown_content_ = random_content() url = reverse('api-content', - url_args={'q': 'sha256:%s' % unknown_content['sha256']}) + url_args={'q': 'sha256:%s' % unknown_content_['sha256']}) rv = self.client.get(url, HTTP_ACCEPT='application/yaml') self.assertEqual(rv.status_code, 404) @@ -239,14 +240,14 @@ self.assertEqual(rv.data, { 'exception': 'NotFoundExc', 'reason': 'Content with sha256 checksum equals to %s not found!' % - unknown_content['sha256'] + unknown_content_['sha256'] }) - @given(unknown_content()) - def test_api_content_raw_ko_not_found(self, unknown_content): + def test_api_content_raw_ko_not_found(self): + unknown_content_ = random_content() url = reverse('api-content-raw', - url_args={'q': 'sha1:%s' % unknown_content['sha1']}) + url_args={'q': 'sha1:%s' % unknown_content_['sha1']}) rv = self.client.get(url) self.assertEqual(rv.status_code, 404) @@ -254,7 +255,7 @@ self.assertEqual(rv.data, { 'exception': 'NotFoundExc', 'reason': 'Content with sha1 checksum equals to %s not found!' % - unknown_content['sha1'] + unknown_content_['sha1'] }) @given(content()) @@ -357,11 +358,11 @@ 'search_stats': {'nbfiles': 1, 'pct': 100.0} }) - @given(unknown_content()) - def test_api_check_content_known_not_found(self, unknown_content): + def test_api_check_content_known_not_found(self): + unknown_content_ = random_content() url = reverse('api-content-known', - url_args={'q': unknown_content['sha1']}) + url_args={'q': unknown_content_['sha1']}) rv = self.client.get(url) self.assertEqual(rv.status_code, 200) @@ -370,7 +371,7 @@ 'search_res': [ { 'found': False, - 'sha1': unknown_content['sha1'] + 'sha1': unknown_content_['sha1'] } ], 'search_stats': {'nbfiles': 1, 'pct': 0.0} 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 @@ -9,7 +9,8 @@ from rest_framework.test import APITestCase from swh.web.common.utils import reverse -from swh.web.tests.strategies import directory, unknown_directory +from swh.web.tests.data import random_sha1 +from swh.web.tests.strategies import directory from swh.web.tests.testcase import WebTestCase @@ -29,11 +30,11 @@ self.assertEqual(rv.data, expected_data) - @given(unknown_directory()) - def test_api_directory_not_found(self, unknown_directory): + def test_api_directory_not_found(self): + unknown_directory_ = random_sha1() url = reverse('api-directory', - url_args={'sha1_git': unknown_directory}) + url_args={'sha1_git': unknown_directory_}) rv = self.client.get(url) self.assertEqual(rv.status_code, 404) @@ -41,7 +42,7 @@ self.assertEqual(rv.data, { 'exception': 'NotFoundExc', 'reason': 'Directory with sha1_git %s not found' - % unknown_directory}) + % unknown_directory_}) @given(directory()) def test_api_directory_with_path_found(self, directory): diff --git a/swh/web/tests/api/views/test_origin.py b/swh/web/tests/api/views/test_origin.py --- a/swh/web/tests/api/views/test_origin.py +++ b/swh/web/tests/api/views/test_origin.py @@ -76,7 +76,7 @@ 'An unexpected error occurred in the api backend: %s' % err_msg }) - @given(new_origin(), visit_dates(4), new_snapshots(4)) + @given(new_origin(), visit_dates(3), new_snapshots(3)) def test_api_lookup_origin_visits(self, new_origin, visit_dates, new_snapshots): @@ -116,7 +116,7 @@ self.assertEqual(rv.data, expected_visits) - @given(new_origin(), visit_dates(4), new_snapshots(4)) + @given(new_origin(), visit_dates(3), new_snapshots(3)) def test_api_lookup_origin_visit(self, new_origin, visit_dates, new_snapshots): @@ -335,7 +335,7 @@ self.assertEqual(rv.status_code, 400, rv.content) mock_idx_storage.assert_not_called() - @given(new_origins(20)) + @given(new_origins(10)) def test_api_lookup_origins(self, new_origins): nb_origins = len(new_origins) diff --git a/swh/web/tests/api/views/test_person.py b/swh/web/tests/api/views/test_person.py --- a/swh/web/tests/api/views/test_person.py +++ b/swh/web/tests/api/views/test_person.py @@ -3,11 +3,13 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information +import random + from hypothesis import given from rest_framework.test import APITestCase from swh.web.common.utils import reverse -from swh.web.tests.strategies import person, unknown_person +from swh.web.tests.strategies import person from swh.web.tests.testcase import WebTestCase @@ -26,10 +28,10 @@ self.assertEqual(rv['Content-Type'], 'application/json') self.assertEqual(rv.data, expected_person) - @given(unknown_person()) - def test_api_person_not_found(self, unknown_person): + def test_api_person_not_found(self): + unknown_person_ = random.randint(1000, 10000000) - url = reverse('api-person', url_args={'person_id': unknown_person}) + url = reverse('api-person', url_args={'person_id': unknown_person_}) rv = self.client.get(url) @@ -37,4 +39,4 @@ self.assertEqual(rv['Content-Type'], 'application/json') self.assertEqual(rv.data, { 'exception': 'NotFoundExc', - 'reason': 'Person with id %s not found' % unknown_person}) + 'reason': 'Person with id %s not found' % unknown_person_}) 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 @@ -9,8 +9,9 @@ from swh.model.hashutil import hash_to_bytes from swh.web.common.utils import reverse +from swh.web.tests.data import random_sha1 from swh.web.tests.strategies import ( - release, unknown_release, sha1, content, directory + release, sha1, content, directory ) from swh.web.tests.testcase import WebTestCase @@ -96,10 +97,10 @@ self.assertEqual(rv['Content-Type'], 'application/json') self.assertEqual(rv.data, expected_release) - @given(unknown_release()) - def test_api_release_not_found(self, unknown_release): + def test_api_release_not_found(self): + unknown_release_ = random_sha1() - url = reverse('api-release', url_args={'sha1_git': unknown_release}) + url = reverse('api-release', url_args={'sha1_git': unknown_release_}) rv = self.client.get(url) @@ -107,7 +108,7 @@ self.assertEqual(rv['Content-Type'], 'application/json') self.assertEqual(rv.data, { 'exception': 'NotFoundExc', - 'reason': 'Release with sha1_git %s not found.' % unknown_release + 'reason': 'Release with sha1_git %s not found.' % unknown_release_ }) @given(release()) diff --git a/swh/web/tests/api/views/test_revision.py b/swh/web/tests/api/views/test_revision.py --- a/swh/web/tests/api/views/test_revision.py +++ b/swh/web/tests/api/views/test_revision.py @@ -14,9 +14,9 @@ from swh.web.common.exc import NotFoundExc from swh.web.common.utils import reverse, parse_timestamp +from swh.web.tests.data import random_sha1 from swh.web.tests.strategies import ( - revision, unknown_revision, new_revision, - unknown_origin_id, origin, origin_with_multiple_visits + revision, new_revision, origin, origin_with_multiple_visits ) from swh.web.tests.testcase import WebTestCase @@ -37,10 +37,11 @@ self.assertEqual(rv['Content-Type'], 'application/json') self.assertEqual(rv.data, expected_revision) - @given(unknown_revision()) - def test_api_revision_not_found(self, unknown_revision): + def test_api_revision_not_found(self): + unknown_revision_ = random_sha1() - url = reverse('api-revision', url_args={'sha1_git': unknown_revision}) + url = reverse('api-revision', + url_args={'sha1_git': unknown_revision_}) rv = self.client.get(url) self.assertEqual(rv.status_code, 404) @@ -48,7 +49,7 @@ self.assertEqual(rv.data, { 'exception': 'NotFoundExc', 'reason': 'Revision with sha1_git %s not found.' % - unknown_revision}) + unknown_revision_}) @given(revision()) def test_api_revision_raw_ok(self, revision): @@ -83,11 +84,11 @@ 'reason': 'No message for revision with sha1_git %s.' % new_revision_id}) - @given(unknown_revision()) - def test_api_revision_raw_ko_no_rev(self, unknown_revision): + def test_api_revision_raw_ko_no_rev(self): + unknown_revision_ = random_sha1() url = reverse('api-revision-raw-message', - url_args={'sha1_git': unknown_revision}) + url_args={'sha1_git': unknown_revision_}) rv = self.client.get(url) self.assertEqual(rv.status_code, 404) @@ -95,13 +96,13 @@ self.assertEqual(rv.data, { 'exception': 'NotFoundExc', 'reason': 'Revision with sha1_git %s not found.' % - unknown_revision}) + unknown_revision_}) - @given(unknown_origin_id()) - def test_api_revision_with_origin_not_found(self, unknown_origin_id): + def test_api_revision_with_origin_not_found(self): + unknown_origin_id_ = random.randint(1000, 1000000) url = reverse('api-revision-origin', - url_args={'origin_id': unknown_origin_id}) + url_args={'origin_id': unknown_origin_id_}) rv = self.client.get(url) self.assertEqual(rv.status_code, 404) @@ -109,7 +110,7 @@ self.assertEqual(rv.data, { 'exception': 'NotFoundExc', 'reason': 'Origin with id %s not found!' % - unknown_origin_id}) + unknown_origin_id_}) @given(origin()) def test_api_revision_with_origin(self, origin): @@ -210,12 +211,11 @@ self.assertEqual(rv['Content-Type'], 'application/json') self.assertEqual(rv.data, expected_revision) - @given(unknown_origin_id()) - def test_api_directory_through_revision_origin_ko(self, - unknown_origin_id): + def test_api_directory_through_revision_origin_ko(self): + unknown_origin_id_ = random.randint(1000, 1000000) url = reverse('api-revision-origin-directory', - url_args={'origin_id': unknown_origin_id}) + url_args={'origin_id': unknown_origin_id_}) rv = self.client.get(url) self.assertEqual(rv.status_code, 404) @@ -223,7 +223,7 @@ self.assertEqual(rv.data, { 'exception': 'NotFoundExc', 'reason': 'Origin with id %s not found!' % - unknown_origin_id + unknown_origin_id_ }) @given(origin()) @@ -306,11 +306,11 @@ query_params={'per_page': per_page}) self.assertIn(next_log_url, rv['Link']) - @given(unknown_revision()) - def test_api_revision_log_not_found(self, unknown_revision): + def test_api_revision_log_not_found(self): + unknown_revision_ = random_sha1() url = reverse('api-revision-log', - url_args={'sha1_git': unknown_revision}) + url_args={'sha1_git': unknown_revision_}) rv = self.client.get(url) @@ -319,7 +319,7 @@ self.assertEqual(rv.data, { 'exception': 'NotFoundExc', 'reason': 'Revision with sha1_git %s not found.' % - unknown_revision}) + unknown_revision_}) self.assertFalse(rv.has_header('Link')) @given(revision()) 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 @@ -10,8 +10,9 @@ from swh.model.hashutil import hash_to_hex from swh.web.common.utils import reverse +from swh.web.tests.data import random_sha1 from swh.web.tests.strategies import ( - snapshot, unknown_snapshot, new_snapshot + snapshot, new_snapshot ) from swh.web.tests.testcase import WebTestCase @@ -117,8 +118,8 @@ self.assertEqual(rv['Content-Type'], 'application/json') self.assertEqual(rv.data, expected_data) - @given(unknown_snapshot()) - def test_api_snapshot_errors(self, unknown_snapshot): + def test_api_snapshot_errors(self): + unknown_snapshot_ = random_sha1() url = reverse('api-snapshot', url_args={'snapshot_id': '63ce369'}) @@ -126,7 +127,7 @@ self.assertEqual(rv.status_code, 400) url = reverse('api-snapshot', - url_args={'snapshot_id': unknown_snapshot}) + url_args={'snapshot_id': unknown_snapshot_}) rv = self.client.get(url) self.assertEqual(rv.status_code, 404) @@ -186,4 +187,4 @@ url = reverse('api-snapshot', url_args={'snapshot_id': snp_id}) rv = self.client.get(url) - self.assertEqual(rv.status_code, 200) + self.assertEqual(rv.status_code, 200, rv.data) diff --git a/swh/web/tests/browse/test_utils.py b/swh/web/tests/browse/test_utils.py --- a/swh/web/tests/browse/test_utils.py +++ b/swh/web/tests/browse/test_utils.py @@ -19,7 +19,7 @@ ('text/plain', 'us-ascii')) @given(origin_with_multiple_visits()) - def test_get_origin_visit_snapshot(self, origin): + def test_get_origin_visit_snapshot_simple(self, origin): visits = self.origin_visit_get(origin['id']) @@ -54,6 +54,8 @@ 'directory': rev_data['directory'] }) + assert branches and releases, 'Incomplete test data.' + origin_visit_branches = utils.get_origin_visit_snapshot( origin, visit_id=visit['visit']) diff --git a/swh/web/tests/common/test_service.py b/swh/web/tests/common/test_service.py --- a/swh/web/tests/common/test_service.py +++ b/swh/web/tests/common/test_service.py @@ -15,12 +15,13 @@ from swh.web.common import service from swh.web.common.exc import BadInputExc, NotFoundExc +from swh.web.tests.data import random_sha1, random_content from swh.web.tests.strategies import ( - content, contents, unknown_content, unknown_contents, + content, contents, unknown_contents, contents_with_ctags, origin, new_origin, visit_dates, directory, - release, revision, unknown_revision, revisions, unknown_revisions, + release, revision, unknown_revision, revisions, ancestor_revisions, non_ancestor_revisions, invalid_sha1, sha256, - revision_with_submodules, unknown_directory, empty_directory, + revision_with_submodules, empty_directory, new_revision, new_origins ) from swh.web.tests.testcase import ( @@ -58,11 +59,11 @@ self.assertEqual(service.lookup_multiple_hashes(input_data), expected_output) - @given(unknown_content()) - def test_lookup_hash_does_not_exist(self, unknown_content): + def test_lookup_hash_does_not_exist(self): + unknown_content_ = random_content() actual_lookup = service.lookup_hash('sha1_git:%s' % - unknown_content['sha1_git']) + unknown_content_['sha1_git']) self.assertEqual(actual_lookup, {'found': None, 'algo': 'sha1_git'}) @@ -77,11 +78,11 @@ self.assertEqual({'found': content_metadata, 'algo': 'sha1'}, actual_lookup) - @given(unknown_content()) - def test_search_hash_does_not_exist(self, content): + def test_search_hash_does_not_exist(self): + unknown_content_ = random_content() actual_lookup = service.search_hash('sha1_git:%s' % - content['sha1_git']) + unknown_content_['sha1_git']) self.assertEqual({'found': False}, actual_lookup) @@ -108,12 +109,12 @@ self.assertEqual(actual_ctags, expected_data) - @given(unknown_content()) - def test_lookup_content_ctags_no_hash(self, unknown_content): + def test_lookup_content_ctags_no_hash(self): + unknown_content_ = random_content() actual_ctags = \ list(service.lookup_content_ctags('sha1:%s' % - unknown_content['sha1'])) + unknown_content_['sha1'])) self.assertEqual(actual_ctags, []) @@ -333,17 +334,18 @@ self.assertIn('Revision %s is not an ancestor of %s' % (sha1_git, root_sha1_git), cm.exception.args[0]) - @given(unknown_revision()) - def test_lookup_directory_with_revision_not_found(self, unknown_revision): + def test_lookup_directory_with_revision_not_found(self): + unknown_revision_ = random_sha1() with self.assertRaises(NotFoundExc) as cm: - service.lookup_directory_with_revision(unknown_revision) - self.assertIn('Revision %s not found' % unknown_revision, + service.lookup_directory_with_revision(unknown_revision_) + self.assertIn('Revision %s not found' % unknown_revision_, cm.exception.args[0]) - @given(unknown_content(), unknown_revision(), unknown_directory()) - def test_lookup_directory_with_revision_unknown_content( - self, unknown_content, unknown_revision, unknown_directory): + def test_lookup_directory_with_revision_unknown_content(self): + unknown_content_ = random_content() + unknown_revision_ = random_sha1() + unknown_directory_ = random_sha1() dir_path = 'README.md' # Create a revision that points to a directory @@ -374,16 +376,16 @@ 'parents': [], 'synthetic': False, 'type': 'file', - 'id': hash_to_bytes(unknown_revision), - 'directory': hash_to_bytes(unknown_directory) + 'id': hash_to_bytes(unknown_revision_), + 'directory': hash_to_bytes(unknown_directory_) } # A directory that points to unknown content dir = { - 'id': hash_to_bytes(unknown_directory), + 'id': hash_to_bytes(unknown_directory_), 'entries': [{ 'name': bytes(dir_path.encode('utf-8')), 'type': 'file', - 'target': hash_to_bytes(unknown_content['sha1_git']), + 'target': hash_to_bytes(unknown_content_['sha1_git']), 'perms': DentryPerms.content }] } @@ -391,8 +393,10 @@ self.storage.directory_add([dir]) self.storage.revision_add([revision]) with self.assertRaises(NotFoundExc) as cm: - service.lookup_directory_with_revision(unknown_revision, dir_path) - self.assertIn('Content not found for revision %s' % unknown_revision, + service.lookup_directory_with_revision( + unknown_revision_, dir_path) + self.assertIn('Content not found for revision %s' % + unknown_revision_, cm.exception.args[0]) @given(revision()) @@ -536,15 +540,15 @@ 'No message for revision with sha1_git %s.' % new_revision_id ) - @given(unknown_revision()) - def test_lookup_revision_msg_no_rev(self, unknown_revision): + def test_lookup_revision_msg_no_rev(self): + unknown_revision_ = random_sha1() with self.assertRaises(NotFoundExc) as cm: - service.lookup_revision_message(unknown_revision) + service.lookup_revision_message(unknown_revision_) self.assertEqual( cm.exception.args[0], - 'Revision with sha1_git %s not found.' % unknown_revision + 'Revision with sha1_git %s not found.' % unknown_revision_ ) @given(revisions()) @@ -558,13 +562,13 @@ self.assertEqual(actual_revisions, expected_revisions) - @given(unknown_revisions()) - def test_lookup_revision_multiple_none_found(self, unknown_revisions): + def test_lookup_revision_multiple_none_found(self): + unknown_revisions_ = [random_sha1(), random_sha1(), random_sha1()] actual_revisions = \ - list(service.lookup_revision_multiple(unknown_revisions)) + list(service.lookup_revision_multiple(unknown_revisions_)) - self.assertEqual(actual_revisions, [None] * len(unknown_revisions)) + self.assertEqual(actual_revisions, [None] * len(unknown_revisions_)) @given(revision()) def test_lookup_revision_log(self, revision): @@ -604,15 +608,15 @@ service.lookup_revision_log_by( origin['id'], 'unknown_branch_name', None, limit=100) - @given(unknown_content()) - def test_lookup_content_raw_not_found(self, unknown_content): + def test_lookup_content_raw_not_found(self): + unknown_content_ = random_content() with self.assertRaises(NotFoundExc) as cm: - service.lookup_content_raw('sha1:' + unknown_content['sha1']) + service.lookup_content_raw('sha1:' + unknown_content_['sha1']) self.assertIn(cm.exception.args[0], 'Content with %s checksum equals to %s not found!' % - ('sha1', unknown_content['sha1'])) + ('sha1', unknown_content_['sha1'])) @given(content()) def test_lookup_content_raw(self, content): @@ -624,15 +628,15 @@ self.assertEqual(actual_content, expected_content) - @given(unknown_content()) - def test_lookup_content_not_found(self, unknown_content): + def test_lookup_content_not_found(self): + unknown_content_ = random_content() with self.assertRaises(NotFoundExc) as cm: - service.lookup_content('sha1:%s' % unknown_content['sha1']) + service.lookup_content('sha1:%s' % unknown_content_['sha1']) self.assertIn(cm.exception.args[0], 'Content with %s checksum equals to %s not found!' % - ('sha1', unknown_content['sha1'])) + ('sha1', unknown_content_['sha1'])) @given(content()) def test_lookup_content_with_sha1(self, content): @@ -668,14 +672,14 @@ with self.assertRaises(BadInputExc): service.lookup_directory('directory_id') - @given(unknown_directory()) - def test_lookup_directory_not_found(self, unknown_directory): + def test_lookup_directory_not_found(self): + unknown_directory_ = random_sha1() with self.assertRaises(NotFoundExc) as cm: - service.lookup_directory(unknown_directory) + service.lookup_directory(unknown_directory_) self.assertIn('Directory with sha1_git %s not found' - % unknown_directory, cm.exception.args[0]) + % unknown_directory_, cm.exception.args[0]) @given(directory()) def test_lookup_directory(self, directory): diff --git a/swh/web/tests/data.py b/swh/web/tests/data.py --- a/swh/web/tests/data.py +++ b/swh/web/tests/data.py @@ -5,6 +5,7 @@ from copy import deepcopy import os +import random import time from swh.indexer.fossology_license import FossologyLicenseIndexer @@ -62,6 +63,27 @@ } +def random_sha1(): + return hash_to_hex(bytes(random.randint(0, 255) for _ in range(20))) + + +def random_sha256(): + return hash_to_hex(bytes(random.randint(0, 255) for _ in range(32))) + + +def random_blake2s256(): + return hash_to_hex(bytes(random.randint(0, 255) for _ in range(32))) + + +def random_content(): + return { + 'sha1': random_sha1(), + 'sha1_git': random_sha1(), + 'sha256': random_sha256(), + 'blake2s256': random_blake2s256(), + } + + # MimetypeIndexer with custom configuration for tests class _MimetypeIndexer(MimetypeIndexer): def parse_config_file(self, *args, **kwargs):