Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/views/test_origin.py
Show First 20 Lines • Show All 516 Lines • ▼ Show 20 Lines | url = reverse( | ||||
"api-1-origin-search", | "api-1-origin-search", | ||||
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): | |||||
mock_config = mocker.patch("swh.web.common.archive.config") | |||||
mock_config.get_config.return_value = { | |||||
"search_config": {"backend": "swh-search", "enable_ql": True} | |||||
} | |||||
expected_origins = { | |||||
"https://github.com/wcoder/highlightjs-line-numbers.js", | |||||
"https://github.com/memononen/libtess2", | |||||
} | |||||
ORIGINS = [{"url": origin} for origin in expected_origins] | |||||
from swh.search.interface import PagedResult | |||||
mock_search = mocker.patch("swh.search.in_memory.InMemorySearch") | |||||
mock_search.origin_search.return_value = PagedResult( | |||||
results=ORIGINS, next_page_token=None, | |||||
) | |||||
url = reverse( | |||||
"api-1-origin-search", | |||||
url_args={"url_pattern": "origin = 'github.com'",}, | |||||
query_params={"visit_type": "git", "use_ql": "true"}, | |||||
) | |||||
rv = check_api_get_responses(api_client, url, status_code=200) | |||||
assert {origin["url"] for origin in rv.data} == expected_origins | |||||
@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 All 35 Lines | def test_api_origin_search_limit(api_client, archive_data, tests_data, mocker, backend): | ||||
rv = check_api_get_responses(api_client, url, status_code=200) | rv = check_api_get_responses(api_client, url, status_code=200) | ||||
assert len(rv.data) == 1000 | assert len(rv.data) == 1000 | ||||
@pytest.mark.parametrize("backend", ["swh-search", "swh-indexer-storage"]) | @pytest.mark.parametrize("backend", ["swh-search", "swh-indexer-storage"]) | ||||
def test_api_origin_metadata_search(api_client, mocker, backend): | def test_api_origin_metadata_search(api_client, mocker, backend): | ||||
mock_config = mocker.patch("swh.web.common.archive.config") | mock_config = mocker.patch("swh.web.common.archive.config") | ||||
mock_config.get_config.return_value = {"metadata_search_backend": backend} | mock_config.get_config.return_value = {"search_config": {"backend": backend}} | ||||
url = reverse( | url = reverse( | ||||
"api-1-origin-metadata-search", query_params={"fulltext": ORIGIN_METADATA_VALUE} | "api-1-origin-metadata-search", query_params={"fulltext": ORIGIN_METADATA_VALUE} | ||||
) | ) | ||||
rv = check_api_get_responses(api_client, url, status_code=200) | rv = check_api_get_responses(api_client, url, status_code=200) | ||||
rv.data = sorted(rv.data, key=lambda d: d["url"]) | rv.data = sorted(rv.data, key=lambda d: d["url"]) | ||||
expected_data = sorted( | expected_data = sorted( | ||||
▲ Show 20 Lines • Show All 102 Lines • Show Last 20 Lines |