Add Chzzk campaign and reward models, import command, and schemas
Some checks failed
Deploy to Server / deploy (push) Failing after 19s
Some checks failed
Deploy to Server / deploy (push) Failing after 19s
This commit is contained in:
parent
c852134338
commit
677aedf42b
14 changed files with 650 additions and 9 deletions
40
chzzk/tests/test_schemas.py
Normal file
40
chzzk/tests/test_schemas.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pydantic
|
||||
import pytest
|
||||
|
||||
from chzzk.schemas import ChzzkApiResponseV1
|
||||
from chzzk.schemas import ChzzkApiResponseV2
|
||||
|
||||
TESTS_DIR = Path(__file__).parent
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("fname", "data_model"),
|
||||
[
|
||||
("v1_905.json", ChzzkApiResponseV1),
|
||||
("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),
|
||||
("v2_905.json", ChzzkApiResponseV1),
|
||||
],
|
||||
)
|
||||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue