Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/views/test_origin.py
Show First 20 Lines • Show All 541 Lines • ▼ Show 20 Lines | url = reverse( | ||||
url_args={"url_pattern": "github com",}, | url_args={"url_pattern": "github com",}, | ||||
query_params={"visit_type": "foo"}, | query_params={"visit_type": "foo"}, | ||||
) | ) | ||||
rv = check_api_get_responses(api_client, url, status_code=200) | rv = check_api_get_responses(api_client, url, status_code=200) | ||||
assert rv.data == [] | assert rv.data == [] | ||||
def test_api_origin_search_use_ql(api_client, mocker): | def test_api_origin_search_use_ql(api_client, mocker): | ||||
mock_config = mocker.patch("swh.web.common.archive.config") | |||||
mock_config.get_config.return_value = { | |||||
"search_config": {"metadata_backend": "swh-search", "enable_ql": True} | |||||
} | |||||
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", | ||||
} | } | ||||
ORIGINS = [{"url": origin} for origin in expected_origins] | ORIGINS = [{"url": origin} for origin in expected_origins] | ||||
mock_archive_search = mocker.patch("swh.web.common.archive.search") | mock_archive_search = mocker.patch("swh.web.common.archive.search") | ||||
mock_archive_search.origin_search.return_value = PagedResult( | mock_archive_search.origin_search.return_value = PagedResult( | ||||
results=ORIGINS, next_page_token=None, | results=ORIGINS, next_page_token=None, | ||||
) | ) | ||||
query = "origin = 'github.com'" | |||||
url = reverse( | url = reverse( | ||||
"api-1-origin-search", | "api-1-origin-search", | ||||
url_args={"url_pattern": "origin = 'github.com'",}, | url_args={"url_pattern": query}, | ||||
query_params={"visit_type": "git", "use_ql": "true"}, | query_params={"visit_type": "git", "use_ql": "true"}, | ||||
) | ) | ||||
rv = check_api_get_responses(api_client, url, status_code=200) | rv = check_api_get_responses(api_client, url, status_code=200) | ||||
assert {origin["url"] for origin in rv.data} == expected_origins | assert {origin["url"] for origin in rv.data} == expected_origins | ||||
mock_archive_search.origin_search.assert_called_with( | |||||
query=query, page_token=None, with_visit=False, visit_types=["git"], limit=70 | |||||
) | |||||
@pytest.mark.parametrize("backend", ["swh-search", "swh-storage"]) | @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, mocker, limit, backend): | def test_api_origin_search_scroll(api_client, archive_data, mocker, limit, backend): | ||||
if backend != "swh-search": | if backend != "swh-search": | ||||
# equivalent to not configuring search in the config | # equivalent to not configuring search in the config | ||||
mocker.patch("swh.web.common.archive.search", None) | mocker.patch("swh.web.common.archive.search", None) | ||||
▲ Show 20 Lines • Show All 157 Lines • Show Last 20 Lines |