<s> """<STR_LIT>""" <EOL> import json <EOL> from django . forms . models import model_to_dict <EOL> from django . test import TestCase <EOL> from django . utils . timezone import timedelta <EOL> from mixer . backend . django import mixer <EOL> from . . constants import FREQUENCIES , OCCURRENCE_DECISIONS <EOL> from . . forms import OccurrenceForm <EOL> from . . models import Event , Occurrence <EOL> from . . utils import now <EOL> class OccurrenceFormTestCase ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> longMessage = True <EOL> def setUp ( self ) : <EOL> self . event = mixer . blend ( '<STR_LIT>' , rule = None , <EOL> end_recurring_period = None ) <EOL> self . event_occurrence = next ( self . event . get_occurrences ( <EOL> self . event . start ) ) <EOL> self . rule = mixer . blend ( <EOL> '<STR_LIT>' , <EOL> name = '<STR_LIT>' , frequency = FREQUENCIES [ '<STR_LIT>' ] , <EOL> params = json . dumps ( { '<STR_LIT>' : <NUM_LIT:0> } ) ) <EOL> self . rec_event = mixer . blend ( <EOL> '<STR_LIT>' , <EOL> rule = self . rule , start = now ( ) , <EOL> end_recurring_period = now ( ) + timedelta ( days = <NUM_LIT> ) , <EOL> ) <EOL> self . rec_occurrence_list = [ <EOL> occ for occ in self . rec_event . get_occurrences ( <EOL> self . rec_event . start , self . rec_event . end_recurring_period ) ] <EOL> self . rec_occurrence = self . rec_occurrence_list [ <NUM_LIT:1> ] <EOL> def test_form ( self ) : <EOL> """<STR_LIT>""" <EOL> data = model_to_dict ( self . event_occurrence ) <EOL> initial = data . copy ( ) <EOL> data . update ( { <EOL> '<STR_LIT>' : OCCURRENCE_DECISIONS [ '<STR_LIT:all>' ] , <EOL> '<STR_LIT:title>' : '<STR_LIT>' } ) <EOL> form = OccurrenceForm ( data = data , initial = initial ) <EOL> self . assertTrue ( form . is_valid ( ) , msg = ( <EOL> '<STR_LIT>' ) ) <EOL> form . save ( ) <EOL> event = Event . objects . get ( pk = self . event . pk ) <EOL> self . assertEqual ( event . title , '<STR_LIT>' , msg = ( <EOL> '<STR_LIT>' ) ) <EOL> data = model_to_dict ( self . rec_occurrence ) <EOL> initial = data . copy ( ) <EOL> data . update ( { <EOL> '<STR_LIT>' : OCCURRENCE_DECISIONS [ '<STR_LIT>' ] , <EOL> '<STR_LIT:title>' : '<STR_LIT>' } ) <EOL> form = OccurrenceForm ( data = data , initial = initial ) <EOL> self . assertTrue ( form . is_valid ( ) , msg = ( <EOL> '<STR_LIT>' ) ) <EOL> form . save ( ) <EOL> self . assertEqual ( Occurrence . objects . all ( ) . count ( ) , <NUM_LIT:1> , msg = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> occ = Occurrence . objects . get ( ) <EOL> self . assertEqual ( occ . title , '<STR_LIT>' , msg = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> occ_to_use = self . rec_occurrence_list [ <NUM_LIT:0> ] <EOL> data = model_to_dict ( occ_to_use ) <EOL> initial = data . copy ( ) <EOL> new_start = occ_to_use . start + timedelta ( hours = <NUM_LIT:1> ) <EOL> data . update ( { <EOL> '<STR_LIT>' : OCCURRENCE_DECISIONS [ '<STR_LIT:all>' ] , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT:start>' : new_start } ) <EOL> form = OccurrenceForm ( data = data , initial = initial ) <EOL> self . assertTrue ( form . is_valid ( ) , msg = ( <EOL> '<STR_LIT>' ) ) <EOL> form . save ( ) <EOL> self . assertEqual ( Occurrence . objects . all ( ) . count ( ) , <NUM_LIT:1> , msg = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> occ = Occurrence . objects . get ( ) <EOL> self . assertEqual ( occ . title , '<STR_LIT>' , msg = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . assertEqual ( occ . description , '<STR_LIT>' , msg = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> occ . start , self . rec_occurrence . start + timedelta ( hours = <NUM_LIT:1> ) , msg = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> occ_to_use = self . rec_occurrence_list [ <NUM_LIT:4> ] <EOL> data = model_to_dict ( occ_to_use ) <EOL> initial = data . copy ( ) <EOL> new_start = occ_to_use . start - timedelta ( days = <NUM_LIT:1> ) <EOL> data . update ( { <EOL> '<STR_LIT>' : OCCURRENCE_DECISIONS [ '<STR_LIT>' ] , <EOL> '<STR_LIT:start>' : new_start } ) <EOL> form = OccurrenceForm ( data = data , initial = initial ) <EOL> self . assertTrue ( form . is_valid ( ) , msg = ( <EOL> '<STR_LIT>' ) ) <EOL> form . save ( ) <EOL> self . assertEqual ( Event . objects . all ( ) . count ( ) , <NUM_LIT:3> , msg = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> event1 = Event . objects . get ( pk = self . rec_event . pk ) <EOL> event2 = Event . objects . exclude ( <EOL> pk__in = [ self . rec_event . pk , self . event . pk ] ) . get ( ) <EOL> self . assertEqual ( <EOL> event1 . end_recurring_period , <EOL> event2 . start - timedelta ( days = <NUM_LIT:1> ) , msg = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> event2 . end_recurring_period , self . rec_event . end_recurring_period , <EOL> msg = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) </s>
