Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/phabricator/tests/test_lister.py
# Copyright (C) 2019-2022 The Software Heritage developers | # Copyright (C) 2019-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 | ||||
import json | import json | ||||
from pathlib import Path | from pathlib import Path | ||||
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.phabricator.lister import PhabricatorLister, get_repo_url | from swh.lister.phabricator.lister import PhabricatorLister, get_repo_url | ||||
@pytest.fixture | @pytest.fixture | ||||
def phabricator_repositories_page1(datadir): | def phabricator_repositories_page1(datadir): | ||||
return json.loads( | return json.loads( | ||||
Path(datadir, "phabricator_api_repositories_page1.json").read_text() | Path(datadir, "phabricator_api_repositories_page1.json").read_text() | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | ): | ||||
API_TOKEN = "foo" | API_TOKEN = "foo" | ||||
lister = PhabricatorLister( | lister = PhabricatorLister( | ||||
scheduler=swh_scheduler, url=FORGE_BASE_URL, instance="swh", api_token=API_TOKEN | scheduler=swh_scheduler, url=FORGE_BASE_URL, instance="swh", api_token=API_TOKEN | ||||
) | ) | ||||
def match_request(request): | def match_request(request): | ||||
return ( | return ( | ||||
request.headers.get("User-Agent") == USER_AGENT | request.headers.get("User-Agent") | ||||
== USER_AGENT_TEMPLATE % PhabricatorLister.LISTER_NAME | |||||
and f"api.token={API_TOKEN}" in request.body | and f"api.token={API_TOKEN}" in request.body | ||||
) | ) | ||||
requests_mock.post( | requests_mock.post( | ||||
f"{FORGE_BASE_URL}{lister.API_REPOSITORY_PATH}", | f"{FORGE_BASE_URL}{lister.API_REPOSITORY_PATH}", | ||||
[ | [ | ||||
{"json": phabricator_repositories_page1}, | {"json": phabricator_repositories_page1}, | ||||
{"json": phabricator_repositories_page2}, | {"json": phabricator_repositories_page2}, | ||||
Show All 37 Lines |