prop_test.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. (
  47. vRecur(FREQ="WEEKLY", COUNT=21),
  48. vRecur(FREQ="WEEKLY", COUNT=21),
  49. True,
  50. ),
  51. (
  52. vRecur(FREQ="WEEKLY", COUNT=21),
  53. vRecur(FREQ="WEEKLY", COUNT=42),
  54. False,
  55. ),
  56. (
  57. vDDDTypes(
  58. datetime.datetime(2012, 7, 3, 16, 39, 2, tzinfo=datetime.timezone.utc)
  59. ),
  60. vDDDTypes(
  61. datetime.datetime(2012, 7, 3, 16, 39, 2, tzinfo=datetime.timezone.utc)
  62. ),
  63. True,
  64. ),
  65. (
  66. vDDDTypes(
  67. datetime.datetime(2012, 7, 3, 16, 39, 2, tzinfo=datetime.timezone.utc)
  68. ),
  69. vDDDTypes(datetime.datetime(2012, 7, 3, 18, 39, 2, tzinfo=_CEST)),
  70. # logically that should be True
  71. # but shouldn't hurt to update the ics file
  72. False,
  73. ),
  74. (
  75. vDDDTypes(
  76. datetime.datetime(2012, 7, 3, 16, 39, 3, tzinfo=datetime.timezone.utc)
  77. ),
  78. vDDDTypes(
  79. datetime.datetime(2012, 7, 3, 16, 39, 2, tzinfo=datetime.timezone.utc)
  80. ),
  81. False,
  82. ),
  83. (
  84. vDDDLists(
  85. [datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc)]
  86. ),
  87. vDDDLists(
  88. [datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc)]
  89. ),
  90. True,
  91. ),
  92. (
  93. vDDDLists(
  94. [
  95. datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),
  96. datetime.datetime(2020, 2, 5, 20, 5, tzinfo=datetime.timezone.utc),
  97. ]
  98. ),
  99. vDDDLists(
  100. [
  101. datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),
  102. datetime.datetime(2020, 2, 5, 20, 5, tzinfo=datetime.timezone.utc),
  103. ]
  104. ),
  105. True,
  106. ),
  107. (
  108. vDDDLists(
  109. [
  110. datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),
  111. datetime.datetime(2020, 2, 5, 20, 5, tzinfo=datetime.timezone.utc),
  112. ]
  113. ),
  114. vDDDLists(
  115. [
  116. datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),
  117. datetime.datetime(2020, 2, 5, 20, 7, tzinfo=datetime.timezone.utc),
  118. ]
  119. ),
  120. False,
  121. ),
  122. (
  123. vDDDLists(
  124. [
  125. datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),
  126. datetime.datetime(2020, 2, 5, 20, 5, tzinfo=datetime.timezone.utc),
  127. ]
  128. ),
  129. vDDDLists(
  130. [
  131. datetime.datetime(2020, 2, 5, 20, 0, tzinfo=datetime.timezone.utc),
  132. datetime.datetime(2020, 2, 5, 20, 5, tzinfo=datetime.timezone.utc),
  133. datetime.datetime(2020, 2, 5, 20, 7, tzinfo=datetime.timezone.utc),
  134. ]
  135. ),
  136. False,
  137. ),
  138. (
  139. vCalAddress("someelse@somewhere.com"),
  140. _parametrize(
  141. vCalAddress("someelse@somewhere.com"),
  142. dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
  143. ),
  144. False,
  145. ),
  146. (
  147. _parametrize(
  148. vCalAddress("someelse@somewhere.com"),
  149. dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
  150. ),
  151. _parametrize(
  152. vCalAddress("someelse@somewhere.com"),
  153. dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
  154. ),
  155. True,
  156. ),
  157. (
  158. [
  159. vCalAddress(
  160. "someone@somewhere.com",
  161. ),
  162. vCalAddress("someelse@somewhere.com"),
  163. ],
  164. [
  165. vCalAddress(
  166. "someone@somewhere.com",
  167. ),
  168. _parametrize(
  169. vCalAddress("someelse@somewhere.com"),
  170. dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
  171. ),
  172. ],
  173. False,
  174. ),
  175. (
  176. [
  177. vCalAddress(
  178. "someone@somewhere.com",
  179. ),
  180. _parametrize(
  181. vCalAddress("someelse@somewhere.com"),
  182. dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
  183. ),
  184. ],
  185. [
  186. vCalAddress(
  187. "someone@somewhere.com",
  188. ),
  189. _parametrize(
  190. vCalAddress("someelse@somewhere.com"),
  191. dict(UTYPE="INDIVIDUAL", PARTSTAT="ACCEPTED"),
  192. ),
  193. ],
  194. True,
  195. ),
  196. ],
  197. )
  198. def test__event_prop_equal(prop_a, prop_b, expected_result):
  199. assert _event_prop_equal(prop_a, prop_b) == expected_result