Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/npm/tests/test_lister.py
# Copyright (C) 2018-2022 The Software Heritage developers | # Copyright (C) 2018-2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from itertools import chain | from itertools import chain | ||||
import json | import json | ||||
from pathlib import Path | from pathlib import Path | ||||
import iso8601 | import iso8601 | ||||
import pytest | import pytest | ||||
from requests.exceptions import HTTPError | from requests.exceptions import HTTPError | ||||
from swh.lister import USER_AGENT | from swh.lister import USER_AGENT_TEMPLATE | ||||
from swh.lister.npm.lister import NpmLister, NpmListerState | from swh.lister.npm.lister import NpmLister, NpmListerState | ||||
@pytest.fixture | @pytest.fixture | ||||
def npm_full_listing_page1(datadir): | def npm_full_listing_page1(datadir): | ||||
return json.loads(Path(datadir, "npm_full_page1.json").read_text()) | return json.loads(Path(datadir, "npm_full_page1.json").read_text()) | ||||
Show All 25 Lines | for package in packages: | ||||
origin_url = lister.PACKAGE_URL_TEMPLATE.format(package_name=package_name) | origin_url = lister.PACKAGE_URL_TEMPLATE.format(package_name=package_name) | ||||
scheduler_origin = [o for o in scheduler_origins if o.url == origin_url] | scheduler_origin = [o for o in scheduler_origins if o.url == origin_url] | ||||
assert scheduler_origin | assert scheduler_origin | ||||
assert scheduler_origin[0].last_update == package_last_update | assert scheduler_origin[0].last_update == package_last_update | ||||
def _match_request(request): | def _match_request(request): | ||||
return request.headers.get("User-Agent") == USER_AGENT | return ( | ||||
request.headers.get("User-Agent") == USER_AGENT_TEMPLATE % NpmLister.LISTER_NAME | |||||
) | |||||
def _url_params(page_size, **kwargs): | def _url_params(page_size, **kwargs): | ||||
params = {"limit": page_size, "include_docs": "true"} | params = {"limit": page_size, "include_docs": "true"} | ||||
params.update(**kwargs) | params.update(**kwargs) | ||||
return params | return params | ||||
▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines |