Skip to content

Commit

Permalink
Merge pull request #128 from elliot-100/118-add-event-attributes
Browse files Browse the repository at this point in the history
Add new `Event` attributes/properties
  • Loading branch information
elliot-100 authored Jul 13, 2024
2 parents 473f9e7 + 76ae9a0 commit 1584dbe
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`. 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
Expand Down
3 changes: 2 additions & 1 deletion spond_classes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

# 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
from .subgroup import Subgroup

__all__ = [
"Event",
"EventType",
"Group",
"Member",
"Role",
Expand Down
28 changes: 27 additions & 1 deletion spond_classes/event.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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}/"
11 changes: 9 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,18 @@ def simple_event_data() -> dict:
Item from 'events' (root).
"""
return {
"id": "A390CE5396D2F5C3015F53E171EC59D5",
"id": "E001",
"heading": "Event 1",
"type": "EVENT",
"responses": {
"acceptedIds": [],
"declinedIds": [],
"unansweredIds": [],
"waitinglistIds": [],
"unconfirmedIds": [],
},
"createdTime": "2020-12-31T19:00:00Z",
"endTimestamp": "2024-08-15T11:00:00Z",
"startTimestamp": "2021-07-06T06:00:00Z",
}

Expand All @@ -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",
Expand All @@ -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",
}
19 changes: 14 additions & 5 deletions tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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, "
"…)"
Expand All @@ -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",
]
Expand All @@ -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, "
"…)"
Expand Down

0 comments on commit 1584dbe

Please sign in to comment.