prop_test.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. # ical2vdir - convert .ics file to vdir directory
  2. #
  3. # Copyright (C) 2020 Fabian Peter Hammerle <fabian@hammerle.me>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. import datetime
  18. import typing
  19. import pytest
  20. from icalendar.prop import vCalAddress, vDDDLists, vDDDTypes, vInt, vRecur, vText
  21. from ical2vdir import _event_prop_equal
  22. _CEST = datetime.timezone(datetime.timedelta(hours=+2))
  23. def _parametrize(obj: typing.Any, params: dict) -> typing.Any:
  24. for key, value in params.items():
  25. obj.params.__setitem__(key, value)
  26. return obj
  27. @pytest.mark.parametrize(
  28. ("prop_a", "prop_b", "expected_result"),
  29. [
  30. (vText("CONFIRMED"), vText("CONFIRMED"), True),
  31. (vText("TENTATIVE"), vText("TENTATIVE"), True),
  32. (vText("CONFIRMED"), vText("TENTATIVE"), False),
  33. (vText("CONFIRMED"), vInt(0), False),
  34. (vInt(0), vInt(0), True),
  35. (vInt(0), vInt(21), False),
  36. (
  37. vCalAddress("mailto:someone@somewhere.com"),
  38. vCalAddress("mailto:someone@somewhere.com"),
  39. True,
  40. ),
  41. (
  42. vCalAddress("mailto:someone@somewhere.com"),
  43. vCalAddress("mailto:someelse@somewhere.com"),
  44. False,
  45. ),
  46. (vRecur(FREQ="WEEKLY", COUNT=21), vRecur(FREQ="WEEKLY", COUNT=21), True,),
  47. (vRecur(FREQ="WEEKLY", COUNT=21), vRecur(FREQ="WEEKLY", COUNT=42), False,),
  48. (
  49. vDDDTypes(
  50. datetime.datetime(2012, 7, 3, 16, 39, 2, tzinfo=datetime.timezone.utc)
  51. ),
  52. vDDDTypes(
  53. datetime.datetime(2012, 7, 3, 16, 39, 2, tzinfo=datetime.timezone.utc)
  54. ),
  55. True,
  56. ),
  57. (
  58. vDDDTypes(
  59. datetime.datetime(2012, 7, 3, 16, 39, 2, tzinfo=datetime.timezone.utc)
  60. ),
  61. vDDDTypes(datetime.datetime(2012, 7, 3, 18, 39, 2, tzinfo=_CEST)),
  62. # logically that should be True
  63. # but shouldn't hurt to update the ics file
  64. False,
  65. ),
  66. (
  67. vDDDTypes(
  68. datetime.datetime(2012, 7, 3, 16, 39, 3, tzinfo=datetime.timezone.utc)
  69. ),
  70. vDDDTypes(
  71. datetime.datetime(2012, 7, 3, 16, 39, 2, tzinfo=datetime.timezone.utc)
  72. ),
  73. False,
  74. ),
  75. (
  76. vDDDLists(
  77. [datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc)]
  78. ),
  79. vDDDLists(
  80. [datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc)]
  81. ),
  82. True,
  83. ),
  84. (
  85. vDDDLists(
  86. [
  87. datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),
  88. datetime.datetime(2020, 2, 5, 20, 5, tzinfo=datetime.timezone.utc),
  89. ]
  90. ),
  91. vDDDLists(
  92. [
  93. datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),
  94. datetime.datetime(2020, 2, 5, 20, 5, tzinfo=datetime.timezone.utc),
  95. ]
  96. ),
  97. True,
  98. ),
  99. (
  100. vDDDLists(
  101. [
  102. datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),
  103. datetime.datetime(2020, 2, 5, 20, 5, tzinfo=datetime.timezone.utc),
  104. ]
  105. ),
  106. vDDDLists(
  107. [
  108. datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),
  109. datetime.datetime(2020, 2, 5, 20, 7, tzinfo=datetime.timezone.utc),
  110. ]
  111. ),
  112. False,
  113. ),
  114. (
  115. vDDDLists(
  116. [
  117. datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),
  118. datetime.datetime(2020, 2, 5, 20, 5, tzinfo=datetime.timezone.utc),
  119. ]
  120. ),
  121. vDDDLists(
  122. [
  123. datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),
  124. datetime.datetime(2020, 2, 5, 20, 5, tzinfo=datetime.timezone.utc),
  125. datetime.datetime(2020, 2, 5, 20, 7, tzinfo=datetime.timezone.utc),
  126. ]
  127. ),
  128. False,
  129. ),
  130. (
  131. vCalAddress("someelse@somewhere.com"),
  132. _parametrize(
  133. vCalAddress("someelse@somewhere.com"),
  134. dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
  135. ),
  136. False,
  137. ),
  138. (
  139. _parametrize(
  140. vCalAddress("someelse@somewhere.com"),
  141. dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
  142. ),
  143. _parametrize(
  144. vCalAddress("someelse@somewhere.com"),
  145. dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
  146. ),
  147. True,
  148. ),
  149. (
  150. [
  151. vCalAddress("someone@somewhere.com",),
  152. vCalAddress("someelse@somewhere.com"),
  153. ],
  154. [
  155. vCalAddress("someone@somewhere.com",),
  156. _parametrize(
  157. vCalAddress("someelse@somewhere.com"),
  158. dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
  159. ),
  160. ],
  161. False,
  162. ),
  163. (
  164. [
  165. vCalAddress("someone@somewhere.com",),
  166. _parametrize(
  167. vCalAddress("someelse@somewhere.com"),
  168. dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
  169. ),
  170. ],
  171. [
  172. vCalAddress("someone@somewhere.com",),
  173. _parametrize(
  174. vCalAddress("someelse@somewhere.com"),
  175. dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
  176. ),
  177. ],
  178. True,
  179. ),
  180. ],
  181. )
  182. def test__event_prop_equal(prop_a, prop_b, expected_result):
  183. assert _event_prop_equal(prop_a, prop_b) == expected_result