<s> import datetime <EOL> import decimal <EOL> from django . test import TestCase <EOL> from django . utils import timezone <EOL> from django . contrib . auth import get_user_model <EOL> from . . models import Customer , Subscription , Charge , Plan <EOL> class CustomerManagerTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> User = get_user_model ( ) <EOL> period_start = datetime . datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> , tzinfo = timezone . utc ) <EOL> period_end = datetime . datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:30> , tzinfo = timezone . utc ) <EOL> start = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , tzinfo = timezone . utc ) <EOL> self . plan = Plan . objects . create ( <EOL> stripe_id = "<STR_LIT>" , <EOL> amount = <NUM_LIT:10> , <EOL> currency = "<STR_LIT>" , <EOL> interval = "<STR_LIT>" , <EOL> interval_count = <NUM_LIT:1> , <EOL> name = "<STR_LIT>" <EOL> ) <EOL> self . plan2 = Plan . objects . create ( <EOL> stripe_id = "<STR_LIT>" , <EOL> amount = <NUM_LIT:5> , <EOL> currency = "<STR_LIT>" , <EOL> interval = "<STR_LIT>" , <EOL> interval_count = <NUM_LIT:1> , <EOL> name = "<STR_LIT>" <EOL> ) <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> customer = Customer . objects . create ( <EOL> user = User . objects . create_user ( username = "<STR_LIT>" . format ( i ) ) , <EOL> stripe_id = "<STR_LIT>" . format ( i ) <EOL> ) <EOL> Subscription . objects . create ( <EOL> stripe_id = "<STR_LIT>" . format ( i ) , <EOL> customer = customer , <EOL> plan = self . plan , <EOL> current_period_start = period_start , <EOL> current_period_end = period_end , <EOL> status = "<STR_LIT>" , <EOL> start = start , <EOL> quantity = <NUM_LIT:1> <EOL> ) <EOL> customer = Customer . objects . create ( <EOL> user = User . objects . create_user ( username = "<STR_LIT>" . format ( <NUM_LIT:11> ) ) , <EOL> stripe_id = "<STR_LIT>" . format ( <NUM_LIT:11> ) <EOL> ) <EOL> Subscription . objects . create ( <EOL> stripe_id = "<STR_LIT>" . format ( <NUM_LIT:11> ) , <EOL> customer = customer , <EOL> plan = self . plan , <EOL> current_period_start = period_start , <EOL> current_period_end = period_end , <EOL> status = "<STR_LIT>" , <EOL> canceled_at = period_end , <EOL> start = start , <EOL> quantity = <NUM_LIT:1> <EOL> ) <EOL> customer = Customer . objects . create ( <EOL> user = User . objects . create_user ( username = "<STR_LIT>" . format ( <NUM_LIT:12> ) ) , <EOL> stripe_id = "<STR_LIT>" . format ( <NUM_LIT:12> ) <EOL> ) <EOL> Subscription . objects . create ( <EOL> stripe_id = "<STR_LIT>" . format ( <NUM_LIT:12> ) , <EOL> customer = customer , <EOL> plan = self . plan2 , <EOL> current_period_start = period_start , <EOL> current_period_end = period_end , <EOL> status = "<STR_LIT>" , <EOL> start = start , <EOL> quantity = <NUM_LIT:1> <EOL> ) <EOL> def test_started_during_no_records ( self ) : <EOL> self . assertEquals ( <EOL> Customer . objects . started_during ( <NUM_LIT> , <NUM_LIT:4> ) . count ( ) , <EOL> <NUM_LIT:0> <EOL> ) <EOL> def test_started_during_has_records ( self ) : <EOL> self . assertEquals ( <EOL> Customer . objects . started_during ( <NUM_LIT> , <NUM_LIT:1> ) . count ( ) , <EOL> <NUM_LIT:12> <EOL> ) <EOL> def test_canceled_during ( self ) : <EOL> self . assertEquals ( <EOL> Customer . objects . canceled_during ( <NUM_LIT> , <NUM_LIT:4> ) . count ( ) , <EOL> <NUM_LIT:1> <EOL> ) <EOL> def test_canceled_all ( self ) : <EOL> self . assertEquals ( <EOL> Customer . objects . canceled ( ) . count ( ) , <EOL> <NUM_LIT:1> <EOL> ) <EOL> def test_active_all ( self ) : <EOL> self . assertEquals ( <EOL> Customer . objects . active ( ) . count ( ) , <EOL> <NUM_LIT:11> <EOL> ) <EOL> def test_started_plan_summary ( self ) : <EOL> for plan in Customer . objects . started_plan_summary_for ( <NUM_LIT> , <NUM_LIT:1> ) : <EOL> if plan [ "<STR_LIT>" ] == self . plan : <EOL> self . assertEquals ( plan [ "<STR_LIT:count>" ] , <NUM_LIT:11> ) <EOL> if plan [ "<STR_LIT>" ] == self . plan2 : <EOL> self . assertEquals ( plan [ "<STR_LIT:count>" ] , <NUM_LIT:1> ) <EOL> def test_active_plan_summary ( self ) : <EOL> for plan in Customer . objects . active_plan_summary ( ) : <EOL> if plan [ "<STR_LIT>" ] == self . plan : <EOL> self . assertEquals ( plan [ "<STR_LIT:count>" ] , <NUM_LIT:10> ) <EOL> if plan [ "<STR_LIT>" ] == self . plan2 : <EOL> self . assertEquals ( plan [ "<STR_LIT:count>" ] , <NUM_LIT:1> ) <EOL> def test_canceled_plan_summary ( self ) : <EOL> for plan in Customer . objects . canceled_plan_summary_for ( <NUM_LIT> , <NUM_LIT:1> ) : <EOL> if plan [ "<STR_LIT>" ] == self . plan : <EOL> self . assertEquals ( plan [ "<STR_LIT:count>" ] , <NUM_LIT:1> ) <EOL> if plan [ "<STR_LIT>" ] == self . plan2 : <EOL> self . assertEquals ( plan [ "<STR_LIT:count>" ] , <NUM_LIT:0> ) <EOL> def test_churn ( self ) : <EOL> self . assertEquals ( <EOL> Customer . objects . churn ( ) , <EOL> decimal . Decimal ( "<STR_LIT:1>" ) / decimal . Decimal ( "<STR_LIT>" ) <EOL> ) <EOL> class ChargeManagerTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> customer = Customer . objects . create ( <EOL> user = get_user_model ( ) . objects . create_user ( username = "<STR_LIT>" ) , <EOL> stripe_id = "<STR_LIT>" <EOL> ) <EOL> Charge . objects . create ( <EOL> stripe_id = "<STR_LIT>" , <EOL> customer = customer , <EOL> charge_created = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , tzinfo = timezone . utc ) , <EOL> paid = True , <EOL> amount = decimal . Decimal ( "<STR_LIT:100>" ) , <EOL> amount_refunded = decimal . Decimal ( "<STR_LIT:0>" ) <EOL> ) <EOL> Charge . objects . create ( <EOL> stripe_id = "<STR_LIT>" , <EOL> customer = customer , <EOL> charge_created = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , tzinfo = timezone . utc ) , <EOL> paid = True , <EOL> amount = decimal . Decimal ( "<STR_LIT:100>" ) , <EOL> amount_refunded = decimal . Decimal ( "<STR_LIT>" ) <EOL> ) <EOL> Charge . objects . create ( <EOL> stripe_id = "<STR_LIT>" , <EOL> customer = customer , <EOL> charge_created = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , tzinfo = timezone . utc ) , <EOL> paid = False , <EOL> amount = decimal . Decimal ( "<STR_LIT:100>" ) , <EOL> amount_refunded = decimal . Decimal ( "<STR_LIT:0>" ) <EOL> ) <EOL> Charge . objects . create ( <EOL> stripe_id = "<STR_LIT>" , <EOL> customer = customer , <EOL> charge_created = datetime . datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> , tzinfo = timezone . utc ) , <EOL> paid = True , <EOL> amount = decimal . Decimal ( "<STR_LIT>" ) , <EOL> amount_refunded = decimal . Decimal ( "<STR_LIT>" ) <EOL> ) <EOL> def test_charges_during ( self ) : <EOL> charges = Charge . objects . during ( <NUM_LIT> , <NUM_LIT:1> ) <EOL> self . assertEqual ( charges . count ( ) , <NUM_LIT:3> ) <EOL> def test_paid_totals_for_jan ( self ) : <EOL> totals = Charge . objects . paid_totals_for ( <NUM_LIT> , <NUM_LIT:1> ) <EOL> self . assertEqual ( totals [ "<STR_LIT>" ] , decimal . Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( totals [ "<STR_LIT>" ] , decimal . Decimal ( "<STR_LIT>" ) ) <EOL> def test_paid_totals_for_apr ( self ) : <EOL> totals = Charge . objects . paid_totals_for ( <NUM_LIT> , <NUM_LIT:4> ) <EOL> self . assertEqual ( totals [ "<STR_LIT>" ] , decimal . Decimal ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( totals [ "<STR_LIT>" ] , decimal . Decimal ( "<STR_LIT>" ) ) <EOL> def test_paid_totals_for_dec ( self ) : <EOL> totals = Charge . objects . paid_totals_for ( <NUM_LIT> , <NUM_LIT:12> ) <EOL> self . assertEqual ( totals [ "<STR_LIT>" ] , None ) <EOL> self . assertEqual ( totals [ "<STR_LIT>" ] , None ) </s>
