Browse Source

fix _event_prop_equal: add missing params check

Fabian Peter Hammerle 4 years ago
parent
commit
907fd47b3d
2 changed files with 69 additions and 1 deletions
  1. 1 1
      ics2vdir/__init__.py
  2. 68 0
      tests/prop_test.py

+ 1 - 1
ics2vdir/__init__.py

@@ -46,7 +46,7 @@ def _event_prop_equal(prop_a, prop_b) -> bool:
     if isinstance(prop_a, (icalendar.prop.vDDDTypes, icalendar.prop.vCategory)):
         # pylint: disable=unidiomatic-typecheck
         return type(prop_a) == type(prop_b) and vars(prop_a) == vars(prop_b)
-    return prop_a == prop_b
+    return prop_a == prop_b and prop_a.params == prop_b.params
 
 
 def _events_equal(event_a: icalendar.cal.Event, event_b: icalendar.cal.Event) -> bool:

+ 68 - 0
tests/prop_test.py

@@ -1,10 +1,19 @@
 import datetime
+import typing
 
 import pytest
 from icalendar.prop import vCalAddress, vDDDLists, vDDDTypes, vInt, vRecur, vText
 
 from ics2vdir import _event_prop_equal
 
+_CEST = datetime.timezone(datetime.timedelta(hours=+2))
+
+
+def _parametrize(obj: typing.Any, params: dict) -> typing.Any:
+    for key, value in params.items():
+        obj.params.__setitem__(key, value)
+    return obj
+
 
 @pytest.mark.parametrize(
     ("prop_a", "prop_b", "expected_result"),
@@ -36,6 +45,15 @@ from ics2vdir import _event_prop_equal
             ),
             True,
         ),
+        (
+            vDDDTypes(
+                datetime.datetime(2012, 7, 3, 16, 39, 2, tzinfo=datetime.timezone.utc)
+            ),
+            vDDDTypes(datetime.datetime(2012, 7, 3, 18, 39, 2, tzinfo=_CEST)),
+            # logically that should be True
+            # but shouldn't hurt to update the ics file
+            False,
+        ),
         (
             vDDDTypes(
                 datetime.datetime(2012, 7, 3, 16, 39, 3, tzinfo=datetime.timezone.utc)
@@ -100,6 +118,56 @@ from ics2vdir import _event_prop_equal
             ),
             False,
         ),
+        (
+            vCalAddress("someelse@somewhere.com"),
+            _parametrize(
+                vCalAddress("someelse@somewhere.com"),
+                dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
+            ),
+            False,
+        ),
+        (
+            _parametrize(
+                vCalAddress("someelse@somewhere.com"),
+                dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
+            ),
+            _parametrize(
+                vCalAddress("someelse@somewhere.com"),
+                dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
+            ),
+            True,
+        ),
+        (
+            [
+                vCalAddress("someone@somewhere.com",),
+                vCalAddress("someelse@somewhere.com"),
+            ],
+            [
+                vCalAddress("someone@somewhere.com",),
+                _parametrize(
+                    vCalAddress("someelse@somewhere.com"),
+                    dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
+                ),
+            ],
+            False,
+        ),
+        (
+            [
+                vCalAddress("someone@somewhere.com",),
+                _parametrize(
+                    vCalAddress("someelse@somewhere.com"),
+                    dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
+                ),
+            ],
+            [
+                vCalAddress("someone@somewhere.com",),
+                _parametrize(
+                    vCalAddress("someelse@somewhere.com"),
+                    dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
+                ),
+            ],
+            True,
+        ),
     ],
 )
 def test__event_prop_equal(prop_a, prop_b, expected_result):