Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/maven/tests/test_lister.py
Show All 24 Lines | |||||
LIST_GIT = (GIT_REPO_URL0_HTTPS,) | LIST_GIT = (GIT_REPO_URL0_HTTPS,) | ||||
USER_REPO1 = "ArangoDB-Community/arangodb-graphql-java" | USER_REPO1 = "ArangoDB-Community/arangodb-graphql-java" | ||||
GIT_REPO_URL1_HTTPS = f"https://github.com/{USER_REPO1}" | GIT_REPO_URL1_HTTPS = f"https://github.com/{USER_REPO1}" | ||||
GIT_REPO_URL1_GIT = f"git://github.com/{USER_REPO1}.git" | GIT_REPO_URL1_GIT = f"git://github.com/{USER_REPO1}.git" | ||||
GIT_REPO_URL1_API = f"https://api.github.com/repos/{USER_REPO1}" | GIT_REPO_URL1_API = f"https://api.github.com/repos/{USER_REPO1}" | ||||
LIST_GIT_INCR = (GIT_REPO_URL1_HTTPS,) | LIST_GIT_INCR = (GIT_REPO_URL1_HTTPS,) | ||||
USER_REPO2 = "webx/citrus" | |||||
GIT_REPO_URL2_HTTPS = f"https://github.com/{USER_REPO2}" | |||||
GIT_REPO_URL2_API = f"https://api.github.com/repos/{USER_REPO2}" | |||||
LIST_SRC = (MVN_URL + "al/aldi/sprova4j",) | LIST_SRC = (MVN_URL + "al/aldi/sprova4j",) | ||||
LIST_SRC_DATA = ( | LIST_SRC_DATA = ( | ||||
{ | { | ||||
"type": "maven", | "type": "maven", | ||||
"url": "https://repo1.maven.org/maven2/al/aldi/sprova4j" | "url": "https://repo1.maven.org/maven2/al/aldi/sprova4j" | ||||
+ "/0.1.0/sprova4j-0.1.0-sources.jar", | + "/0.1.0/sprova4j-0.1.0-sources.jar", | ||||
"time": "2021-07-12T17:06:59+00:00", | "time": "2021-07-12T17:06:59+00:00", | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
@pytest.fixture | @pytest.fixture | ||||
def maven_pom_3(datadir) -> bytes: | def maven_pom_3(datadir) -> bytes: | ||||
return Path(datadir, "https_maven.org", "arangodb-graphql-1.2.pom").read_bytes() | return Path(datadir, "https_maven.org", "arangodb-graphql-1.2.pom").read_bytes() | ||||
@pytest.fixture | @pytest.fixture | ||||
def maven_pom_multi_byte_encoding(datadir) -> bytes: | |||||
return Path(datadir, "https_maven.org", "citrus-parent-3.0.7.pom").read_bytes() | |||||
@pytest.fixture | |||||
def requests_mock(requests_mock): | def requests_mock(requests_mock): | ||||
"""If github api calls for the configured scm repository, returns its canonical url.""" | """If github api calls for the configured scm repository, returns its canonical url.""" | ||||
for url_api, url_html in [ | for url_api, url_html in [ | ||||
(GIT_REPO_URL0_API, GIT_REPO_URL0_HTTPS), | (GIT_REPO_URL0_API, GIT_REPO_URL0_HTTPS), | ||||
(GIT_REPO_URL1_API, GIT_REPO_URL1_HTTPS), | (GIT_REPO_URL1_API, GIT_REPO_URL1_HTTPS), | ||||
(GIT_REPO_URL2_API, GIT_REPO_URL2_HTTPS), | |||||
]: | ]: | ||||
requests_mock.get( | requests_mock.get( | ||||
url_api, | url_api, | ||||
json={"html_url": url_html}, | json={"html_url": url_html}, | ||||
) | ) | ||||
yield requests_mock | yield requests_mock | ||||
▲ Show 20 Lines • Show All 238 Lines • ▼ Show 20 Lines | def test_maven_list_pom_bad_encoding(swh_scheduler, requests_mock, maven_pom_1): | ||||
lister = MavenLister(scheduler=swh_scheduler, url=MVN_URL, index_url=INDEX_URL) | lister = MavenLister(scheduler=swh_scheduler, url=MVN_URL, index_url=INDEX_URL) | ||||
lister.run() | lister.run() | ||||
# If the maven_index_full step succeeded but not the pom parsing step, | # If the maven_index_full step succeeded but not the pom parsing step, | ||||
# then we get only one maven-jar origin and one git origin. | # then we get only one maven-jar origin and one git origin. | ||||
scheduler_origins = swh_scheduler.get_listed_origins(lister.lister_obj.id).results | scheduler_origins = swh_scheduler.get_listed_origins(lister.lister_obj.id).results | ||||
assert len(scheduler_origins) == 2 | assert len(scheduler_origins) == 2 | ||||
def test_maven_list_pom_multi_byte_encoding( | |||||
swh_scheduler, requests_mock, maven_pom_multi_byte_encoding | |||||
): | |||||
"""should parse POM file with multi-byte encoding.""" | |||||
# replace pom file with a multi-byte encoding one | |||||
requests_mock.get(URL_POM_1, content=maven_pom_multi_byte_encoding) | |||||
lister = MavenLister(scheduler=swh_scheduler, url=MVN_URL, index_url=INDEX_URL) | |||||
lister.run() | |||||
scheduler_origins = swh_scheduler.get_listed_origins(lister.lister_obj.id).results | |||||
assert len(scheduler_origins) == 3 |