Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: allenporter/gcal_sync
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.8.1
Choose a base ref
...
head repository: allenporter/gcal_sync
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.9.0
Choose a head ref
  • 3 commits
  • 6 files changed
  • 2 contributors

Commits on May 20, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    943ac90 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1131503 View commit details
  3. Release 0.9.0

    allenporter committed May 20, 2022
    Copy the full SHA
    1258ad4 View commit details
Showing with 50 additions and 3 deletions.
  1. +9 −1 gcal_sync/api.py
  2. +1 −1 gcal_sync/model.py
  3. +1 −1 setup.cfg
  4. +1 −0 tests/conftest.py
  5. +20 −0 tests/test_api.py
  6. +18 −0 tests/test_model.py
10 changes: 9 additions & 1 deletion gcal_sync/api.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,9 @@
# pylint: disable=line-too-long
EVENT_API_FIELDS = f"kind,nextPageToken,nextSyncToken,items({EVENT_FIELDS})"

CALENDAR_ID = "calendarId"
CALENDAR_LIST_URL = "users/me/calendarList"
CALENDAR_GET_URL = "calendars/{calendar_id}"
CALENDAR_EVENTS_URL = "calendars/{calendar_id}/events"


@@ -153,10 +155,16 @@ async def async_list_calendars(
params = {}
if request:
params = json.loads(request.json(exclude_none=True, by_alias=True))
_LOGGER.debug(params)
result = await self._auth.get_json(CALENDAR_LIST_URL, params=params)
return CalendarListResponse.parse_obj(result)

async def async_get_calendar(self, calendar_id: str) -> Calendar:
"""Return the calendar with the specified id."""
result = await self._auth.get_json(
CALENDAR_GET_URL.format(calendar_id=calendar_id)
)
return Calendar.parse_obj(result)

async def async_create_event(
self,
calendar_id: str,
2 changes: 1 addition & 1 deletion gcal_sync/model.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ class Calendar(BaseModel):
summary: str = ""
description: Optional[str]
location: Optional[str]
timezone: Optional[str]
timezone: Optional[str] = Field(alias="timeZone")


class DateOrDatetime(BaseModel):
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = gcal-sync
version = 0.8.1
version = 0.9.0
description = A python library for syncing Google Calendar to local storage for use in Home Assistant
long_description = file: README.md
long_description_content_type = text/markdown
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -83,6 +83,7 @@ def mock_app() -> aiohttp.web.Application:
app["request-json"] = []
app["request-post"] = []
app.router.add_get("/users/me/calendarList", handler)
app.router.add_get("/calendars/{calendarId}", handler)
app.router.add_get("/calendars/{calendarId}/events", handler)
app.router.add_post("/calendars/{calendarId}/events", handler)
return app
20 changes: 20 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -16,6 +16,26 @@
)


async def test_get_calendar(
calendar_service_cb: Callable[[], Awaitable[GoogleCalendarService]],
json_response: ApiResult,
url_request: Callable[[], str],
) -> None:
"""Test list calendars API."""

json_response(
{
"id": "calendar-id-1",
"summary": "Calendar 1",
},
)
calendar_service = await calendar_service_cb()
result = await calendar_service.async_get_calendar("primary")
assert result == Calendar(id="calendar-id-1", summary="Calendar 1")

assert url_request() == ["/calendars/primary"]


async def test_list_calendars(
calendar_service_cb: Callable[[], Awaitable[GoogleCalendarService]],
json_response: ApiResult,
18 changes: 18 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
@@ -37,6 +37,24 @@ def test_calendar() -> None:
assert calendar.timezone is None


def test_calendar_timezone() -> None:
"""Exercise basic parsing of a calendar API response."""

calendar = Calendar.parse_obj(
{
"kind": "calendar#calendarListEntry",
"id": "some-calendar-id",
"summary": "Calendar summary",
"timeZone": "America/Los_Angeles",
}
)
assert calendar.id == "some-calendar-id"
assert calendar.summary == "Calendar summary"
assert calendar.description is None
assert calendar.location is None
assert calendar.timezone == "America/Los_Angeles"


def test_event_with_date() -> None:
"""Exercise basic parsing of an event API response."""