-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
test_recurrence.py
632 lines (555 loc) · 24.5 KB
/
test_recurrence.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
"""Test calendar rrules."""
import datetime
from django.test import TestCase
from dateutil import tz
from dateutil.rrule import DAILY
from dateutil.rrule import MO
from dateutil.rrule import MONTHLY
from dateutil.rrule import TH
from dateutil.rrule import TU
from dateutil.rrule import WEEKLY
from dateutil.rrule import YEARLY
from dateutil.rrule import rrule
from icalendar.prop import vRecur
import recurrence
from django_ical import utils
class BuildRruleTest(TestCase):
"""Test building an Rrule for icalendar."""
def test_every_day(self):
"""Repeat every day."""
vrecurr = vRecur(utils.build_rrule(freq="DAILY"))
assert vrecurr["FREQ"] == "DAILY"
assert vrecurr.to_ical().decode() == "FREQ=DAILY"
assert len(vrecurr.keys()) == 1
def test_daily_byhour(self):
"""Repeat every day at 10, 12 and 17."""
vrecurr = utils.build_rrule(freq="DAILY", byhour=[10, 12, 17])
assert vrecurr["FREQ"] == "DAILY"
assert vrecurr["BYHOUR"] == [10, 12, 17]
vRecur(vrecurr).to_ical().decode() == "FREQ=DAILY;BYHOUR=10,12,17"
assert len(vrecurr.keys()) == 2
def test_daily_byhour_once(self):
"""Repeat every day at 10."""
vrecurr = utils.build_rrule(freq="DAILY", byhour=10)
assert vrecurr["FREQ"] == "DAILY"
assert vrecurr["BYHOUR"] == 10
vRecur(vrecurr).to_ical().decode() == "FREQ=DAILY;BYHOUR=10"
assert len(vrecurr.keys()) == 2
def test_every_week(self):
"""Repeat every week."""
vrecurr = utils.build_rrule(freq="WEEKLY")
assert vrecurr["FREQ"] == "WEEKLY"
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY"
assert len(vrecurr.keys()) == 1
def test_ever_hour(self):
"""Repeat every hour."""
vrecurr = utils.build_rrule(freq="HOURLY")
assert vrecurr["FREQ"] == "HOURLY"
vRecur(vrecurr).to_ical().decode() == "FREQ=HOURLY"
assert len(vrecurr.keys()) == 1
def test_ever_4_hours(self):
"""Repeat every 4 hours."""
vrecurr = utils.build_rrule(interval=4, freq="HOURLY")
assert vrecurr["FREQ"] == "HOURLY"
assert vrecurr["INTERVAL"] == 4
vRecur(vrecurr).to_ical().decode() == "FREQ=HOURLY;INTERVAL=4"
assert len(vrecurr.keys()) == 2
def test_weekly_tue(self):
"""Repeat every week on Tuesday."""
vrecurr = utils.build_rrule(freq="WEEKLY", byday="TU")
assert vrecurr["FREQ"] == "WEEKLY"
assert vrecurr["BYDAY"] == "TU"
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;BYDAY=TU"
assert len(vrecurr.keys()) == 2
def test_weekly_mo_wed(self):
"""Repeat every week on Monday, Wednesday."""
vrecurr = utils.build_rrule(freq="WEEKLY", byday=["MO", "WE"])
assert vrecurr["FREQ"] == "WEEKLY"
assert vrecurr["BYDAY"] == ["MO", "WE"]
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;BYDAY=MO,WE"
assert len(vrecurr.keys()) == 2
def test_every_weekday(self):
"""Repeat every weekday."""
vrecurr = utils.build_rrule(freq="WEEKLY", byday=["MO", "TU", "WE", "TH", "FR"])
assert vrecurr["FREQ"] == "WEEKLY"
assert vrecurr["BYDAY"] == ["MO", "TU", "WE", "TH", "FR"]
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR"
assert len(vrecurr.keys()) == 2
def test_every_2_weeks(self):
"""Repeat every 2 weeks."""
vrecurr = utils.build_rrule(interval=2, freq="WEEKLY")
assert vrecurr["FREQ"] == "WEEKLY"
assert vrecurr["INTERVAL"] == 2
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;INTERVAL=2"
assert len(vrecurr.keys()) == 2
def test_every_month(self):
"""Repeat every month."""
vrecurr = utils.build_rrule(freq="MONTHLY")
assert vrecurr["FREQ"] == "MONTHLY"
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY"
assert len(vrecurr.keys()) == 1
def test_every_6_months(self):
"""Repeat very 6 months."""
vrecurr = utils.build_rrule(interval=6, freq="MONTHLY")
assert vrecurr["FREQ"] == "MONTHLY"
assert vrecurr["INTERVAL"] == 6
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;INTERVAL=6"
assert len(vrecurr.keys()) == 2
def test_every_year(self):
"""Repeat every year."""
vrecurr = utils.build_rrule(freq="YEARLY")
assert vrecurr["FREQ"] == "YEARLY"
vRecur(vrecurr).to_ical().decode() == "FREQ=YEARLY"
assert len(vrecurr.keys()) == 1
def test_every_month_on_the_4th(self):
"""Repeat every month on the 4th."""
vrecurr = utils.build_rrule(freq="MONTHLY", bymonthday=4)
assert vrecurr["FREQ"] == "MONTHLY"
assert vrecurr["BYMONTHDAY"] == 4
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYMONTHDAY=4"
assert len(vrecurr.keys()) == 2
def test_every_month_on_the_4th_last(self):
"""Repeat every month on the 4th last."""
vrecurr = utils.build_rrule(freq="MONTHLY", bymonthday=-4)
assert vrecurr["FREQ"] == "MONTHLY"
assert vrecurr["BYMONTHDAY"] == -4
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYMONTHDAY=-4"
assert len(vrecurr.keys()) == 2
def test_ever_month_3rd_tu(self):
"""Repeat every month on the 3rd Tuesday."""
vrecurr = utils.build_rrule(freq="MONTHLY", byday="+3TU")
assert vrecurr["FREQ"] == "MONTHLY"
assert vrecurr["BYDAY"] == "+3TU"
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYDAY=+3TU"
assert len(vrecurr.keys()) == 2
def test_ever_month_3rd_last_tu(self):
"""Repeat every month on the 3rd last Tuesday."""
vrecurr = utils.build_rrule(freq="MONTHLY", byday="-3TU")
assert vrecurr["FREQ"] == "MONTHLY"
assert vrecurr["BYDAY"] == "-3TU"
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYDAY=-3TU"
assert len(vrecurr.keys()) == 2
def test_ever_month_last_mo(self):
"""Repeat every month on the last Monday."""
vrecurr = utils.build_rrule(freq="MONTHLY", byday="-1MO")
assert vrecurr["FREQ"] == "MONTHLY"
assert vrecurr["BYDAY"] == "-1MO"
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYDAY=-1MO"
assert len(vrecurr.keys()) == 2
def test_every_week_until_jan_2007(self):
"""Repeat every week until January 1, 2007."""
utc = tz.UTC
jan2007 = datetime.datetime(2007, 1, 1, 0, 0, tzinfo=utc)
vrecurr = utils.build_rrule(freq="WEEKLY", until=jan2007)
assert vrecurr["FREQ"] == "WEEKLY"
assert vrecurr["UNTIL"] == jan2007
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;UNTIL=20070101T000000Z"
assert len(vrecurr.keys()) == 2
def test_every_week_20_times(self):
"""Repeat every week for 20 times."""
vrecurr = utils.build_rrule(freq="WEEKLY", count=20)
assert vrecurr["FREQ"] == "WEEKLY"
assert vrecurr["COUNT"] == 20
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;COUNT=20"
assert len(vrecurr.keys()) == 2
def test_every_month_last_working_day(self):
"""Repeat the last working day of each month."""
vrecurr = utils.build_rrule(
freq="MONTHLY", byday=["MO", "TU", "WE", "TH", "FR"], bysetpos=-1
)
assert vrecurr["FREQ"] == "MONTHLY"
assert vrecurr["BYDAY"] == ["MO", "TU", "WE", "TH", "FR"]
assert vrecurr["BYSETPOS"] == -1
vRecur(
vrecurr
).to_ical().decode() == "FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1"
assert len(vrecurr.keys()) == 3
def test_ever_month_last_day(self):
"""Repeat the last day of each month."""
vrecurr = utils.build_rrule(freq="MONTHLY", bymonthday=-1)
assert vrecurr["FREQ"] == "MONTHLY"
assert vrecurr["BYMONTHDAY"] == -1
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYMONTHDAY=-1"
assert len(vrecurr.keys()) == 2
def test_every_day_in_jan(self):
"""Repeat every day in January"""
vrecurr = utils.build_rrule(
freq="YEARLY", bymonth=1, byday=["MO", "TU", "WE", "TH", "FR", "SA", "SU"]
)
assert vrecurr["FREQ"] == "YEARLY"
assert vrecurr["BYMONTH"] == 1
assert vrecurr["BYDAY"] == ["MO", "TU", "WE", "TH", "FR", "SA", "SU"]
vRecur(
vrecurr
).to_ical().decode() == "FREQ=YEARLY;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYMONTH=1"
assert len(vrecurr.keys()) == 3
def test_every_2nd_15th_of_month(self):
"""Repeat monthly on the 2nd and 15th of the month."""
vrecurr = utils.build_rrule(freq="MONTHLY", bymonthday=[4, 15])
assert vrecurr["FREQ"] == "MONTHLY"
assert vrecurr["BYMONTHDAY"] == [4, 15]
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYMONTHDAY=4,15"
assert len(vrecurr.keys()) == 2
def test_every_fr_13th(self):
"""Repeat every Friday the 13th."""
vrecurr = utils.build_rrule(freq="YEARLY", bymonthday=13, byday="FR")
assert vrecurr["FREQ"] == "YEARLY"
assert vrecurr["BYMONTHDAY"] == 13
assert vrecurr["BYDAY"] == "FR"
vRecur(vrecurr).to_ical().decode() == "FREQ=YEARLY;BYDAY=FR;BYMONTHDAY=13"
assert len(vrecurr.keys()) == 3
class FromTextTests(TestCase):
"""Test build a vRecur dictionary from an RRULE string."""
def test_every_day(self):
"""Repeat every day."""
vrecurr = utils.build_rrule_from_text("FREQ=DAILY")
assert vrecurr["FREQ"] == ["DAILY"]
vRecur(vrecurr).to_ical().decode() == "FREQ=DAILY"
assert len(vrecurr.keys()) == 1
def test_daily_byhour(self):
"""Repeat every day at 10, 12 and 17."""
vrecurr = utils.build_rrule_from_text("FREQ=DAILY;BYHOUR=10,12,17")
assert vrecurr["FREQ"] == ["DAILY"]
assert vrecurr["BYHOUR"] == [10, 12, 17]
vRecur(vrecurr).to_ical().decode() == "FREQ=DAILY;BYHOUR=10,12,17"
assert len(vrecurr.keys()) == 2
def test_every_week(self):
"""Repeat every week."""
vrecurr = utils.build_rrule_from_text("FREQ=WEEKLY")
assert vrecurr["FREQ"] == ["WEEKLY"]
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY"
assert len(vrecurr.keys()) == 1
def test_ever_hour(self):
"""Repeat every hour."""
vrecurr = utils.build_rrule_from_text("FREQ=HOURLY")
assert vrecurr["FREQ"] == ["HOURLY"]
vRecur(vrecurr).to_ical().decode() == "FREQ=HOURLY"
assert len(vrecurr.keys()) == 1
def test_ever_4_hours(self):
"""Repeat every 4 hours."""
vrecurr = utils.build_rrule_from_text("INTERVAL=4;FREQ=HOURLY")
assert vrecurr["FREQ"] == ["HOURLY"]
assert vrecurr["INTERVAL"] == [4]
vRecur(vrecurr).to_ical().decode() == "FREQ=HOURLY;INTERVAL=4"
assert len(vrecurr.keys()) == 2
def test_weekly_tue(self):
"""Repeat every week on Tuesday."""
vrecurr = utils.build_rrule_from_text("FREQ=WEEKLY;BYDAY=TU")
assert vrecurr["FREQ"] == ["WEEKLY"]
assert vrecurr["BYDAY"] == ["TU"]
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;BYDAY=TU"
assert len(vrecurr.keys()) == 2
def test_weekly_mo_wed(self):
"""Repeat every week on Monday, Wednesday."""
vrecurr = utils.build_rrule_from_text("FREQ=WEEKLY;BYDAY=MO,WE")
assert vrecurr["FREQ"] == ["WEEKLY"]
assert vrecurr["BYDAY"] == ["MO", "WE"]
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;BYDAY=MO,WE"
assert len(vrecurr.keys()) == 2
def test_every_weekday(self):
"""Repeat every weekday."""
vrecurr = utils.build_rrule_from_text("FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR")
assert vrecurr["FREQ"] == ["WEEKLY"]
assert vrecurr["BYDAY"] == ["MO", "TU", "WE", "TH", "FR"]
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR"
assert len(vrecurr.keys()) == 2
def test_every_2_weeks(self):
"""Repeat every 2 weeks."""
vrecurr = utils.build_rrule_from_text("INTERVAL=2;FREQ=WEEKLY")
assert vrecurr["FREQ"] == ["WEEKLY"]
assert vrecurr["INTERVAL"] == [2]
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;INTERVAL=2"
assert len(vrecurr.keys()) == 2
def test_every_month(self):
"""Repeat every month."""
vrecurr = utils.build_rrule_from_text("FREQ=MONTHLY")
assert vrecurr["FREQ"] == ["MONTHLY"]
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY"
assert len(vrecurr.keys()) == 1
def test_every_6_months(self):
"""Repeat very 6 months."""
vrecurr = utils.build_rrule_from_text("INTERVAL=6;FREQ=MONTHLY")
assert vrecurr["FREQ"] == ["MONTHLY"]
assert vrecurr["INTERVAL"] == [6]
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;INTERVAL=6"
assert len(vrecurr.keys()) == 2
def test_every_year(self):
"""Repeat every year."""
vrecurr = utils.build_rrule_from_text("FREQ=YEARLY")
assert vrecurr["FREQ"] == ["YEARLY"]
vRecur(vrecurr).to_ical().decode() == "FREQ=YEARLY"
assert len(vrecurr.keys()) == 1
def test_every_month_on_the_4th(self):
"""Repeat every month on the 4th."""
vrecurr = utils.build_rrule_from_text("FREQ=MONTHLY;BYMONTHDAY=4")
assert vrecurr["FREQ"] == ["MONTHLY"]
assert vrecurr["BYMONTHDAY"] == [4]
assert len(vrecurr.keys()) == 2
vrecurr = utils.build_rrule_from_text("FREQ=MONTHLY;BYMONTHDAY=+4")
assert vrecurr["FREQ"] == ["MONTHLY"]
assert vrecurr["BYMONTHDAY"] == [4]
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYMONTHDAY=4"
assert len(vrecurr.keys()) == 2
def test_every_month_on_the_4th_last(self):
"""Repeat every month on the 4th last."""
vrecurr = utils.build_rrule_from_text("FREQ=MONTHLY;BYMONTHDAY=-4")
assert vrecurr["FREQ"] == ["MONTHLY"]
assert vrecurr["BYMONTHDAY"] == [-4]
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYMONTHDAY=-4"
assert len(vrecurr.keys()) == 2
def test_ever_month_3rd_tu(self):
"""Repeat every month on the 3rd Tuesday."""
vrecurr = utils.build_rrule_from_text("FREQ=MONTHLY;BYDAY=+3TU")
assert vrecurr["FREQ"] == ["MONTHLY"]
assert vrecurr["BYDAY"] == ["+3TU"]
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYDAY=+3TU"
assert len(vrecurr.keys()) == 2
def test_ever_month_3rd_last_tu(self):
"""Repeat every month on the 3rd last Tuesday."""
vrecurr = utils.build_rrule_from_text("FREQ=MONTHLY;BYDAY=-3TU")
assert vrecurr["FREQ"] == ["MONTHLY"]
assert vrecurr["BYDAY"] == ["-3TU"]
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYDAY=-3TU"
assert len(vrecurr.keys()) == 2
def test_ever_month_last_mo(self):
"""Repeat every month on the last Monday."""
vrecurr = utils.build_rrule_from_text("FREQ=MONTHLY;BYDAY=-1MO")
assert vrecurr["FREQ"] == ["MONTHLY"]
assert vrecurr["BYDAY"] == ["-1MO"]
assert len(vrecurr.keys()) == 2
def test_ever_month_second_last_fr(self):
"""Repeat every month on the 2nd last Friday."""
vrecurr = utils.build_rrule_from_text("FREQ=MONTHLY;BYDAY=-2FR")
assert vrecurr["FREQ"] == ["MONTHLY"]
assert vrecurr["BYDAY"] == ["-2FR"]
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYDAY=-2FR"
assert len(vrecurr.keys()) == 2
def test_every_week_until_jan_2007(self):
"""Repeat every week until January 1, 2007."""
utc = tz.UTC
vrecurr = utils.build_rrule_from_text("FREQ=WEEKLY;UNTIL=20070101T000000Z")
assert vrecurr["FREQ"] == ["WEEKLY"]
assert vrecurr["UNTIL"] == [datetime.datetime(2007, 1, 1, 0, 0, tzinfo=utc)]
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;UNTIL=20070101T000000Z"
assert len(vrecurr.keys()) == 2
def test_every_week_20_times(self):
"""Repeat every week for 20 times."""
vrecurr = utils.build_rrule_from_text("FREQ=WEEKLY;COUNT=20")
assert vrecurr["FREQ"] == ["WEEKLY"]
assert vrecurr["COUNT"] == [20]
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;COUNT=20"
assert len(vrecurr.keys()) == 2
def test_every_month_last_working_day(self):
"""Repeat the last working day of each month."""
vrecurr = utils.build_rrule_from_text(
"FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1;"
)
assert vrecurr["FREQ"] == ["MONTHLY"]
assert vrecurr["BYDAY"] == ["MO", "TU", "WE", "TH", "FR"]
assert vrecurr["BYSETPOS"] == [-1]
vRecur(
vrecurr
).to_ical().decode() == "FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1"
assert len(vrecurr.keys()) == 3
def test_ever_month_last_day(self):
"""Repeat the last day of each month."""
vrecurr = utils.build_rrule_from_text("FREQ=MONTHLY;BYMONTHDAY=-1")
assert vrecurr["FREQ"] == ["MONTHLY"]
assert vrecurr["BYMONTHDAY"] == [-1]
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYMONTHDAY=-1"
assert len(vrecurr.keys()) == 2
def test_every_day_in_jan(self):
"""Repeat every day in January"""
vrecurr = utils.build_rrule_from_text(
"FREQ=YEARLY;BYMONTH=1;BYDAY=MO,TU,WE,TH,FR,SA,SU;"
)
assert vrecurr["FREQ"] == ["YEARLY"]
assert vrecurr["BYMONTH"] == [1]
assert vrecurr["BYDAY"] == ["MO", "TU", "WE", "TH", "FR", "SA", "SU"]
vRecur(
vrecurr
).to_ical().decode() == "FREQ=YEARLY;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYMONTH=1"
assert len(vrecurr.keys()) == 3
def test_every_2nd_15th_of_month(self):
"""Repeat monthly on the 2nd and 15th of the month."""
vrecurr = utils.build_rrule_from_text("FREQ=MONTHLY;BYMONTHDAY=4,15")
assert vrecurr["FREQ"] == ["MONTHLY"]
assert vrecurr["BYMONTHDAY"] == [4, 15]
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYMONTHDAY=4,15"
assert len(vrecurr.keys()) == 2
def test_every_fr_13th(self):
"""Repeat every Friday the 13th."""
vrecurr = utils.build_rrule_from_text("FREQ=YEARLY;BYMONTHDAY=13;BYDAY=FR")
assert vrecurr["FREQ"] == ["YEARLY"]
assert vrecurr["BYMONTHDAY"] == [13]
assert vrecurr["BYDAY"] == ["FR"]
vRecur(vrecurr).to_ical().decode() == "FREQ=YEARLY;BYDAY=FR;BYMONTHDAY=13"
assert len(vrecurr.keys()) == 3
class FromDateutilRruleTests(TestCase):
"""Build an ical string from a dateutil rrule."""
def test_weekly_by_month_year_day(self):
rule = rrule(
WEEKLY,
bymonth=(1, 7),
byyearday=(1, 100, 200, 365),
dtstart=datetime.datetime(1997, 9, 2, 9, 0),
)
vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
vRecur(
vrecurr
).to_ical().decode() == "FREQ=WEEKLY;BYYEARDAY=1,100,200,365;BYMONTH=1,7"
def test_weekly_by_month_nweekday(self):
rule = rrule(
WEEKLY,
count=3,
bymonth=(1, 3),
byweekday=(TU(1), TH(-1)),
dtstart=datetime.datetime(1997, 9, 2, 9, 0),
)
vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
vRecur(
vrecurr
).to_ical().decode() == "FREQ=WEEKLY;COUNT=3;BYDAY=TU,TH;BYMONTH=1,3"
def test_weekly_by_monthday(self):
rule = rrule(
WEEKLY,
count=3,
bymonthday=(1, 3),
dtstart=datetime.datetime(1997, 9, 2, 9, 0),
)
vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;COUNT=3;BYMONTHDAY=1,3"
def test_weekly_by_weekday(self):
rule = rrule(
WEEKLY,
count=3,
byweekday=(TU, TH),
dtstart=datetime.datetime(1997, 9, 2, 9, 0),
)
vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;COUNT=3;BYDAY=TU,TH"
def test_daily_by_month_nweekday(self):
rule = rrule(
DAILY,
count=3,
bymonth=(1, 3),
byweekday=(TU(1), TH(-1)),
dtstart=datetime.datetime(1997, 9, 2, 9, 0),
)
vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
vRecur(
vrecurr
).to_ical().decode() == "FREQ=DAILY;COUNT=3;BYDAY=TU,TH;BYMONTH=1,3"
def test_yearly_month_nweekday(self):
rule = rrule(
YEARLY,
count=3,
bymonth=(1, 3),
byweekday=(TU(1), TH(-1)),
dtstart=datetime.datetime(1997, 9, 2, 9, 0),
)
vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
vRecur(
vrecurr
).to_ical().decode() == "FREQ=YEARLY;COUNT=3;BYDAY=+1TU,-1TH;BYMONTH=1,3"
def test_yearly_month_yearday(self):
rule = rrule(
YEARLY,
count=4,
bymonth=(4, 7),
byyearday=(1, 100, 200, 365),
dtstart=datetime.datetime(1997, 9, 2, 9, 0),
)
vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
assert (
vRecur(vrecurr).to_ical().decode()
== "FREQ=YEARLY;COUNT=4;BYYEARDAY=1,100,200,365;BYMONTH=4,7"
)
def test_yearly_weekno_weekday(self):
rule = rrule(
YEARLY,
count=3,
byweekno=1,
byweekday=MO,
dtstart=datetime.datetime(1997, 9, 2, 9, 0),
)
vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
vRecur(vrecurr).to_ical().decode() == "FREQ=YEARLY;COUNT=3;BYDAY=MO;BYWEEKNO=1"
def test_yearly_setpos(self):
rule = rrule(
YEARLY,
count=3,
bymonthday=15,
byhour=(6, 18),
bysetpos=(3, -3),
dtstart=datetime.datetime(1997, 9, 2, 9, 0),
)
vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
assert (
vRecur(vrecurr).to_ical().decode()
== "FREQ=YEARLY;COUNT=3;BYHOUR=6,18;BYMONTHDAY=15;BYSETPOS=3,-3"
)
def test_monthly_month_monthday(self):
rule = rrule(
MONTHLY,
count=3,
bymonth=(1, 3),
bymonthday=(5, 7),
dtstart=datetime.datetime(1997, 9, 2, 9, 0),
)
vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
vRecur(
vrecurr
).to_ical().decode() == "FREQ=MONTHLY;COUNT=3;BYMONTHDAY=5,7;BYMONTH=1,3"
def test_monthly_nweekday(self):
rule = rrule(
MONTHLY,
count=3,
byweekday=(TU(1), TH(-1)),
dtstart=datetime.datetime(1997, 9, 2, 9, 0),
)
vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;COUNT=3;BYDAY=+1TU,-1TH"
def test_monthly_month_nweekday(self):
rule = rrule(
MONTHLY,
bymonth=(1, 3),
byweekday=(TU(1), TH(-1)),
dtstart=datetime.datetime(1997, 9, 2, 9, 0),
)
vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYDAY=+1TU,-1TH;BYMONTH=1,3"
class FromDjangoRecurrenceRruleTests(TestCase):
"""Build an ical string from a django-recurrence rrule."""
def test_rule(self):
rule = recurrence.Rule(recurrence.WEEKLY)
vrecurr = utils.build_rrule_from_recurrences_rrule(rule)
vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY"
def test_complex_rule_serialization(self):
rule = recurrence.Rule(
recurrence.WEEKLY,
interval=17,
wkst=1,
count=7,
byday=[recurrence.to_weekday("-1MO"), recurrence.to_weekday("TU")],
bymonth=[1, 3],
)
vrecurr = utils.build_rrule_from_recurrences_rrule(rule)
assert (
vRecur(vrecurr).to_ical().decode()
== "FREQ=WEEKLY;COUNT=7;INTERVAL=17;BYDAY=-1MO,TU;BYMONTH=1,3;WKST=TU"
)
def test_complex_rule_serialization_with_weekday_instance(self):
rule = recurrence.Rule(
recurrence.WEEKLY,
interval=17,
wkst=recurrence.to_weekday(1),
count=7,
byday=[recurrence.to_weekday("-1MO"), recurrence.to_weekday("TU")],
bymonth=[1, 3],
)
vrecurr = utils.build_rrule_from_recurrences_rrule(rule)
assert (
vRecur(vrecurr).to_ical().decode()
== "FREQ=WEEKLY;COUNT=7;INTERVAL=17;BYDAY=-1MO,TU;BYMONTH=1,3;WKST=TU"
)