Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/tests/test_scanner.py
- This file was added.
# Copyright (C) 2020 The Software Heritage developers | |||||
# See the AUTHORS file at the top-level directory of this distribution | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
import pytest | |||||
import json | |||||
from pathlib import PosixPath | |||||
from .data import correct_api_response | |||||
from swh.scanner.scanner import pids_discovery, get_subpaths, run | |||||
from swh.scanner.model import Tree | |||||
from swh.scanner.exceptions import APIError | |||||
aio_url = 'http://example.org/api/known/' | |||||
vlorentz: Use "example.org" or one of its subdomains as domain, it avoids using a domain that belongs to… | |||||
def test_scanner_correct_api_request(mock_aioresponse, event_loop, aiosession): | |||||
mock_aioresponse.post(aio_url, status=200, content_type='application/json', | |||||
body=json.dumps(correct_api_response)) | |||||
actual_result = event_loop.run_until_complete( | |||||
pids_discovery([], aiosession, 'http://example.org/api/')) | |||||
assert correct_api_response == actual_result | |||||
def test_scanner_raise_apierror(mock_aioresponse, event_loop, aiosession): | |||||
mock_aioresponse.post(aio_url, content_type='application/json', | |||||
status=413) | |||||
with pytest.raises(APIError): | |||||
event_loop.run_until_complete( | |||||
pids_discovery([], aiosession, 'http://example.org/api/')) | |||||
def test_scanner_get_subpaths(tmp_path, temp_paths): | |||||
for subpath, pid in get_subpaths(tmp_path): | |||||
assert subpath in temp_paths['paths'] | |||||
assert pid in temp_paths['pids'] | |||||
@pytest.mark.options(debug=False) | |||||
def test_app(app): | |||||
assert not app.debug | |||||
Done Inline Actionsdef test_app(app): """Ensures the app not in debug mode""" assert not app.debug The second argument of assert is a message to be displayed on error, not a comment. vlorentz: ```
def test_app(app):
"""Ensures the app not in debug mode"""
assert not app.debug
```… | |||||
def test_scanner_result(live_server, event_loop, test_folder): | |||||
live_server.start() | |||||
api_url = live_server.url() + '/' | |||||
result_path = test_folder.joinpath(PosixPath('sample-folder-result.json')) | |||||
with open(result_path, 'r') as json_file: | |||||
expected_result = json.loads(json_file.read()) | |||||
sample_folder = test_folder.joinpath(PosixPath('sample-folder')) | |||||
source_tree = Tree(sample_folder) | |||||
event_loop.run_until_complete( | |||||
run(sample_folder, api_url, source_tree)) | |||||
actual_result = source_tree.getJsonTree() | |||||
assert actual_result == expected_result |
Use "example.org" or one of its subdomains as domain, it avoids using a domain that belongs to someone.