Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/views/test_origin.py
Show First 20 Lines • Show All 513 Lines • ▼ Show 20 Lines | def test_api_origin_search_words(api_client, 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) == 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("backend", ["swh-search", "swh-storage"]) | ||||
def test_api_origin_search_visit_type(api_client, mocker, backend): | |||||
if backend != "swh-search": | |||||
# equivalent to not configuring search in the config | |||||
mocker.patch("swh.web.common.archive.search", None) | |||||
expected_origins = { | |||||
"https://github.com/wcoder/highlightjs-line-numbers.js", | |||||
"https://github.com/memononen/libtess2", | |||||
} | |||||
url = reverse( | |||||
"api-1-origin-search", | |||||
url_args={"url_pattern": "github com",}, | |||||
query_params={"visit_type": "git"}, | |||||
) | |||||
rv = check_api_get_responses(api_client, url, status_code=200) | |||||
assert {origin["url"] for origin in rv.data} == expected_origins | |||||
url = reverse( | |||||
"api-1-origin-search", | |||||
url_args={"url_pattern": "github com",}, | |||||
query_params={"visit_type": "foo"}, | |||||
) | |||||
rv = check_api_get_responses(api_client, url, status_code=200) | |||||
assert rv.data == [] | |||||
@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) | ||||
expected_origins = { | expected_origins = { | ||||
▲ Show 20 Lines • Show All 126 Lines • Show Last 20 Lines |