Browse Source

added integration test

Fabian Peter Hammerle 4 years ago
parent
commit
7ecc72bcb4
3 changed files with 120 additions and 0 deletions
  1. 32 0
      tests/cli_test.py
  2. 18 0
      tests/conftest.py
  3. 70 0
      tests/resources/google-calendar.ics

+ 32 - 0
tests/cli_test.py

@@ -0,0 +1,32 @@
+import io
+import pathlib
+import subprocess
+import unittest.mock
+
+import icalendar
+
+import ics2vdir
+
+# pylint: disable=protected-access
+
+
+def test_entrypoint_help():
+    subprocess.run(["ics2vdir", "--help"], check=True, stdout=subprocess.PIPE)
+
+
+def test__main_create(
+    temp_dir_path: pathlib.Path, google_calendar_file: io.BufferedReader
+):
+    with unittest.mock.patch("sys.stdin", google_calendar_file):
+        with unittest.mock.patch("sys.argv", ["", "--output-dir", str(temp_dir_path)]):
+            ics2vdir._main()
+    created_item_paths = sorted(temp_dir_path.iterdir())
+    assert [p.name for p in created_item_paths] == [
+        "1234567890qwertyuiopasdfgh@google.com.ics",
+        "recurr1234567890qwertyuiop@google.com.20150908T090000+0200.ics",
+        "recurr1234567890qwertyuiop@google.com.20150924T090000+0200.ics",
+    ]
+    event = icalendar.cal.Event.from_ical(created_item_paths[1].read_bytes())
+    assert isinstance(event, icalendar.cal.Event)
+    assert event["UID"] == "recurr1234567890qwertyuiop@google.com"
+    assert event["SUMMARY"] == "recurring"

+ 18 - 0
tests/conftest.py

@@ -0,0 +1,18 @@
+import io
+import pathlib
+import typing
+
+import pytest
+
+
+@pytest.fixture
+def temp_dir_path(tmpdir) -> pathlib.Path:
+    return pathlib.Path(tmpdir)
+
+
+@pytest.fixture
+def google_calendar_file() -> typing.Iterator[io.BufferedReader]:
+    with pathlib.Path(__file__).parent.joinpath(
+        "resources", "google-calendar.ics"
+    ).open("rb") as file:
+        yield typing.cast(io.BufferedReader, file)

+ 70 - 0
tests/resources/google-calendar.ics

@@ -0,0 +1,70 @@
+BEGIN:VCALENDAR
+PRODID:-//Google Inc//Google Calendar 70.9054//EN
+VERSION:2.0
+CALSCALE:GREGORIAN
+METHOD:PUBLISH
+X-WR-CALNAME:personal
+X-WR-TIMEZONE:Europe/Vienna
+BEGIN:VTIMEZONE
+TZID:Europe/Vienna
+X-LIC-LOCATION:Europe/Vienna
+BEGIN:DAYLIGHT
+TZOFFSETFROM:+0100
+TZOFFSETTO:+0200
+TZNAME:CEST
+DTSTART:19700329T020000
+RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
+END:DAYLIGHT
+BEGIN:STANDARD
+TZOFFSETFROM:+0200
+TZOFFSETTO:+0100
+TZNAME:CET
+DTSTART:19701025T030000
+RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
+END:STANDARD
+END:VTIMEZONE
+BEGIN:VEVENT
+DTSTART:20201024T100000Z
+DTEND:20201026T120000Z
+DTSTAMP:20200205T160640Z
+UID:1234567890qwertyuiopasdfgh@google.com
+CREATED:20191231T103841Z
+DESCRIPTION:
+LAST-MODIFIED:20191231T103841Z
+LOCATION:
+SEQUENCE:0
+STATUS:CONFIRMED
+SUMMARY:simple
+TRANSP:OPAQUE
+END:VEVENT
+BEGIN:VEVENT
+DTSTART;TZID=Europe/Vienna:20150924T090000
+DTEND;TZID=Europe/Vienna:20150924T123000
+DTSTAMP:20200205T160640Z
+UID:recurr1234567890qwertyuiop@google.com
+RECURRENCE-ID;TZID=Europe/Vienna:20150924T090000
+CREATED:20140228T212925Z
+DESCRIPTION:
+LAST-MODIFIED:20150908T181423Z
+LOCATION:
+SEQUENCE:5
+STATUS:CONFIRMED
+SUMMARY:recurring
+TRANSP:TRANSPARENT
+END:VEVENT
+BEGIN:VEVENT
+DTSTART;TZID=Europe/Vienna:20150908T080000
+DTEND;TZID=Europe/Vienna:20150908T163000
+DTSTAMP:20200205T160640Z
+UID:recurr1234567890qwertyuiop@google.com
+RECURRENCE-ID;TZID=Europe/Vienna:20150908T090000
+CREATED:20140228T212925Z
+DESCRIPTION:
+LAST-MODIFIED:20150908T181423Z
+LOCATION:
+SEQUENCE:7
+STATUS:CONFIRMED
+SUMMARY:recurring
+TRANSP:TRANSPARENT
+END:VEVENT
+END:VCALENDAR