forked from DGNum/gestioCOF
Add assertion to check ical data is as expected
This commit is contained in:
parent
c239f28f17
commit
7e0ecd8e0f
1 changed files with 36 additions and 0 deletions
|
@ -8,6 +8,8 @@ from django.test import Client
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
|
|
||||||
|
import icalendar
|
||||||
|
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,6 +94,40 @@ class TestCaseMixin:
|
||||||
else:
|
else:
|
||||||
self.assertEqual(actual, expected)
|
self.assertEqual(actual, expected)
|
||||||
|
|
||||||
|
def _test_event_equal(self, event, exp):
|
||||||
|
for k, v_desc in exp.items():
|
||||||
|
if isinstance(v_desc, tuple):
|
||||||
|
v_getter = v_desc[0]
|
||||||
|
v = v_desc[1]
|
||||||
|
else:
|
||||||
|
v_getter = lambda v: v
|
||||||
|
v = v_desc
|
||||||
|
if v_getter(event[k.upper()]) != v:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _find_event(self, ev, l):
|
||||||
|
for i, elt in enumerate(l):
|
||||||
|
if self._test_event_equal(ev, elt):
|
||||||
|
return elt, i
|
||||||
|
return False, -1
|
||||||
|
|
||||||
|
def assertCalEqual(self, ical_content, expected):
|
||||||
|
remaining = expected.copy()
|
||||||
|
unexpected = []
|
||||||
|
|
||||||
|
cal = icalendar.Calendar.from_ical(ical_content)
|
||||||
|
|
||||||
|
for ev in cal.walk('vevent'):
|
||||||
|
found, i_found = self._find_event(ev, remaining)
|
||||||
|
if found:
|
||||||
|
remaining.pop(i_found)
|
||||||
|
else:
|
||||||
|
unexpected.append(ev)
|
||||||
|
|
||||||
|
self.assertListEqual(unexpected, [])
|
||||||
|
self.assertListEqual(remaining, [])
|
||||||
|
|
||||||
|
|
||||||
class ViewTestCaseMixin(TestCaseMixin):
|
class ViewTestCaseMixin(TestCaseMixin):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue