<s> import datetime <EOL> from django . test import TestCase <EOL> from django . utils import timezone <EOL> from schedule . models import Event , Rule , Calendar , CalendarRelation <EOL> class TestCalendar ( TestCase ) : <EOL> def setup ( self ) : <EOL> pass <EOL> def __create_event ( self , start , end ) : <EOL> data = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT:start>' : start , <EOL> '<STR_LIT:end>' : end <EOL> } <EOL> return Event . objects . create ( ** data ) <EOL> def test_get_recent_events_without_events_is_empty ( self ) : <EOL> calendar = Calendar ( ) <EOL> self . assertEqual ( list ( calendar . get_recent ( ) ) , [ ] ) <EOL> def test_get_recent_events_with_events_return_the_event ( self ) : <EOL> pass <EOL> def test_occurrences_after_without_events_is_empty ( self ) : <EOL> calendar = Calendar ( ) <EOL> self . assertEqual ( list ( calendar . occurrences_after ( timezone . now ( ) ) ) , [ ] ) <EOL> def test_occurrences_after_with_events_after_returns_events ( self ) : <EOL> calendar = Calendar ( ) <EOL> calendar . save ( ) <EOL> start_after = timezone . now ( ) + datetime . timedelta ( days = <NUM_LIT:1> ) <EOL> end_after = start_after + datetime . timedelta ( hours = <NUM_LIT:1> ) <EOL> event = self . __create_event ( start_after , end_after ) <EOL> calendar . events . add ( event ) <EOL> occurrences = list ( calendar . occurrences_after ( timezone . now ( ) ) ) <EOL> self . assertEqual ( len ( occurrences ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( occurrences [ <NUM_LIT:0> ] . start , start_after ) <EOL> self . assertEqual ( occurrences [ <NUM_LIT:0> ] . end , end_after ) <EOL> def test_occurrences_after_with_events_before_returns_empty ( self ) : <EOL> calendar = Calendar ( ) <EOL> calendar . save ( ) <EOL> start_after = timezone . now ( ) + datetime . timedelta ( days = - <NUM_LIT:1> ) <EOL> end_after = start_after + datetime . timedelta ( hours = <NUM_LIT:1> ) <EOL> event = self . __create_event ( start_after , end_after ) <EOL> calendar . events . add ( event ) <EOL> occurrences = list ( calendar . occurrences_after ( timezone . now ( ) ) ) <EOL> self . assertEqual ( occurrences , [ ] ) <EOL> def test_get_calendar_for_object ( self ) : <EOL> calendar = Calendar ( name = '<STR_LIT>' ) <EOL> calendar . save ( ) <EOL> rule = Rule ( ) <EOL> rule . save ( ) <EOL> calendar . create_relation ( rule ) <EOL> result = Calendar . objects . get_calendar_for_object ( rule ) <EOL> self . assertEqual ( result . name , '<STR_LIT>' ) <EOL> def test_get_calendar_for_object_without_calendars ( self ) : <EOL> with self . assertRaises ( Calendar . DoesNotExist ) : <EOL> rule = Rule ( ) <EOL> rule . save ( ) <EOL> Calendar . objects . get_calendar_for_object ( rule ) <EOL> def test_get_calendar_for_object_with_more_than_one_calendar ( self ) : <EOL> calendar_1 = Calendar ( name = '<STR_LIT>' ) <EOL> calendar_1 . save ( ) <EOL> calendar_2 = Calendar ( name = '<STR_LIT>' ) <EOL> calendar_2 . save ( ) <EOL> rule = Rule ( ) <EOL> rule . save ( ) <EOL> calendar_1 . create_relation ( rule ) <EOL> calendar_2 . create_relation ( rule ) <EOL> with self . assertRaises ( AssertionError ) : <EOL> result = Calendar . objects . get_calendar_for_object ( rule ) <EOL> def test_get_or_create_calendar_for_object_without_calendar ( self ) : <EOL> """<STR_LIT>""" <EOL> rule = Rule ( ) <EOL> rule . save ( ) <EOL> calendar = Calendar . objects . get_or_create_calendar_for_object ( rule , name = '<STR_LIT>' ) <EOL> self . assertEqual ( calendar . name , '<STR_LIT>' ) <EOL> calendar_from_rule = Calendar . objects . get_calendars_for_object ( rule ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( calendar , calendar_from_rule ) <EOL> def test_get_or_create_calendar_for_object_withouth_name ( self ) : <EOL> """<STR_LIT>""" <EOL> rule = Rule ( ) <EOL> rule . save ( ) <EOL> calendar = Calendar . objects . get_or_create_calendar_for_object ( rule ) <EOL> calendar_from_rule = Calendar . objects . get_calendars_for_object ( rule ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( calendar , calendar_from_rule ) <EOL> def test_get_calendars_for_object_without_calendars ( self ) : <EOL> rule = Rule ( ) <EOL> rule . save ( ) <EOL> calendar = Calendar . objects . get_or_create_calendar_for_object ( rule , name = '<STR_LIT>' , distinction = '<STR_LIT>' ) <EOL> rule = Rule ( ) <EOL> rule . save ( ) <EOL> calendars = list ( Calendar . objects . get_calendars_for_object ( rule , distinction = '<STR_LIT>' ) ) <EOL> self . assertEqual ( len ( calendars ) , <NUM_LIT:0> ) <EOL> def test_calendar_absolute_and_event_url ( self ) : <EOL> """<STR_LIT>""" <EOL> rule = Rule ( ) <EOL> rule . save ( ) <EOL> calendar = Calendar . objects . get_or_create_calendar_for_object ( rule , name = '<STR_LIT>' , distinction = '<STR_LIT>' ) <EOL> abs_url = calendar . get_absolute_url ( ) <EOL> calendar . add_event_url ( ) <EOL> relation = CalendarRelation . objects . create_relation ( calendar , rule ) </s>
