|
@@ -16,7 +16,9 @@
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
import copy
|
|
|
+import os
|
|
|
import pathlib
|
|
|
+import unittest.mock
|
|
|
|
|
|
import icalendar.cal
|
|
|
import pytest
|
|
@@ -49,6 +51,16 @@ END:VEVENT
|
|
|
# pylint: disable=protected-access
|
|
|
|
|
|
|
|
|
+def test__write_event_cleanup(tmpdir):
|
|
|
+ event = icalendar.cal.Event.from_ical(_SINGLE_EVENT_ICAL)
|
|
|
+ with unittest.mock.patch("os.unlink") as unlink_mock:
|
|
|
+ with pytest.raises(IsADirectoryError):
|
|
|
+ ical2vdir._write_event(event, pathlib.Path(tmpdir))
|
|
|
+ unlink_mock.assert_called_once()
|
|
|
+ unlink_args, _ = unlink_mock.call_args
|
|
|
+ os.unlink(unlink_args[0])
|
|
|
+
|
|
|
+
|
|
|
@pytest.mark.parametrize(
|
|
|
("event_ical", "expected_filename"),
|
|
|
[
|
|
@@ -80,22 +92,22 @@ def test__event_vdir_filename(event_ical, expected_filename):
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("event_ical", [_SINGLE_EVENT_ICAL])
|
|
|
-def test__export_event_create(tmpdir, event_ical):
|
|
|
+def test__sync_event_create(tmpdir, event_ical):
|
|
|
temp_path = pathlib.Path(tmpdir)
|
|
|
event = icalendar.cal.Event.from_ical(event_ical)
|
|
|
- ical2vdir._export_event(event, temp_path)
|
|
|
+ ical2vdir._sync_event(event, temp_path)
|
|
|
(ics_path,) = temp_path.iterdir()
|
|
|
assert ics_path.name == "1qa2ws3ed4rf5tg@google.com.ics"
|
|
|
assert ics_path.read_bytes() == _SINGLE_EVENT_ICAL
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("event_ical", [_SINGLE_EVENT_ICAL])
|
|
|
-def test__export_event_update(tmpdir, event_ical):
|
|
|
+def test__sync_event_update(tmpdir, event_ical):
|
|
|
temp_path = pathlib.Path(tmpdir)
|
|
|
event = icalendar.cal.Event.from_ical(event_ical)
|
|
|
- ical2vdir._export_event(event, temp_path)
|
|
|
+ ical2vdir._sync_event(event, temp_path)
|
|
|
event["SUMMARY"] += " suffix"
|
|
|
- ical2vdir._export_event(event, temp_path)
|
|
|
+ ical2vdir._sync_event(event, temp_path)
|
|
|
(ics_path,) = temp_path.iterdir()
|
|
|
assert ics_path.name == event["UID"] + ".ics"
|
|
|
assert ics_path.read_bytes() == _SINGLE_EVENT_ICAL.replace(
|
|
@@ -104,12 +116,12 @@ def test__export_event_update(tmpdir, event_ical):
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("event_ical", [_SINGLE_EVENT_ICAL])
|
|
|
-def test__export_event_unchanged(tmpdir, event_ical):
|
|
|
+def test__sync_event_unchanged(tmpdir, event_ical):
|
|
|
temp_path = pathlib.Path(tmpdir)
|
|
|
event = icalendar.cal.Event.from_ical(event_ical)
|
|
|
- ical2vdir._export_event(event, temp_path)
|
|
|
+ ical2vdir._sync_event(event, temp_path)
|
|
|
(ics_path,) = temp_path.iterdir()
|
|
|
old_stat = copy.deepcopy(ics_path.stat())
|
|
|
- ical2vdir._export_event(event, temp_path)
|
|
|
+ ical2vdir._sync_event(event, temp_path)
|
|
|
assert ics_path.stat() == old_stat
|
|
|
assert ics_path.read_bytes() == _SINGLE_EVENT_ICAL
|