• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

andy-goellner / pco-python-sdk / 12967109248

25 Jan 2025 05:43PM UTC coverage: 80.57% (-0.3%) from 80.84%
12967109248

Pull #8

github

web-flow
Merge f32dcbab7 into 9a0a02ce3
Pull Request #8: feat: Adding support for dynamic attributes in pco objects

8 of 8 new or added lines in 2 files covered. (100.0%)

2 existing lines in 1 file now uncovered.

311 of 386 relevant lines covered (80.57%)

2.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.58
/src/planning_center_python/models/pco_object.py
1
from collections.abc import Mapping
3✔
2
from typing import Any, ClassVar, Optional, cast
3✔
3
from planning_center_python.errors import (
3✔
4
    InvalidParamsError,
5
    InvalidRequestError,
6
    NoAttributesDefinedError,
7
)
8

9

10
class PCOObject:
3✔
11
    """Base class object from which all Planning Center objects should inherit from"""
12

13
    OBJECT_TYPE: ClassVar[str] = "BaseClass"
3✔
14

15
    def __init__(self, data: Mapping[str, Any] = {}, id: Optional[str] = None):
3✔
16
        self._data = data
3✔
17
        object_data = cast(Mapping[str, Any], data.get("data")) or {}
3✔
18
        self._id = id or object_data.get("id")
3✔
19
        self._type = object_data.get("type") or self.OBJECT_TYPE
3✔
20
        self._validate()
3✔
21
        self.attributes = object_data.get("attributes")
3✔
22

23
    def get_attribute(self, name: str) -> Any:
3✔
24
        if not self.attributes:
3✔
25
            raise NoAttributesDefinedError
3✔
26
        return self.attributes.get(name)
3✔
27

28
    def _object_url(self) -> str:
3✔
29
        raise NotImplementedError
×
30

31
    def _instance_url(self) -> str:
3✔
32
        if not self.id:
3✔
33
            raise InvalidRequestError(
×
34
                "Cannot determine instance url without a valid id"
35
            )
36

37
        return "%s/%s" % (self._object_url(), self.id)
3✔
38

39
    def _validate(self):
3✔
40
        if not self.id:
3✔
41
            raise InvalidParamsError(self, "id")
×
42
        if not self.type:
3✔
43
            raise InvalidParamsError(self, "type")
×
44
        if self.type != self.OBJECT_TYPE:
3✔
45
            raise InvalidParamsError(self, "type", "Class types do not match")
×
46

47
    def _init_attributes(self, attributes: Mapping[str, Any]):
3✔
UNCOV
48
        for key, val in attributes.items():
×
UNCOV
49
            setattr(self, key, val)
×
50

51
    @property
3✔
52
    def id(self) -> str | None:
3✔
53
        return self._id
3✔
54

55
    @property
3✔
56
    def type(self) -> str | None:
3✔
57
        return self._type
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc