Code Repositories xandikos / 44924a2
Add tests for extract_from_calendar. Jelmer Vernooń≥ a month ago
1 changed file(s) with 94 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1616 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
1717 # MA 02110-1301, USA.
1818
19 from icalendar.cal import component_factory, Calendar as ICalendar
20 import unittest
1921 from wsgiref.util import setup_testing_defaults
2022
2123 from xandikos import caldav
6971 code, headers, contents = self.mkcalendar(app, '/resource/bla')
7072 self.assertEqual('201 Created', code)
7173 self.assertEqual(b'', contents)
74
75
76 class ExtractfromCalendarTests(unittest.TestCase):
77
78 def setUp(self):
79 super(ExtractfromCalendarTests, self).setUp()
80 self.requested = ET.Element('{%s}calendar-data' % caldav.NAMESPACE)
81
82 def extractEqual(self, incal_str, outcal_str):
83 incal = ICalendar.from_ical(incal_str)
84 expected_outcal = ICalendar.from_ical(outcal_str)
85 outcal = ICalendar()
86 caldav.extract_from_calendar(incal, outcal, self.requested)
87 self.assertEqual(outcal, expected_outcal)
88
89 def test_comp(self):
90 comp = ET.SubElement(self.requested, '{%s}comp' % caldav.NAMESPACE)
91 comp.set('name', 'VCALENDAR')
92 self.extractEqual("""\
93 BEGIN:VCALENDAR
94 BEGIN:VTODO
95 CLASS:PUBLIC
96 COMPLETED:20100829T234417Z
97 CREATED:20090606T042958Z
98 END:VTODO
99 END:VCALENDAR
100 """, """\
101 BEGIN:VCALENDAR
102 END:VCALENDAR
103 """)
104
105 def test_comp_nested(self):
106 vcal_comp = ET.SubElement(self.requested, '{%s}comp' % caldav.NAMESPACE)
107 vcal_comp.set('name', 'VCALENDAR')
108 vtodo_comp = ET.SubElement(vcal_comp, '{%s}comp' % caldav.NAMESPACE)
109 vtodo_comp.set('name', 'VTODO')
110 self.extractEqual("""\
111 BEGIN:VCALENDAR
112 BEGIN:VTODO
113 COMPLETED:20100829T234417Z
114 CREATED:20090606T042958Z
115 END:VTODO
116 END:VCALENDAR
117 """, """\
118 BEGIN:VCALENDAR
119 BEGIN:VTODO
120 END:VTODO
121 END:VCALENDAR
122 """)
123 self.extractEqual("""\
124 BEGIN:VCALENDAR
125 BEGIN:VEVENT
126 COMPLETED:20100829T234417Z
127 CREATED:20090606T042958Z
128 END:VEVENT
129 END:VCALENDAR
130 """, """\
131 BEGIN:VCALENDAR
132 END:VCALENDAR
133 """)
134
135 def test_prop(self):
136 vcal_comp = ET.SubElement(self.requested, '{%s}comp' % caldav.NAMESPACE)
137 vcal_comp.set('name', 'VCALENDAR')
138 vtodo_comp = ET.SubElement(vcal_comp, '{%s}comp' % caldav.NAMESPACE)
139 vtodo_comp.set('name', 'VTODO')
140 completed_prop = ET.SubElement(vtodo_comp, '{%s}prop' % caldav.NAMESPACE)
141 completed_prop.set('name', 'COMPLETED')
142 self.extractEqual("""\
143 BEGIN:VCALENDAR
144 BEGIN:VTODO
145 COMPLETED:20100829T234417Z
146 CREATED:20090606T042958Z
147 END:VTODO
148 END:VCALENDAR
149 """, """\
150 BEGIN:VCALENDAR
151 BEGIN:VTODO
152 COMPLETED:20100829T234417Z
153 END:VTODO
154 END:VCALENDAR
155 """)
156 self.extractEqual("""\
157 BEGIN:VCALENDAR
158 BEGIN:VEVENT
159 CREATED:20090606T042958Z
160 END:VEVENT
161 END:VCALENDAR
162 """, """\
163 BEGIN:VCALENDAR
164 END:VCALENDAR
165 """)