event_test.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 icalendar.cal
  18. import pytest
  19. import ical2vdir
  20. @pytest.mark.parametrize(
  21. ("event_a_ical", "event_b_ical", "expected_result"),
  22. (
  23. [
  24. (
  25. """BEGIN:VEVENT
  26. SUMMARY:party
  27. DTSTART:20201024T100000Z
  28. DTEND:20201026T120000Z
  29. DTSTAMP:20200205T160640Z
  30. UID:123456789@google.com
  31. SEQUENCE:0
  32. CREATED:20191231T103841Z
  33. DESCRIPTION:
  34. LAST-MODIFIED:20191231T103841Z
  35. LOCATION:
  36. STATUS:CONFIRMED
  37. TRANSP:OPAQUE
  38. END:VEVENT
  39. """,
  40. """BEGIN:VEVENT
  41. SUMMARY:party
  42. DTSTART:20201024T100000Z
  43. DTEND:20201026T120000Z
  44. DTSTAMP:20200205T160640Z
  45. UID:123456789@google.com
  46. SEQUENCE:0
  47. CREATED:20191231T103841Z
  48. DESCRIPTION:
  49. LAST-MODIFIED:20191231T103841Z
  50. LOCATION:
  51. STATUS:CONFIRMED
  52. TRANSP:OPAQUE
  53. END:VEVENT
  54. """,
  55. True,
  56. ),
  57. (
  58. """BEGIN:VEVENT
  59. SUMMARY:party
  60. DTSTART:20201024T100000Z
  61. DTEND:20201026T120000Z
  62. DTSTAMP:20200205T160640Z
  63. UID:123456789@google.com
  64. SEQUENCE:0
  65. CREATED:20191231T103841Z
  66. DESCRIPTION:
  67. LAST-MODIFIED:20191231T103841Z
  68. LOCATION:
  69. STATUS:CONFIRMED
  70. TRANSP:OPAQUE
  71. END:VEVENT
  72. """,
  73. """BEGIN:VEVENT
  74. SUMMARY:party
  75. DTSTART:20201024T100000Z
  76. DTEND:20201026T120000Z
  77. DTSTAMP:20200205T160640Z
  78. UID:123456789@google.com
  79. SEQUENCE:0
  80. CREATED:20191231T103841Z
  81. DESCRIPTION:
  82. LAST-MODIFIED:20191231T103841Z
  83. STATUS:CONFIRMED
  84. TRANSP:OPAQUE
  85. END:VEVENT
  86. """,
  87. False,
  88. ),
  89. (
  90. """BEGIN:VEVENT
  91. SUMMARY:party
  92. DTSTART:20201024T100000Z
  93. DTEND:20201026T120000Z
  94. DTSTAMP:20200205T160640Z
  95. UID:123456789@google.com
  96. SEQUENCE:0
  97. CREATED:20191231T103841Z
  98. LAST-MODIFIED:20191231T103841Z
  99. END:VEVENT
  100. """,
  101. """BEGIN:VEVENT
  102. SUMMARY:party
  103. DTSTART:20201024T100000Z
  104. DTEND:20201026T120000Z
  105. DTSTAMP:20200205T160640Z
  106. UID:123456789@google.com
  107. SEQUENCE:1
  108. CREATED:20191231T103841Z
  109. LAST-MODIFIED:20191231T103841Z
  110. END:VEVENT
  111. """,
  112. False,
  113. ),
  114. (
  115. """BEGIN:VEVENT
  116. SUMMARY:party
  117. DTSTART:20201024T100000Z
  118. DTEND:20201026T120000Z
  119. DTSTAMP:20200205T160640Z
  120. UID:123456789@google.com
  121. SEQUENCE:0
  122. CREATED:20191231T103841Z
  123. LAST-MODIFIED:20191231T103841Z
  124. END:VEVENT
  125. """,
  126. # ignoring DTSTAMP
  127. """BEGIN:VEVENT
  128. SUMMARY:party
  129. DTSTART:20201024T100000Z
  130. DTEND:20201026T120000Z
  131. DTSTAMP:20200205T200640Z
  132. UID:123456789@google.com
  133. SEQUENCE:0
  134. CREATED:20191231T103841Z
  135. LAST-MODIFIED:20191231T103841Z
  136. END:VEVENT
  137. """,
  138. True,
  139. ),
  140. ]
  141. ),
  142. )
  143. def test__events_equal(
  144. event_a_ical: str, event_b_ical: str, expected_result: bool
  145. ) -> None:
  146. event_a = icalendar.cal.Event.from_ical(event_a_ical)
  147. event_b = icalendar.cal.Event.from_ical(event_b_ical)
  148. # pylint: disable=protected-access
  149. assert ical2vdir._events_equal(event_a, event_b) == expected_result