def test_cancel_contract_positive_balance(self): """ Test that the balance is charged as the cancellation fee if the contract is cancelled while the balance is positive. """ pc = PrepaidContract(datetime.date(2000, 9, 29), 10) pc.new_month(month=10, year=2000, bill=Bill()) # make a call that costs $15 c1 = Call(src_nr="123-4567", dst_nr="987-6543", calltime=datetime.datetime(year=2000, month=10, day=31, hour=20, minute=30, second=0), duration=ceil(15 / PREPAID_MINS_COST * 60), src_loc=(-79.45188229255568, 43.62186408875219), dst_loc=(-79.36866519485261, 43.680793196449336)) pc.bill_call(c1) # since the call was very long, the balance should be positive now self.assertAlmostEqual(pc.balance, 5) cancel = pc.cancel_contract() # since the balance is positive, it should be billed, so the cost for # the month should be the balance self.assertAlmostEqual(cancel, pc.balance)
def test_cancel_contract_negative_balance(self): """ Test that $0 is charged as the cancellation fee if the contract is cancelled while the balance is negative (aka some credit exists). """ pc = PrepaidContract(datetime.date(2000, 9, 29), 25) pc.new_month(month=10, year=2000, bill=Bill()) self.assertAlmostEqual(pc.balance, -25) cancel = pc.cancel_contract() # since the balance is negative, it should be forfeited, so the cost for # the month should be $0 self.assertAlmostEqual(cancel, 0)
def test_new_month_no_top_off(self): """ Test that the new_month function works in general, aka test that it sets up the bill and rate correctly, and that it sets up and bills the balance correctly. Test that the balance is NOT topped off if there is >=$10 of credit. """ pc = PrepaidContract(datetime.date(2000, 9, 29), 100) bill1 = Bill() pc.new_month(month=10, year=2000, bill=bill1) assert pc.bill is bill1 # the balance should not have changed self.assertAlmostEqual(pc.balance, -100) # the bill cost should be the balance self.assertAlmostEqual(pc.bill.get_cost(), pc.balance) bill2 = Bill() pc.new_month(month=11, year=2000, bill=bill2) assert pc.bill is bill2 # the balance still should not have changed self.assertAlmostEqual(pc.balance, -100) self.assertAlmostEqual(pc.bill.get_cost(), pc.balance)
def test_new_month_top_off(self): """ Test that the new_month function works in general, aka test that it sets up the bill and rate correctly, and that it sets up and bills the balance correctly. Test that the balance is topped off if there is <$10 of credit, and not unnecessarily topped off after that. """ pc = PrepaidContract(datetime.date(2000, 9, 29), 0) bill1 = Bill() pc.new_month(month=10, year=2000, bill=bill1) assert pc.bill is bill1 self.assertEqual(pc.bill.min_rate, PREPAID_MINS_COST) # the balance should have decreased by $25 because of the top off self.assertEqual(pc.balance, -25) # the customer should not be billed for the top off, their bill should # simply reflect the new balance self.assertAlmostEqual(pc.bill.get_cost(), pc.balance) bill2 = Bill() pc.new_month(month=11, year=2000, bill=bill2) assert pc.bill is bill2 self.assertEqual(pc.bill.min_rate, PREPAID_MINS_COST) # the balance should not have changed self.assertEqual(pc.balance, -25) self.assertAlmostEqual(pc.bill.get_cost(), pc.balance)