ttvdrops/chzzk/tests/test_schemas.py
Joakim Hellsén 596769874f
All checks were successful
Deploy to Server / deploy (pull_request) Successful in 13s
Deploy to Server / deploy (push) Successful in 21s
Remove references to ChzzkApiResponseV1 in schema tests and update test cases to use ChzzkApiResponseV2
2026-04-01 04:05:59 +02:00

37 lines
1 KiB
Python

import json
from pathlib import Path
import pydantic
import pytest
from chzzk.schemas import ChzzkApiResponseV2
TESTS_DIR = Path(__file__).parent
@pytest.mark.parametrize(
("fname", "data_model"),
[
("v2_905.json", ChzzkApiResponseV2),
],
)
def test_chzzk_schema_strict(fname: str, data_model: type) -> None:
"""Test that the schema strictly validates the given JSON file against the provided Pydantic model."""
with Path(TESTS_DIR / fname).open(encoding="utf-8") as f:
data = json.load(f)
# Should not raise
data_model.model_validate(data)
@pytest.mark.parametrize(
("fname", "data_model"),
[
("v1_905.json", ChzzkApiResponseV2),
],
)
def test_chzzk_schema_cross_fail(fname: str, data_model: type) -> None:
"""Test that the schema fails when validating the wrong JSON file/model combination."""
with Path(TESTS_DIR / fname).open(encoding="utf-8") as f:
data = json.load(f)
with pytest.raises(pydantic.ValidationError):
data_model.model_validate(data)