Skip to content

Commit

Permalink
add unit test for issue #205
Browse files Browse the repository at this point in the history
  • Loading branch information
llazzaro committed May 29, 2016
1 parent 7030569 commit 8872280
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/test_occurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,42 @@ def test_create_occurrence_without_event(self):
"""
o = Occurrence()

def test_get_occurrences_non_intersection_returns_empty_occ(self):
rule = Rule(frequency="DAILY")
rule.save()
cal = Calendar(name="MyCal")
cal.save()
recurring_data = {
'title': 'Recent Event',
'start': datetime.datetime(2016, 1, 5, 8, 0, tzinfo=pytz.utc),
'end': datetime.datetime(2016, 1, 5, 9, 0, tzinfo=pytz.utc),
'end_recurring_period': datetime.datetime(2016, 8, 5, 0, 0, tzinfo=pytz.utc),
'rule': rule,
'calendar': cal
}
recurring_event = Event.objects.create(**recurring_data)
occurrences = recurring_event.get_occurrences(start=self.start, end=self.end)
self.assertEquals(occurrences, [])

def test_get_occurrences_is_sorted(self):
rule = Rule(frequency="DAILY")
rule.save()
cal = Calendar(name="MyCal")
cal.save()
recurring_data = {
'title': 'Recent Event',
'start': datetime.datetime(2016, 1, 5, 8, 0, tzinfo=pytz.utc),
'end': datetime.datetime(2016, 1, 5, 9, 0, tzinfo=pytz.utc),
'end_recurring_period': datetime.datetime(2016, 8, 5, 0, 0, tzinfo=pytz.utc),
'rule': rule,
'calendar': cal
}
recurring_event = Event.objects.create(**recurring_data)

start = datetime.datetime(2016, 1, 12, 0, 0, tzinfo=pytz.utc)
end = datetime.datetime(2016, 1, 27, 0, 0, tzinfo=pytz.utc)
occurrences = recurring_event.get_occurrences(start=start, end=end)

sorted_occurrences = sorted(occurrences, key=lambda occ: occ.start)

self.assertEquals(occurrences, sorted_occurrences)

0 comments on commit 8872280

Please sign in to comment.