1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
"""Tests for BOOLEAN data types."""
import pytest
from ical.component import ComponentModel
from ical.exceptions import CalendarParseError
from ical.parsing.property import ParsedProperty
class FakeModel(ComponentModel):
"""Model under test."""
example: bool
def test_bool() -> None:
"""Test for boolean fields."""
model = FakeModel.parse_obj(
{"example": [ParsedProperty(name="example", value="TRUE")]}
)
assert model.example
model = FakeModel.parse_obj(
{"example": [ParsedProperty(name="example", value="FALSE")]}
)
assert not model.example
with pytest.raises(CalendarParseError):
FakeModel.parse_obj({"example": [ParsedProperty(name="example", value="efd")]})
# Populate based on bool object
model = FakeModel(example=True)
assert model.example
component = model.__encode_component_root__()
assert component.properties == [
ParsedProperty(name="example", value="TRUE"),
]
model = FakeModel(example=False)
assert not model.example
component = model.__encode_component_root__()
assert component.properties == [
ParsedProperty(name="example", value="FALSE"),
]
|