Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/nixguix/tests/test_nixguix.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 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 pytest | import pytest | ||||
from json.decoder import JSONDecodeError | from json.decoder import JSONDecodeError | ||||
from swh.loader.package.nixguix.loader import ( | from swh.loader.package.nixguix.loader import ( | ||||
NixGuixLoader, retrieve_sources | NixGuixLoader, retrieve_sources, clean_sources | ||||
) | ) | ||||
from swh.loader.package.tests.common import ( | from swh.loader.package.tests.common import ( | ||||
get_stats, check_snapshot | get_stats, check_snapshot | ||||
) | ) | ||||
sources_url = 'https://nix-community.github.io/nixpkgs-swh/sources.json' | sources_url = 'https://nix-community.github.io/nixpkgs-swh/sources.json' | ||||
Show All 9 Lines | with pytest.raises(ValueError): | ||||
NixGuixLoader('https://non-existing-url') | NixGuixLoader('https://non-existing-url') | ||||
def test_retrieve_non_json(swh_config, requests_mock_datadir): | def test_retrieve_non_json(swh_config, requests_mock_datadir): | ||||
with pytest.raises(JSONDecodeError): | with pytest.raises(JSONDecodeError): | ||||
NixGuixLoader('https://example.com/file.txt') | NixGuixLoader('https://example.com/file.txt') | ||||
def test_clean_sources_invalid_schema(swh_config, requests_mock_datadir): | |||||
sources = {} | |||||
ardumont: you can add:
```
with pytest.raises(ValueError, match="sources structure must contain"):
... | |||||
Done Inline ActionsOh, nice. I didn't know that! lewo: Oh, nice. I didn't know that! | |||||
with pytest.raises(ValueError, | |||||
match="sources structure invalid, missing: .*"): | |||||
clean_sources(sources) | |||||
def test_clean_sources_invalid_version(swh_config, requests_mock_datadir): | |||||
sources = { | |||||
'version': 2, | |||||
'sources': [], | |||||
'revision': 'my-revision' | |||||
} | |||||
Not Done Inline ActionsAdd the match="version '2' not supported"... ardumont: Add the `match="version '2' not supported"`... | |||||
with pytest.raises(ValueError, | |||||
match="sources structure version .* is not supported"): | |||||
clean_sources(sources) | |||||
def test_clean_sources_invalid_sources(swh_config, requests_mock_datadir): | |||||
sources = { | |||||
'version': 1, | |||||
'sources': [ | |||||
# Valid source | |||||
{ | |||||
'type': 'url', | |||||
'urls': ['my-url'], | |||||
'integrity': 'my-integrity' | |||||
}, | |||||
# integrity is missing | |||||
{ | |||||
'type': 'url', | |||||
'urls': ['my-url'], | |||||
}, | |||||
# urls is not a list | |||||
{ | |||||
'type': 'url', | |||||
'urls': 'my-url', | |||||
'integrity': 'my-integrity' | |||||
}, | |||||
# type is not url | |||||
{ | |||||
'type': 'git', | |||||
'urls': ['my-url'], | |||||
'integrity': 'my-integrity' | |||||
} | |||||
], | |||||
'revision': 'my-revision' | |||||
} | |||||
clean = clean_sources(sources) | |||||
assert len(clean['sources']) == 1 | |||||
def test_loader_one_visit(swh_config, requests_mock_datadir): | def test_loader_one_visit(swh_config, requests_mock_datadir): | ||||
loader = NixGuixLoader(sources_url) | loader = NixGuixLoader(sources_url) | ||||
res = loader.load() | res = loader.load() | ||||
assert res['status'] == 'eventful' | assert res['status'] == 'eventful' | ||||
stats = get_stats(loader.storage) | stats = get_stats(loader.storage) | ||||
assert { | assert { | ||||
'content': 1, | 'content': 1, | ||||
▲ Show 20 Lines • Show All 236 Lines • Show Last 20 Lines |
you can add: