Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/views/test_origin.py
Show First 20 Lines • Show All 384 Lines • ▼ Show 20 Lines | def test_api_origin_not_found(api_client, new_origin): | ||||
assert rv.status_code == 404, rv.data | assert rv.status_code == 404, rv.data | ||||
assert rv['Content-Type'] == 'application/json' | assert rv['Content-Type'] == 'application/json' | ||||
assert rv.data == { | assert 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'] | ||||
} | } | ||||
def test_api_origin_search(api_client): | @pytest.mark.parametrize('backend', ['swh-search', 'swh-storage']) | ||||
def test_api_origin_search(api_client, mocker, backend): | |||||
if backend != 'swh-search': | |||||
# equivalent to not configuring search in the config | |||||
mocker.patch('swh.web.common.service.search', None) | |||||
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', | ||||
url_args={'url_pattern': 'github.com'}, | url_args={'url_pattern': 'github.com'}, | ||||
Show All 18 Lines | url = reverse('api-1-origin-search', | ||||
url_args={'url_pattern': 'github.com'}, | url_args={'url_pattern': 'github.com'}, | ||||
query_params={'limit': 10}) | query_params={'limit': 10}) | ||||
rv = api_client.get(url) | rv = api_client.get(url) | ||||
assert rv.status_code == 200, rv.data | assert rv.status_code == 200, rv.data | ||||
assert rv['Content-Type'] == 'application/json' | assert rv['Content-Type'] == 'application/json' | ||||
assert {origin['url'] for origin in rv.data} == expected_origins | assert {origin['url'] for origin in rv.data} == expected_origins | ||||
def test_api_origin_search_words(api_client): | @pytest.mark.parametrize('backend', ['swh-search', 'swh-storage']) | ||||
def test_api_origin_search_words(api_client, mocker, backend): | |||||
if backend != 'swh-search': | |||||
# equivalent to not configuring search in the config | |||||
mocker.patch('swh.web.common.service.search', None) | |||||
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': 2}) | query_params={'limit': 2}) | ||||
Show All 26 Lines | def test_api_origin_search_words(api_client, mocker, backend): | ||||
rv = api_client.get(url) | rv = api_client.get(url) | ||||
assert rv.status_code == 200, rv.data | assert rv.status_code == 200, rv.data | ||||
assert rv['Content-Type'] == 'application/json' | assert rv['Content-Type'] == 'application/json' | ||||
assert len(rv.data) == 1 | assert len(rv.data) == 1 | ||||
assert {origin['url'] for origin in rv.data} \ | assert {origin['url'] for origin in rv.data} \ | ||||
== {'https://github.com/memononen/libtess2'} | == {'https://github.com/memononen/libtess2'} | ||||
@pytest.mark.parametrize('backend', ['swh-search', 'swh-storage']) | |||||
@pytest.mark.parametrize('limit', [1, 2, 3, 10]) | @pytest.mark.parametrize('limit', [1, 2, 3, 10]) | ||||
def test_api_origin_search_scroll(api_client, archive_data, limit): | def test_api_origin_search_scroll( | ||||
api_client, archive_data, mocker, limit, backend): | |||||
if backend != 'swh-search': | |||||
# equivalent to not configuring search in the config | |||||
mocker.patch('swh.web.common.service.search', None) | |||||
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 = _scroll_results(api_client, url) | results = _scroll_results(api_client, url) | ||||
assert {origin['url'] for origin in results} == expected_origins | assert {origin['url'] for origin in results} == expected_origins | ||||
def test_api_origin_search_limit(api_client, archive_data): | @pytest.mark.parametrize('backend', ['swh-search', 'swh-storage']) | ||||
def test_api_origin_search_limit( | |||||
api_client, archive_data, tests_data, mocker, backend): | |||||
if backend == 'swh-search': | |||||
tests_data['search'].origin_update([ | |||||
{'url': 'http://foobar/{}'.format(i)} | |||||
for i in range(2000) | |||||
]) | |||||
else: | |||||
# equivalent to not configuring search in the config | |||||
mocker.patch('swh.web.common.service.search', None) | |||||
archive_data.origin_add([ | archive_data.origin_add([ | ||||
{'url': 'http://foobar/{}'.format(i)} | {'url': 'http://foobar/{}'.format(i)} | ||||
for i in range(2000) | for i in range(2000) | ||||
]) | ]) | ||||
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': 1050}) | query_params={'limit': 1050}) | ||||
rv = api_client.get(url) | rv = api_client.get(url) | ||||
assert rv.status_code == 200, rv.data | assert rv.status_code == 200, rv.data | ||||
assert rv['Content-Type'] == 'application/json' | assert rv['Content-Type'] == 'application/json' | ||||
assert len(rv.data) == 1000 | assert len(rv.data) == 1000 | ||||
▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines |