<s> from __future__ import unicode_literals <EOL> import unittest <EOL> from freezegun import freeze_time <EOL> from billy . models . plan import PlanModel <EOL> from billy . models . schedule import next_transaction_datetime <EOL> from billy . utils . generic import utc_now <EOL> from billy . utils . generic import utc_datetime <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> class TestSchedule ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . plan_model = PlanModel <EOL> def assert_schedule ( self , started_at , frequency , interval , length , expected ) : <EOL> result = [ ] <EOL> for period in range ( length ) : <EOL> dt = next_transaction_datetime ( <EOL> started_at = started_at , <EOL> frequency = frequency , <EOL> period = period , <EOL> interval = interval , <EOL> ) <EOL> result . append ( dt ) <EOL> self . assertEqual ( result , expected ) <EOL> def test_invalid_interval ( self ) : <EOL> with self . assertRaises ( ValueError ) : <EOL> next_transaction_datetime ( <EOL> started_at = utc_now ( ) , <EOL> frequency = self . plan_model . frequencies . DAILY , <EOL> period = <NUM_LIT:0> , <EOL> interval = <NUM_LIT:0> , <EOL> ) <EOL> with self . assertRaises ( ValueError ) : <EOL> next_transaction_datetime ( <EOL> started_at = utc_now ( ) , <EOL> frequency = self . plan_model . frequencies . DAILY , <EOL> period = <NUM_LIT:0> , <EOL> interval = - <NUM_LIT:1> , <EOL> ) <EOL> def test_daily_schedule ( self ) : <EOL> with freeze_time ( '<STR_LIT>' ) : <EOL> now = utc_now ( ) <EOL> self . assert_schedule ( <EOL> started_at = now , <EOL> frequency = self . plan_model . frequencies . DAILY , <EOL> interval = <NUM_LIT:1> , <EOL> length = <NUM_LIT:10> , <EOL> expected = [ <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:30> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:1> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:2> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:3> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:4> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:5> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:6> ) , <EOL> ] <EOL> ) <EOL> def test_daily_schedule_with_interval ( self ) : <EOL> with freeze_time ( '<STR_LIT>' ) : <EOL> now = utc_now ( ) <EOL> self . assert_schedule ( <EOL> started_at = now , <EOL> frequency = self . plan_model . frequencies . DAILY , <EOL> interval = <NUM_LIT:3> , <EOL> length = <NUM_LIT:4> , <EOL> expected = [ <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:3> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:6> ) , <EOL> ] <EOL> ) <EOL> def test_daily_schedule_with_end_of_month ( self ) : <EOL> def assert_next_day ( now_dt , expected ) : <EOL> with freeze_time ( now_dt ) : <EOL> now = utc_now ( ) <EOL> next_dt = next_transaction_datetime ( <EOL> started_at = now , <EOL> frequency = self . plan_model . frequencies . DAILY , <EOL> period = <NUM_LIT:1> , <EOL> ) <EOL> self . assertEqual ( next_dt , expected ) <EOL> assert_next_day ( '<STR_LIT>' , utc_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:1> ) ) <EOL> assert_next_day ( '<STR_LIT>' , utc_datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:1> ) ) <EOL> assert_next_day ( '<STR_LIT>' , utc_datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> ) ) <EOL> assert_next_day ( '<STR_LIT>' , utc_datetime ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:1> ) ) <EOL> assert_next_day ( '<STR_LIT>' , utc_datetime ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:1> ) ) <EOL> assert_next_day ( '<STR_LIT>' , utc_datetime ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:1> ) ) <EOL> assert_next_day ( '<STR_LIT>' , utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:1> ) ) <EOL> assert_next_day ( '<STR_LIT>' , utc_datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:1> ) ) <EOL> assert_next_day ( '<STR_LIT>' , utc_datetime ( <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT:1> ) ) <EOL> assert_next_day ( '<STR_LIT>' , utc_datetime ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT:1> ) ) <EOL> assert_next_day ( '<STR_LIT>' , utc_datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:1> ) ) <EOL> assert_next_day ( '<STR_LIT>' , utc_datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> def test_weekly_schedule ( self ) : <EOL> with freeze_time ( '<STR_LIT>' ) : <EOL> now = utc_now ( ) <EOL> self . assert_schedule ( <EOL> started_at = now , <EOL> frequency = self . plan_model . frequencies . WEEKLY , <EOL> interval = <NUM_LIT:1> , <EOL> length = <NUM_LIT:5> , <EOL> expected = [ <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:1> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:8> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:15> ) , <EOL> ] <EOL> ) <EOL> def test_weekly_schedule_with_interval ( self ) : <EOL> with freeze_time ( '<STR_LIT>' ) : <EOL> now = utc_now ( ) <EOL> self . assert_schedule ( <EOL> started_at = now , <EOL> frequency = self . plan_model . frequencies . WEEKLY , <EOL> interval = <NUM_LIT:2> , <EOL> length = <NUM_LIT:3> , <EOL> expected = [ <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:1> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:15> ) , <EOL> ] <EOL> ) <EOL> def test_monthly_schedule ( self ) : <EOL> with freeze_time ( '<STR_LIT>' ) : <EOL> now = utc_now ( ) <EOL> self . assert_schedule ( <EOL> started_at = now , <EOL> frequency = self . plan_model . frequencies . MONTHLY , <EOL> interval = <NUM_LIT:1> , <EOL> length = <NUM_LIT:6> , <EOL> expected = [ <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT> ) , <EOL> ] <EOL> ) <EOL> def test_monthly_schedule_with_interval ( self ) : <EOL> with freeze_time ( '<STR_LIT>' ) : <EOL> now = utc_now ( ) <EOL> self . assert_schedule ( <EOL> started_at = now , <EOL> frequency = self . plan_model . frequencies . MONTHLY , <EOL> interval = <NUM_LIT:6> , <EOL> length = <NUM_LIT:4> , <EOL> expected = [ <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> ) , <EOL> ] <EOL> ) <EOL> def test_monthly_schedule_with_end_of_month ( self ) : <EOL> with freeze_time ( '<STR_LIT>' ) : <EOL> now = utc_now ( ) <EOL> self . assert_schedule ( <EOL> started_at = now , <EOL> frequency = self . plan_model . frequencies . MONTHLY , <EOL> interval = <NUM_LIT:1> , <EOL> length = <NUM_LIT:7> , <EOL> expected = [ <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:30> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT:30> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> ) , <EOL> ] <EOL> ) <EOL> with freeze_time ( '<STR_LIT>' ) : <EOL> now = utc_now ( ) <EOL> self . assert_schedule ( <EOL> started_at = now , <EOL> frequency = self . plan_model . frequencies . MONTHLY , <EOL> interval = <NUM_LIT:1> , <EOL> length = <NUM_LIT:6> , <EOL> expected = [ <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT:30> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:30> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:30> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:30> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:30> ) , <EOL> ] <EOL> ) <EOL> def test_yearly_schedule ( self ) : <EOL> with freeze_time ( '<STR_LIT>' ) : <EOL> now = utc_now ( ) <EOL> self . assert_schedule ( <EOL> started_at = now , <EOL> frequency = self . plan_model . frequencies . YEARLY , <EOL> interval = <NUM_LIT:1> , <EOL> length = <NUM_LIT:5> , <EOL> expected = [ <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> ) , <EOL> ] ) <EOL> def test_yearly_schedule_with_interval ( self ) : <EOL> with freeze_time ( '<STR_LIT>' ) : <EOL> now = utc_now ( ) <EOL> self . assert_schedule ( <EOL> started_at = now , <EOL> frequency = self . plan_model . frequencies . YEARLY , <EOL> interval = <NUM_LIT:2> , <EOL> length = <NUM_LIT:3> , <EOL> expected = [ <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> ) , <EOL> ] ) <EOL> def test_yearly_schedule_with_leap_year ( self ) : <EOL> with freeze_time ( '<STR_LIT>' ) : <EOL> now = utc_now ( ) <EOL> self . assert_schedule ( <EOL> started_at = now , <EOL> frequency = self . plan_model . frequencies . YEARLY , <EOL> interval = <NUM_LIT:1> , <EOL> length = <NUM_LIT:5> , <EOL> expected = [ <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> ) , <EOL> utc_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> ) , <EOL> ] <EOL> ) </s>
