|
13 | 13 |
|
14 | 14 | import aiohttp |
15 | 15 | import aiohttp.web |
| 16 | +import caldav |
16 | 17 | import niquests as requests |
17 | | -from xandikos.web import XandikosApp, XandikosBackend |
| 18 | +from xandikos.web import SingleUserFilesystemBackend, XandikosApp |
18 | 19 |
|
19 | 20 | from plann.cli import _add_journal, _add_todo, _check_for_panic, _list, _select |
20 | 21 | from plann.interactive import ( |
|
24 | 25 | _mass_reprioritize, |
25 | 26 | command_edit, |
26 | 27 | ) |
27 | | -from plann.lib import _adjust_ical_relations, _adjust_relations, find_calendars |
| 28 | +from plann.lib import _adjust_ical_relations, _adjust_relations |
28 | 29 | from plann.panic_planning import timeline_suggestion |
29 | 30 | from tests.test_panic import datetime_ |
30 | 31 |
|
@@ -89,7 +90,7 @@ def start_xandikos_server(): |
89 | 90 | serverdir.__enter__() |
90 | 91 | ## Most of the stuff below is cargo-cult-copied from xandikos.web.main |
91 | 92 | ## Later jelmer created some API that could be used for this |
92 | | - backend = XandikosBackend(path=serverdir.name) |
| 93 | + backend = SingleUserFilesystemBackend(serverdir.name) |
93 | 94 | backend._mark_as_principal("/sometestuser/") |
94 | 95 | backend.create_principal("/sometestuser/", create_defaults=True) |
95 | 96 | mainapp = XandikosApp( |
@@ -132,7 +133,7 @@ def stop_xandikos_server(server_params): |
132 | 133 | ## ... but the thread may be stuck waiting for a request ... |
133 | 134 | def silly_request(): |
134 | 135 | try: |
135 | | - requests.get(server_params["caldav_url"]) |
| 136 | + requests.get(server_params["caldav_url"]).close() |
136 | 137 | except Exception: |
137 | 138 | pass |
138 | 139 | threading.Thread(target=silly_request).start() |
@@ -162,24 +163,37 @@ def passthrough(x): |
162 | 163 | def test_plann(): |
163 | 164 | conn_details = start_xandikos_server() |
164 | 165 | try: |
165 | | - ctx = MagicMock() |
166 | | - ctx.obj = dict() |
167 | | - ctx.obj['calendars'] = find_calendars(conn_details, raise_errors=True) |
168 | | - |
169 | | - def dag(obj, reltype, observed=None): |
170 | | - if not hasattr(obj, 'get_relatives'): |
171 | | - obj = ctx.obj['calendars'][0].object_by_uid(obj) |
172 | | - else: |
173 | | - obj.load() |
174 | | - if not observed: |
175 | | - observed = set() |
176 | | - ret = {} |
177 | | - relatives = obj.get_relatives(reltypes={reltype}, fetch_objects=False) |
178 | | - for x in relatives[reltype]: |
179 | | - assert x not in observed |
180 | | - observed.add(x) |
181 | | - ret[x] = dag(x, reltype, observed) |
182 | | - return ret |
| 166 | + with caldav.get_calendars( |
| 167 | + url=conn_details['caldav_url'], |
| 168 | + username=conn_details['caldav_user'], |
| 169 | + password=conn_details['caldav_password'], |
| 170 | + raise_errors=True, |
| 171 | + ) as calendars: |
| 172 | + _run_plann_tests(calendars) |
| 173 | + |
| 174 | + finally: |
| 175 | + stop_xandikos_server(conn_details) |
| 176 | + |
| 177 | + |
| 178 | +def _run_plann_tests(calendars): |
| 179 | + ctx = MagicMock() |
| 180 | + ctx.obj = dict() |
| 181 | + ctx.obj['calendars'] = list(calendars) |
| 182 | + |
| 183 | + def dag(obj, reltype, observed=None): |
| 184 | + if not hasattr(obj, 'get_relatives'): |
| 185 | + obj = ctx.obj['calendars'][0].object_by_uid(obj) |
| 186 | + else: |
| 187 | + obj.load() |
| 188 | + if not observed: |
| 189 | + observed = set() |
| 190 | + ret = {} |
| 191 | + relatives = obj.get_relatives(reltypes={reltype}, fetch_objects=False) |
| 192 | + for x in relatives[reltype]: |
| 193 | + assert x not in observed |
| 194 | + observed.add(x) |
| 195 | + ret[x] = dag(x, reltype, observed) |
| 196 | + return ret |
183 | 197 |
|
184 | 198 | ## We create two tasks todo1 and todo2, todo2 being a child of todo1 |
185 | 199 | todo1 = _add_todo(ctx, summary=['make plann good'], set_due='2012-12-20 23:15:00', set_dtstart='2012-12-20 22:15:00', set_uid='todo1', set_categories='plann,keyboard') |
@@ -234,8 +248,8 @@ def dag(obj, reltype, observed=None): |
234 | 248 |
|
235 | 249 | ## Test that the calendar_name template attribute works |
236 | 250 | list_cal = _list(ctx.obj['objs'], template="{calendar_name}", echo=False) |
237 | | - assert list_cal[0] == todo1.parent.name |
238 | | - assert list_cal[1] == todo2.parent.name |
| 251 | + assert list_cal[0] == todo1.parent.get_display_name() |
| 252 | + assert list_cal[1] == todo2.parent.get_display_name() |
239 | 253 |
|
240 | 254 | ## panic planning, timeline_suggestion. |
241 | 255 | ## We have two tasks in the calendar, each with one hour duration |
@@ -312,6 +326,9 @@ def dag(obj, reltype, observed=None): |
312 | 326 | assert len(ctx.obj['objs'])==4 |
313 | 327 |
|
314 | 328 | ## Reset ... let's connect todo1 and todo2 again, and remove events |
| 329 | + ## Reload to get fresh ETags — _check_for_panic modified these objects on the server |
| 330 | + todo1.load() |
| 331 | + todo2.load() |
315 | 332 | _adjust_relations(todo1, {todo2}) |
316 | 333 | _adjust_relations(todo2, set()) |
317 | 334 | todo1.load() |
@@ -435,8 +452,5 @@ def prompt(*largs, **kwargs): |
435 | 452 | command_edit(todo1, 'set due=2012-12-19 19:15:00', interactive=False) |
436 | 453 | assert todo1.icalendar_component['DUE'].dt > todo1.icalendar_component['DTSTART'].dt |
437 | 454 |
|
438 | | - finally: |
439 | | - stop_xandikos_server(conn_details) |
440 | | - |
441 | 455 | ## TODO: |
442 | 456 | ## Things to be tested: lib._procrastinate, cli._select, cli._cats, cli._list, cli._interactive_edit, cli._set_something, cli._interactive_ical_edit, cli._edit, cli._check_for_panic, _add_todo, _agenda, _check_due, |
0 commit comments