From 45eac6a899b8c4cc51e6480832d341c6e9b92b46 Mon Sep 17 00:00:00 2001 From: Elliot <3186037+elliot-100@users.noreply.github.com> Date: Tue, 2 Jul 2024 14:05:38 +0100 Subject: [PATCH 1/2] Add `Event` attributes: `cancelled`, `created_time`, `end_time`, `invite_time`, `type` and property `url`; add `EventType` to public API --- CHANGELOG.md | 8 +++++++- spond_classes/__init__.py | 3 ++- spond_classes/event.py | 28 +++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e33a52..236e9ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,16 @@ Historic and pre-release versions aren't necessarily included. ## UNRELEASED - TBC +### Added + +- `Event` attributes: `cancelled`, `created_time`, `end_time`, `invite_time`, `type`, + property `url`. Tests and docs pending. + ### Changed - Consistent pattern for all classes' string representation, including full `uid` -- Dependencies: remove upper bounds for simplicity +- Dependencies: remove upper bounds for simplicity; drop redundant python-dateutil +- Dev dependencies: drop redundant types-python-dateutil ## [0.10.1] - 2024-07-02 diff --git a/spond_classes/__init__.py b/spond_classes/__init__.py index bd9b48a..9217c9e 100644 --- a/spond_classes/__init__.py +++ b/spond_classes/__init__.py @@ -2,7 +2,7 @@ # Explicitly import all classes and functions into the package namespace. -from .event import Event +from .event import Event, EventType from .group import Group from .member import Member from .role import Role @@ -10,6 +10,7 @@ __all__ = [ "Event", + "EventType", "Group", "Member", "Role", diff --git a/spond_classes/event.py b/spond_classes/event.py index 18d9832..6f92e95 100644 --- a/spond_classes/event.py +++ b/spond_classes/event.py @@ -1,6 +1,7 @@ -"""Module containing `Event` class and nested `Responses` class.""" +"""Module containing `Event` class and nested `EventType`,`Responses` classes.""" from datetime import datetime +from enum import Enum from pydantic import BaseModel, Field @@ -21,6 +22,13 @@ class Responses(BaseModel): """`unconfirmedIds` in API.""" +class EventType(Enum): + """Represents the kind of `Event`.""" + + EVENT = "EVENT" + RECURRING = "RECURRING" + + class Event(BaseModel): """Represents an event in the Spond system. @@ -32,10 +40,23 @@ class Event(BaseModel): uses `uid`.""" heading: str responses: Responses + type: EventType + created_time: datetime = Field(alias="createdTime") + """Derived from `createdTime` in API.""" + end_time: datetime = Field(alias="endTimestamp") + """Datetime at which the `Event` ends. + Derived from `endTimestamp` in API.""" start_time: datetime = Field(alias="startTimestamp") """Datetime at which the `Event` starts. Derived from `startTimestamp` in API.""" + # Optional in API data + cancelled: bool | None = Field(default=None) + """Optional.""" + invite_time: datetime | None = Field(alias="inviteTime", default=None) + """Optional. + Derived from `inviteTime` in API.""" + def __str__(self) -> str: """Return simple human-readable description. @@ -48,3 +69,8 @@ def __str__(self) -> str: f"start_time: {start_time_tag}," f" …)" ) + + @property + def url(self) -> str: + """Return the URL of the `Event`.""" + return f"https://spond.com/client/sponds/{self.uid}/" From 76ae9a045dfb10a4965eabdd03cf1ae86b3ba2c8 Mon Sep 17 00:00:00 2001 From: Elliot <3186037+elliot-100@users.noreply.github.com> Date: Sat, 13 Jul 2024 21:52:13 +0100 Subject: [PATCH 2/2] Tests: add test for new `Event` attributes --- CHANGELOG.md | 2 +- tests/conftest.py | 11 +++++++++-- tests/test_event.py | 19 ++++++++++++++----- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 236e9ad..0b997dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ Historic and pre-release versions aren't necessarily included. ### Added - `Event` attributes: `cancelled`, `created_time`, `end_time`, `invite_time`, `type`, - property `url`. Tests and docs pending. + property `url`. Docs pending. ### Changed diff --git a/tests/conftest.py b/tests/conftest.py index 73cd56e..9e4d42e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -159,8 +159,9 @@ def simple_event_data() -> dict: Item from 'events' (root). """ return { - "id": "A390CE5396D2F5C3015F53E171EC59D5", + "id": "E001", "heading": "Event 1", + "type": "EVENT", "responses": { "acceptedIds": [], "declinedIds": [], @@ -168,6 +169,8 @@ def simple_event_data() -> dict: "waitinglistIds": [], "unconfirmedIds": [], }, + "createdTime": "2020-12-31T19:00:00Z", + "endTimestamp": "2024-08-15T11:00:00Z", "startTimestamp": "2021-07-06T06:00:00Z", } @@ -180,8 +183,10 @@ def complex_event_data() -> dict: Item from 'events' (root). """ return { - "id": "36D7F1A46EB2CDED4B6F22D400229822", + "id": "E002", + "cancelled": "True", "heading": "Event 2", + "type": "RECURRING", "responses": { "acceptedIds": [ "B24FA75A4CCBC63199A57361E88B0646", @@ -199,5 +204,7 @@ def complex_event_data() -> dict: "2D1BB37608F09511FD5F280D219DFD97", ], }, + "createdTime": "2019-04-24T19:00:00Z", + "endTimestamp": "2024-08-15T11:00:00Z", "startTimestamp": "2022-11-04T06:00:00Z", } diff --git a/tests/test_event.py b/tests/test_event.py index 989e60f..4e6e03e 100644 --- a/tests/test_event.py +++ b/tests/test_event.py @@ -2,7 +2,7 @@ from datetime import datetime, timezone -from spond_classes import Event +from spond_classes import Event, EventType def test_from_dict_simple(simple_event_data: dict) -> None: @@ -12,17 +12,21 @@ def test_from_dict_simple(simple_event_data: dict) -> None: """ my_event = Event(**simple_event_data) - assert my_event.uid == "A390CE5396D2F5C3015F53E171EC59D5" + assert my_event.uid == "E001" assert my_event.heading == "Event 1" + assert my_event.type is EventType.EVENT + assert my_event.url == "https://spond.com/client/sponds/E001/" assert my_event.responses.accepted_uids == [] assert my_event.responses.declined_uids == [] assert my_event.responses.unanswered_uids == [] assert my_event.responses.waiting_list_uids == [] assert my_event.responses.unconfirmed_uids == [] + assert my_event.created_time == datetime(2020, 12, 31, 19, 0, tzinfo=timezone.utc) + assert my_event.end_time == datetime(2024, 8, 15, 11, 0, tzinfo=timezone.utc) assert my_event.start_time == datetime(2021, 7, 6, 6, 0, tzinfo=timezone.utc) assert str(my_event) == ( "Event(" - "uid='A390CE5396D2F5C3015F53E171EC59D5', " + "uid='E001', " "heading='Event 1', " "start_time: 2021-07-06 06:00:00+00:00, " "…)" @@ -36,8 +40,11 @@ def test_from_dict_complex(complex_event_data: dict) -> None: """ my_event = Event(**complex_event_data) - assert my_event.uid == "36D7F1A46EB2CDED4B6F22D400229822" + assert my_event.uid == "E002" + assert my_event.cancelled is True assert my_event.heading == "Event 2" + assert my_event.type is EventType.RECURRING + assert my_event.url == "https://spond.com/client/sponds/E002/" assert my_event.responses.accepted_uids == [ "B24FA75A4CCBC63199A57361E88B0646", ] @@ -53,10 +60,12 @@ def test_from_dict_complex(complex_event_data: dict) -> None: assert my_event.responses.unconfirmed_uids == [ "2D1BB37608F09511FD5F280D219DFD97", ] + assert my_event.created_time == datetime(2019, 4, 24, 19, 0, tzinfo=timezone.utc) + assert my_event.end_time == datetime(2024, 8, 15, 11, 0, tzinfo=timezone.utc) assert my_event.start_time == datetime(2022, 11, 4, 6, 0, tzinfo=timezone.utc) assert str(my_event) == ( "Event(" - "uid='36D7F1A46EB2CDED4B6F22D400229822', " + "uid='E002', " "heading='Event 2', " "start_time: 2022-11-04 06:00:00+00:00, " "…)"