Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/tests/test_npm.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 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 | ||||
import os | import os | ||||
import pytest | |||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.loader.package.npm import ( | from swh.loader.package.npm import ( | ||||
parse_npm_package_author, extract_npm_package_author | parse_npm_package_author, extract_npm_package_author | ||||
) | ) | ||||
from swh.loader.package.tests.common import ( | from swh.loader.package.tests.common import ( | ||||
check_snapshot, check_metadata_paths, get_stats | check_snapshot, check_metadata_paths, get_stats | ||||
▲ Show 20 Lines • Show All 512 Lines • ▼ Show 20 Lines | assert { # 3 new releases artifacts | ||||
'snapshot': 2, | 'snapshot': 2, | ||||
} == stats | } == stats | ||||
urls = [ | urls = [ | ||||
m.url for m in requests_mock_datadir_visits.request_history | m.url for m in requests_mock_datadir_visits.request_history | ||||
if m.url.startswith('https://registry.npmjs.org') | if m.url.startswith('https://registry.npmjs.org') | ||||
] | ] | ||||
assert len(urls) == len(set(urls)) # we visited each artifact once across | assert len(urls) == len(set(urls)) # we visited each artifact once across | ||||
anlambert: Here, I would rather use the [[ https://docs.pytest.org/en/latest/fixture.html#using-fixtures… | |||||
Done Inline ActionsNice, thanks for the heads up on this. ardumont: Nice, thanks for the heads up on this. | |||||
Done Inline Actionsardumont: https://docs.pytest.org/en/latest/reference.html#pytest-mark-usefixtures | |||||
@pytest.mark.usefixtures('requests_mock_datadir') | |||||
def test_npm_loader_version_divergence(swh_config): | |||||
package = '@aller_shared' | |||||
url = package_url(package) | |||||
loader = NpmLoader(package, url, package_metadata_url(package)) | |||||
actual_load_status = loader.load() | |||||
assert actual_load_status['status'] == 'eventful' | |||||
assert actual_load_status['status'] is not None | |||||
origin_visit = list(loader.storage.origin_visit_get(url))[-1] | |||||
assert origin_visit['status'] == 'full' | |||||
assert origin_visit['type'] == 'npm' | |||||
stats = get_stats(loader.storage) | |||||
assert { # 1 new releases artifacts | |||||
'content': 534, | |||||
'directory': 153, | |||||
'origin': 1, | |||||
'origin_visit': 1, | |||||
'person': 1, | |||||
'release': 0, | |||||
'revision': 2, | |||||
'skipped_content': 0, | |||||
'snapshot': 1, | |||||
} == stats | |||||
expected_snapshot = { | |||||
'id': 'b11ebac8c9d0c9e5063a2df693a18e3aba4b2f92', | |||||
'branches': { | |||||
'HEAD': { | |||||
'target_type': 'alias', | |||||
'target': 'releases/0.1.0' | |||||
}, | |||||
'releases/0.1.0': { | |||||
'target_type': 'revision', | |||||
'target': '845673bfe8cbd31b1eaf757745a964137e6f9116', | |||||
}, | |||||
'releases/0.1.1-alpha.14': { | |||||
'target_type': 'revision', | |||||
'target': '05181c12cd8c22035dd31155656826b85745da37', | |||||
}, | |||||
}, | |||||
} | |||||
check_snapshot(expected_snapshot, loader.storage) |
Here, I would rather use the [[ https://docs.pytest.org/en/latest/fixture.html#using-fixtures-from-classes-modules-or-projects | usefixtures ]] decorator from pytest as there is no direct access to the requests_mock_datadir fixture in the test implementation.