<s> from datetime import datetime <EOL> from django . utils . timezone import make_aware <EOL> from recurrence import choices <EOL> from recurrence . models import Date , Recurrence , Rule <EOL> import pytest <EOL> import pytz <EOL> import recurrence <EOL> def aware ( dt ) : <EOL> return make_aware ( dt , pytz . utc ) <EOL> @ pytest . mark . django_db <EOL> def test_recurrence_to_recurrence_object ( ) : <EOL> limits = Recurrence . objects . create ( ) <EOL> Rule . objects . create ( <EOL> recurrence = limits , <EOL> mode = choices . INCLUSION , <EOL> freq = recurrence . WEEKLY <EOL> ) <EOL> object = limits . to_recurrence_object ( ) <EOL> assert [ r . to_text ( ) for r in object . rrules ] == [ '<STR_LIT>' ] <EOL> assert object . exrules == [ ] <EOL> assert object . rdates == [ ] <EOL> assert object . exdates == [ ] <EOL> @ pytest . mark . django_db <EOL> def test_recurrence_to_recurrence_object_complex ( ) : <EOL> limits = Recurrence . objects . create ( <EOL> dtstart = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> dtend = datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> ) <EOL> Rule . objects . create ( <EOL> recurrence = limits , <EOL> mode = choices . INCLUSION , <EOL> freq = recurrence . WEEKLY , <EOL> until = aware ( datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> ) <EOL> Rule . objects . create ( <EOL> recurrence = limits , <EOL> mode = choices . EXCLUSION , <EOL> freq = recurrence . MONTHLY , <EOL> until = aware ( datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> ) <EOL> Date . objects . create ( <EOL> recurrence = limits , <EOL> mode = choices . INCLUSION , <EOL> dt = aware ( datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> ) <EOL> Date . objects . create ( <EOL> recurrence = limits , <EOL> mode = choices . EXCLUSION , <EOL> dt = aware ( datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> ) <EOL> object = limits . to_recurrence_object ( ) <EOL> assert object . dtstart == aware ( datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> assert object . dtend == aware ( datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> assert len ( object . rrules ) == <NUM_LIT:1> <EOL> output_rule = object . rrules [ <NUM_LIT:0> ] <EOL> assert output_rule . freq == recurrence . WEEKLY <EOL> assert output_rule . until == aware ( datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> assert len ( object . exrules ) == <NUM_LIT:1> <EOL> output_rule = object . exrules [ <NUM_LIT:0> ] <EOL> assert output_rule . freq == recurrence . MONTHLY <EOL> assert output_rule . until == aware ( datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> @ pytest . mark . django_db <EOL> def test_recurrence_to_recurrence_object_non_naive_sd_ed ( ) : <EOL> limits = Recurrence . objects . create ( <EOL> dtstart = aware ( datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) , <EOL> dtend = aware ( datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) , <EOL> ) <EOL> object = limits . to_recurrence_object ( ) <EOL> assert object . dtstart == aware ( datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> assert object . dtend == aware ( datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> @ pytest . mark . django_db <EOL> def test_create_from_recurrence_object ( ) : <EOL> inrule = recurrence . Rule ( <EOL> recurrence . WEEKLY <EOL> ) <EOL> exrule = recurrence . Rule ( <EOL> recurrence . MONTHLY <EOL> ) <EOL> limits = recurrence . Recurrence ( <EOL> dtstart = datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> dtend = datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> rrules = [ inrule ] , <EOL> exrules = [ exrule ] , <EOL> rdates = [ datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ] , <EOL> exdates = [ aware ( datetime ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) ] <EOL> ) <EOL> object = Recurrence . objects . create_from_recurrence_object ( limits ) <EOL> assert object . dtstart == aware ( datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> assert object . dtend == aware ( datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> rules = object . rules . all ( ) <EOL> assert len ( rules ) == <NUM_LIT:2> <EOL> in_rules = [ r for r in rules if r . mode == choices . INCLUSION ] <EOL> out_rules = [ r for r in rules if r . mode == choices . EXCLUSION ] <EOL> assert len ( in_rules ) == <NUM_LIT:1> <EOL> assert len ( out_rules ) == <NUM_LIT:1> <EOL> assert in_rules [ <NUM_LIT:0> ] . freq == recurrence . WEEKLY <EOL> assert out_rules [ <NUM_LIT:0> ] . freq == recurrence . MONTHLY <EOL> dates = object . dates . all ( ) <EOL> assert len ( dates ) == <NUM_LIT:2> <EOL> in_dates = [ d for d in dates if d . mode == choices . INCLUSION ] <EOL> out_dates = [ d for d in dates if d . mode == choices . EXCLUSION ] <EOL> assert len ( in_dates ) == <NUM_LIT:1> <EOL> assert len ( out_dates ) == <NUM_LIT:1> <EOL> assert in_dates [ <NUM_LIT:0> ] . dt == aware ( datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> assert out_dates [ <NUM_LIT:0> ] . dt == aware ( datetime ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) </s>
