Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/views/test_origin.py
Show First 20 Lines • Show All 310 Lines • ▼ Show 20 Lines | def test_api_lookup_origin_visit_not_found(self, origin): | ||||
max_visit_id = max([v['visit'] for v in all_visits]) | max_visit_id = max([v['visit'] for v in all_visits]) | ||||
url = reverse('api-1-origin-visit', | url = reverse('api-1-origin-visit', | ||||
url_args={'origin_url': origin['url'], | url_args={'origin_url': origin['url'], | ||||
'visit_id': max_visit_id + 1}) | 'visit_id': max_visit_id + 1}) | ||||
rv = self.client.get(url) | rv = self.client.get(url) | ||||
self.maxDiff = None | |||||
self.assertEqual(rv.status_code, 404, rv.data) | self.assertEqual(rv.status_code, 404, rv.data) | ||||
self.assertEqual(rv['Content-Type'], 'application/json') | self.assertEqual(rv['Content-Type'], 'application/json') | ||||
self.assertEqual(rv.data, { | self.assertEqual(rv.data, { | ||||
'exception': 'NotFoundExc', | 'exception': 'NotFoundExc', | ||||
'reason': 'Origin %s or its visit with id %s not found!' % | 'reason': 'Origin %s or its visit with id %s not found!' % | ||||
(origin['url'], max_visit_id+1) | (origin['url'], max_visit_id+1) | ||||
}) | }) | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | def test_api_origin_not_found(self, new_origin): | ||||
self.assertEqual(rv.status_code, 404, rv.data) | self.assertEqual(rv.status_code, 404, rv.data) | ||||
self.assertEqual(rv['Content-Type'], 'application/json') | self.assertEqual(rv['Content-Type'], 'application/json') | ||||
self.assertEqual(rv.data, { | self.assertEqual(rv.data, { | ||||
'exception': 'NotFoundExc', | 'exception': 'NotFoundExc', | ||||
'reason': 'Origin with url %s not found!' % new_origin['url'] | 'reason': 'Origin with url %s not found!' % new_origin['url'] | ||||
}) | }) | ||||
@pytest.mark.origin_id | |||||
def test_api_origin_search(self): | def test_api_origin_search(self): | ||||
expected_origins = { | expected_origins = { | ||||
'https://github.com/wcoder/highlightjs-line-numbers.js', | 'https://github.com/wcoder/highlightjs-line-numbers.js', | ||||
'https://github.com/memononen/libtess2', | 'https://github.com/memononen/libtess2', | ||||
} | } | ||||
# Search for 'github.com', get only one | # Search for 'github.com', get only one | ||||
url = reverse('api-1-origin-search', | url = reverse('api-1-origin-search', | ||||
Show All 21 Lines | def test_api_origin_search(self): | ||||
url_args={'url_pattern': 'github.com'}, | url_args={'url_pattern': 'github.com'}, | ||||
query_params={'limit': 10}) | query_params={'limit': 10}) | ||||
rv = self.client.get(url) | rv = self.client.get(url) | ||||
self.assertEqual(rv.status_code, 200, rv.data) | self.assertEqual(rv.status_code, 200, rv.data) | ||||
self.assertEqual(rv['Content-Type'], 'application/json') | self.assertEqual(rv['Content-Type'], 'application/json') | ||||
self.assertEqual({origin['url'] for origin in rv.data}, | self.assertEqual({origin['url'] for origin in rv.data}, | ||||
expected_origins) | expected_origins) | ||||
@pytest.mark.origin_id | |||||
def test_api_origin_search_regexp(self): | |||||
expected_origins = { | |||||
'https://github.com/memononen/libtess2', | |||||
'repo_with_submodules' | |||||
} | |||||
url = reverse('api-1-origin-search', | |||||
url_args={'url_pattern': '(repo|libtess)'}, | |||||
query_params={'limit': 10, | |||||
'regexp': True}) | |||||
rv = self.client.get(url) | |||||
self.assertEqual(rv.status_code, 200, rv.data) | |||||
self.assertEqual(rv['Content-Type'], 'application/json') | |||||
self.assertEqual({origin['url'] for origin in rv.data}, | |||||
expected_origins) | |||||
@pytest.mark.origin_id | |||||
@given(strategies.integers(min_value=1)) | @given(strategies.integers(min_value=1)) | ||||
def test_api_origin_search_scroll(self, limit): | def test_api_origin_search_scroll(self, limit): | ||||
expected_origins = { | expected_origins = { | ||||
'https://github.com/wcoder/highlightjs-line-numbers.js', | 'https://github.com/wcoder/highlightjs-line-numbers.js', | ||||
'https://github.com/memononen/libtess2', | 'https://github.com/memononen/libtess2', | ||||
} | } | ||||
url = reverse('api-1-origin-search', | url = reverse('api-1-origin-search', | ||||
url_args={'url_pattern': 'github.com'}, | url_args={'url_pattern': 'github.com'}, | ||||
query_params={'limit': limit}) | query_params={'limit': limit}) | ||||
results = self._scroll_results(url) | results = self._scroll_results(url) | ||||
self.assertEqual({origin['url'] for origin in results}, | self.assertEqual({origin['url'] for origin in results}, | ||||
expected_origins) | expected_origins) | ||||
def test_api_origin_search_limit(self): | def test_api_origin_search_limit(self): | ||||
self.storage.origin_add([ | self.search.origin_update([ | ||||
{'url': 'http://foobar/{}'.format(i)} | {'url': 'http://foobar/{}'.format(i)} | ||||
for i in range(200) | for i in range(200) | ||||
]) | ]) | ||||
url = reverse('api-1-origin-search', | url = reverse('api-1-origin-search', | ||||
url_args={'url_pattern': 'foobar'}, | url_args={'url_pattern': 'foobar'}, | ||||
query_params={'limit': 150}) | query_params={'limit': 150}) | ||||
rv = self.client.get(url) | rv = self.client.get(url) | ||||
▲ Show 20 Lines • Show All 149 Lines • Show Last 20 Lines |