def test_pending_invoice(self): self.policy.billing_schedule = "Annual" pa = PolicyAccounting(self.policy.id) invoices_pending = pa.evaluate_cancellation_pending_due_to_non_pay( date(2015, 3, 3)) self.assertEquals(invoices_pending, True) invoices_pending = pa.evaluate_cancellation_pending_due_to_non_pay( date(2015, 2, 1)) self.assertEquals(invoices_pending, False)
def test_pending_no_payment_before_cancellation_edge(self): """ Same as above, but testing edge case of date_cursor == due_date """ pa = PolicyAccounting(self.policy.id) # No payment made and we are past the due date, but before cancellation d = date(2015, 2, 1) self.assertTrue( pa.evaluate_cancellation_pending_due_to_non_pay(date_cursor=d))
def test_pending_no_payment_after_cancellation_edge(self): """ Test the method when the account is pending cancellation and after cancellation date has been reached. """ pa = PolicyAccounting(self.policy.id) # No payment made and we are past the due date, but before cancellation d = date(2015, 2, 14) self.assertTrue( pa.evaluate_cancellation_pending_due_to_non_pay(date_cursor=d))
def test_evaluate_pending(self): self.policy.billing_schedule = "Annual" pa = PolicyAccounting(self.policy.id) # Test Evaluate cancellation pending self.assertEquals( pa.evaluate_cancellation_pending_due_to_non_pay(date(2015, 2, 2)), True) # Made payment by insured p = pa.make_payment(date_cursor=date(2015, 2, 2), amount=1200) # None return cause payment must be made by agent self.assertEquals(p, None)
def test_pending_payment_before_cancellation_edge(self): """ Same as above, but when an insufficient payment has been made """ pa = PolicyAccounting(self.policy.id) self.payments.append( pa.make_payment(contact_id=self.policy.named_insured, date_cursor=date(2015, 1, 15), amount=100)) # No payment made and we are past the due date, but before cancellation d = date(2015, 3, 1) self.assertTrue( pa.evaluate_cancellation_pending_due_to_non_pay(date_cursor=d))
def test_good_standing_no_payment(self): """ Test the method when the account is in good standing and no payment has been made. """ pa = PolicyAccounting(self.policy.id) # Note that on 2015/1/2 the account is in good standing even # when no payment has been made d = date(2015, 1, 10) self.assertFalse( pa.evaluate_cancellation_pending_due_to_non_pay(date_cursor=d))
def test_evaluate_cancellation_pending(self): policy = Policy('Test Policy', date(2015, 1, 1), 1200) policy.named_insured = self.test_insured.id policy.agent = self.test_agent.id self.policies.append(policy) db.session.add(policy) db.session.commit() # Get the policy from the database policy.billing_schedule = "Annual" pa = PolicyAccounting(policy.id) # Evaluate status on eff date self.assertFalse(pa.evaluate_cancellation_pending_due_to_non_pay(date_cursor=date(2015, 1, 1))) # Evaluate status on due date self.assertFalse(pa.evaluate_cancellation_pending_due_to_non_pay(date_cursor=date(2015, 2, 1))) # Evaluate status after due date and before cancel date self.assertTrue(pa.evaluate_cancellation_pending_due_to_non_pay(date_cursor=date(2015, 2, 2))) # Need to test this with a different billing schedule to ensure that overlapping invoices # are not causing errors. policy.billing_schedule = "Monthly" pa.make_invoices() # Make a payment self.payments.append(pa.make_payment(date_cursor=date(2015, 01, 01), amount=100))
def test_pending_payment_before_cancellation(self): """ Test the method when a payment has been made on the invoice but the account is pending cancellation and before cancellation date has been reached. """ pa = PolicyAccounting(self.policy.id) self.payments.append( pa.make_payment(contact_id=self.policy.named_insured, date_cursor=date(2015, 1, 15), amount=100)) # Second payment made and we are past the due date, but before cancellation d = date(2015, 3, 10) self.assertTrue( pa.evaluate_cancellation_pending_due_to_non_pay(date_cursor=d))
def test_good_standing_payment(self): """ Test the method when the account is in good standing and a payment has been made """ pa = PolicyAccounting(self.policy.id) self.payments.append( pa.make_payment(contact_id=self.policy.named_insured, date_cursor=date(2015, 1, 15), amount=100)) # First billing cycle should be covered by above payment, so # a date in the middle of the second cycle should be good d = date(2015, 2, 10) # print(pa.return_account_balance(d)) self.assertFalse( pa.evaluate_cancellation_pending_due_to_non_pay(date_cursor=d))
class TestCancellationPolicies(unittest.TestCase): @classmethod def setUpClass(cls): cls.test_agent = Contact('Test Agent', 'Agent') cls.test_insured = Contact('Test Insured', 'Named Insured') db.session.add(cls.test_agent) db.session.add(cls.test_insured) db.session.commit() cls.policy = Policy('Test Policy', date(2015, 1, 1), 1600) cls.policy.named_insured = cls.test_insured.id cls.policy.agent = cls.test_agent.id cls.policy.billing_schedule = "Quarterly" db.session.add(cls.policy) db.session.commit() @classmethod def tearDownClass(cls): db.session.delete(cls.test_insured) db.session.delete(cls.test_agent) db.session.delete(cls.policy) db.session.commit() def setUp(self): self.payments = [] self.pa = PolicyAccounting(self.policy.id) self.invoices = Invoice.query.filter_by( policy_id=self.policy.id).order_by(Invoice.bill_date).all() self.payments.append( self.pa.make_payment(contact_id=self.policy.named_insured, date_cursor=self.invoices[0].bill_date, amount=400)) self.pa.evaluate_cancel = MagicMock( side_effect=self.pa.evaluate_cancel) def tearDown(self): for invoice in self.policy.invoices: db.session.delete(invoice) for payment in self.payments: db.session.delete(payment) db.session.commit() def test_Given_unpaid_policy_When_cancellation_pending_before_cancel_date_Then_not_due_to_cancel( self): # evaluation date it's 10 days after due_date evaluation_date = self.invoices[1].due_date + relativedelta(days=10) result = self.pa.evaluate_cancellation_pending_due_to_non_pay( date_cursor=evaluation_date) self.pa.evaluate_cancel.assert_called_with(evaluation_date) self.assertIsNotNone(result) self.assertFalse(result) def test_Given_unpaid_policy_When_cancellation_pending_past_cancel_date_Then_due_to_cancel( self): # evaluation date it's 20 days after due_date evaluation_date = self.invoices[1].due_date + relativedelta(days=20) result = self.pa.evaluate_cancellation_pending_due_to_non_pay( date_cursor=evaluation_date) self.assertIsNotNone(result) self.assertTrue(result) def test_Given_paid_policy_after_bill_date_When_paid_before_cancel_date_Then_not_due_to_cancel( self): # the policy has been paid 8 days after due date self.payments.append( self.pa.make_payment(contact_id=self.policy.named_insured, date_cursor=self.invoices[1].due_date + relativedelta(days=8), amount=400)) evaluation_date = self.invoices[1].due_date + relativedelta(days=20) result = self.pa.evaluate_cancellation_pending_due_to_non_pay( date_cursor=evaluation_date) self.pa.evaluate_cancel.assert_called_with(evaluation_date) self.assertIsNotNone(result) self.assertFalse(result) def test_Given_policy_to_cancel_When_policy_canceled_Then_policy_data_updated( self): pa = PolicyAccounting(self.policy.id) pa.cancel_policy("underwriting") self.assertEqual(pa.policy.status, 'Canceled') self.assertEqual(pa.policy.reason, "underwriting") self.assertEqual(pa.policy.date_changed, datetime.now().date())
def test_evaluate_cancellation_pending_after_due_date(self): self.policy.billing_schedule = "Annual" pa = PolicyAccounting(self.policy) self.assertEquals(pa.evaluate_cancellation_pending_due_to_non_pay(date(2015, 1, 17)), False)
def test_pending_cancellation_equal_due_date_true(self): pa = PolicyAccounting(self.policy.id) self.assertEquals( pa.evaluate_cancellation_pending_due_to_non_pay( date_cursor=date(2015, 3, 1)), True)
def test_pending_cancellation_false(self): pa = PolicyAccounting(self.policy.id) self.assertEquals( pa.evaluate_cancellation_pending_due_to_non_pay( date_cursor=date(2015, 2, 8)), False)
def test_evaluate_cancellation_pending_due_to_non_pay(self): pa = PolicyAccounting(self.policy.id) cancellation_pending = pa.evaluate_cancellation_pending_due_to_non_pay(date(2015, 1, 17)) self.assertEquals(cancellation_pending, True)