File: test_cal_address.py

package info (click to toggle)
python-ical 12.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,776 kB
  • sloc: python: 15,157; sh: 9; makefile: 5
file content (63 lines) | stat: -rw-r--r-- 2,067 bytes parent folder | download
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Tests for RELATED-TO data types."""

from pydantic import field_serializer
import pytest
from ical.exceptions import CalendarParseError

from ical.component import ComponentModel
from ical.parsing.component import ParsedComponent
from ical.parsing.property import ParsedProperty, ParsedPropertyParameter
from ical.types import CalAddress, Role
from ical.types.data_types import serialize_field


class FakeModel(ComponentModel):
    """Model under test."""

    example: CalAddress

    serialize_fields = field_serializer("*")(serialize_field)  # type: ignore[pydantic-field]


def test_caladdress_role() -> None:
    """Test for no explicit reltype specified."""
    model = FakeModel.model_validate(
        {
            "example": [
                ParsedProperty(
                    name="attendee",
                    value="mailto:mrbig@example.com",
                    params=[
                        ParsedPropertyParameter(name="ROLE", values=["CHAIR"]),
                        ParsedPropertyParameter(name="CUTYPE", values=["INDIVIDUAL"]),
                    ],
                )
            ]
        },
    )
    assert model.example
    assert model.example.uri == "mailto:mrbig@example.com"
    assert model.example.role == Role.CHAIR
    assert model.example.user_type == "INDIVIDUAL"


def test_caladdress_role_parse_failure() -> None:
    """Test for no explicit reltype specified."""
    model = FakeModel.model_validate(
        {
            "example": [
                ParsedProperty(
                    name="attendee",
                    value="mailto:mrbig@example.com",
                    params=[
                        ParsedPropertyParameter(name="ROLE", values=["OTHER-ROLE"]),
                        ParsedPropertyParameter(name="CUTYPE", values=["OTHER-CUTYPE"]),
                    ],
                )
            ]
        },
    )
    assert model.example
    assert model.example.uri == "mailto:mrbig@example.com"
    assert model.example.role == "OTHER-ROLE"
    assert model.example.user_type == "OTHER-CUTYPE"