Skip to content

Commit

Permalink
Update test_pkg_config based on commit's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianBracq committed Sep 5, 2023
1 parent 2830580 commit 1c6bc58
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions tests/common/test_pkg_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,21 @@
from pathlib import Path

import httpx
from jsonschema import Draft7Validator
import pytest
import pytest_check as check
import yaml

from msticpy.common import pkg_config
from msticpy.context.geoip import GeoLiteLookup, IPStackLookup

from ..unit_test_lib import custom_mp_config, get_test_data_path, get_queries_schema
from ..unit_test_lib import custom_mp_config, get_test_data_path
from ..data.queries.test_query_files import validate_queries_file_structure

_TEST_DATA = get_test_data_path()
_QUERIES_SCHEMA = get_queries_schema()

# pylint: disable=protected-access


def validate_queries_file_structure(query_file: Path, expected: bool = True):
"""Test if query files have a valid structure."""
with query_file.open(mode="r", encoding="utf-8") as queries:
queries_yaml = yaml.safe_load(queries)
if expected:
check.is_true(
Draft7Validator(_QUERIES_SCHEMA).is_valid(queries_yaml),
msg=f"File {query_file} is not a valid query file",
)
else:
check.is_false(
Draft7Validator(_QUERIES_SCHEMA).is_valid(queries_yaml),
msg=f"File {query_file} was expected to be invalid but is a valid query file",
)


def test_load_default():
"""Test load default settings."""
settings = pkg_config._settings
Expand All @@ -62,15 +45,8 @@ def test_load_default():
path = Path(__file__).resolve().parent.parent.joinpath(path)
check.is_true(path.is_dir())
for query_file in Path(path).resolve().rglob("*.yaml"):
validate_queries_file_structure(
query_file,
expected=not (
"fail" in query_file.name
or "msticpyconfig" in query_file.name
or "sentinel_query_import_data"
in [parent.name for parent in query_file.absolute().parents]
),
)
if "tests" not in [parent.name for parent in query_file.absolute().parents]:
validate_queries_file_structure(query_file)


def test_custom_config():
Expand Down

0 comments on commit 1c6bc58

Please sign in to comment.