2024-05-20 08:44:52 +00:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import pytest
|
|
|
|
from jsonschema import validate
|
|
|
|
|
2024-05-20 20:30:08 +00:00
|
|
|
def test_validate_manifest_against_local_schema():
|
|
|
|
"""Ensures that the manifest matches the local schema, for situations where the schema is being changed."""
|
|
|
|
json_relative: str = '../sherlock/resources/data.json'
|
|
|
|
schema_relative: str = '../sherlock/resources/data.schema.json'
|
|
|
|
|
|
|
|
json_path: str = os.path.join(os.path.dirname(__file__), json_relative)
|
|
|
|
schema_path: str = os.path.join(os.path.dirname(__file__), schema_relative)
|
|
|
|
|
|
|
|
with open(json_path, 'r') as f:
|
2024-05-20 08:44:52 +00:00
|
|
|
jsondat = json.load(f)
|
2024-05-20 20:30:08 +00:00
|
|
|
with open(schema_path, 'r') as f:
|
2024-05-20 08:44:52 +00:00
|
|
|
schemadat = json.load(f)
|
2024-05-20 20:30:08 +00:00
|
|
|
|
2024-05-20 08:44:52 +00:00
|
|
|
validate(instance=jsondat, schema=schemadat)
|
|
|
|
|
2024-05-20 20:30:08 +00:00
|
|
|
|
|
|
|
def test_validate_manifest_against_remote_schema(remote_schema):
|
|
|
|
"""Ensures that the manifest matches the remote schema, so as to not unexpectedly break clients."""
|
2024-05-20 08:44:52 +00:00
|
|
|
json_relative: str = '../sherlock/resources/data.json'
|
|
|
|
json_path: str = os.path.join(os.path.dirname(__file__), json_relative)
|
2024-05-20 20:30:08 +00:00
|
|
|
|
|
|
|
with open(json_path, 'r') as f:
|
|
|
|
jsondat = json.load(f)
|
|
|
|
|
|
|
|
validate(instance=jsondat, schema=remote_schema)
|
2024-05-20 08:44:52 +00:00
|
|
|
|
|
|
|
# Ensure that the expected values are beind returned by the site list
|
|
|
|
@pytest.mark.parametrize("target_name,target_expected_err_type", [
|
|
|
|
('GitHub', 'status_code'),
|
|
|
|
('GitLab', 'message'),
|
|
|
|
])
|
|
|
|
def test_site_list_iterability (sites_info, target_name, target_expected_err_type):
|
|
|
|
assert sites_info[target_name]['errorType'] == target_expected_err_type
|