Example #1
0
 def test_deleted_invoices_changed_billing_schedule_from_monthly(self):
     self.policy.billing_schedule = "Monthly"
     pa = PolicyAccounting(self.policy)
     pa.change_billing_schedule("Quarterly")
     invoices = Invoice.query.filter_by(policy_id=self.policy.id)\
                             .filter(Invoice.deleted.is_(True))\
                             .all()
     self.assertEquals(len(invoices), 12)
Example #2
0
 def test_new_invoices_changed_billing_schedule_from_two_pay(self):
     self.policy.billing_schedule = "Quarterly"
     pa = PolicyAccounting(self.policy)
     pa.change_billing_schedule("Two-Pay")
     invoices = Invoice.query.filter_by(policy_id=self.policy.id) \
                             .filter(Invoice.deleted.is_(False)) \
                             .all()
     self.assertEquals(len(invoices), 2)
Example #3
0
 def test_quarterly_on_eff_date_after_change(self):
     """
     Same as above, but after a change in billing schedule.
     """
     self.policy.billing_schedule = "Monthly"
     pa = PolicyAccounting(self.policy.id)
     pa.change_billing_schedule("Quarterly")
     self.assertEquals(
         pa.return_account_balance(date_cursor=self.policy.effective_date),
         300)
Example #4
0
 def test_quarterly_on_last_installment_bill_date_after_change(self):
     """
     Same as above, buf after change in billing schedule.
     """
     self.policy.billing_schedule = "Monthly"
     pa = PolicyAccounting(self.policy.id)
     pa.change_billing_schedule("Quarterly")
     invoices = Invoice.query.filter_by(policy_id=self.policy.id)\
                             .filter(Invoice.deleted == False)\
                             .order_by(Invoice.bill_date).all()
     self.assertEquals(
         pa.return_account_balance(date_cursor=invoices[3].bill_date), 1200)
Example #5
0
    def test_change_billing_schedule_two_pay_to_annual(self):
        print "Testing change of billing schedule from two-pay to annual...\n"
        self.policy.annual_premium = 1200
        self.policy.billing_schedule = 'Two-Pay'

        pa = PolicyAccounting(self.policy.id)

        self.assertTrue(self.policy.invoices)

        invoice = Invoice.query.filter_by(policy_id=self.policy.id).first()
        invoice.amount_due = 0

        pa.change_billing_schedule("Annual")
        db.session.rollback()
 def test_change_billing_schedule_tp_a(self):
     """
      Test change billing from two pay to annual
     """
     self.policy.billing_schedule = "Two-Pay"
     # No invoices currently exist
     self.assertFalse(self.policy.invoices)
     # Invoices should be made when the class is initiated
     pa = PolicyAccounting(self.policy.id)
     self.assertEquals(len(self.policy.invoices), 2)
     self.assertEquals(self.policy.invoices[1].amount_due,
                       self.policy.annual_premium / 2)
     pa.change_billing_schedule('Annual')
     # Invoice count should still be 2 cause unsuccess changing
     self.assertEquals(len(self.policy.invoices), 2)
Example #7
0
    def test_change_billing_schedule_monthly_to_two_pay(self):
        print "Testing change of billing schedule from monthly to two-pay...\n"
        self.policy.annual_premium = 1200
        self.policy.billing_schedule = 'Monthly'

        pa = PolicyAccounting(self.policy.id)

        self.assertTrue(self.policy.invoices)

        invoices = Invoice.query.filter_by(policy_id=self.policy.id).all()
        for i in range(0, 5):
            invoices[i].amount_due = 0

        pa.change_billing_schedule("Two-Pay")
        db.session.rollback()
Example #8
0
    def test_update_billing_schedule_to_same_schedule(self):
        self.policy.billing_schedule = "Annual"
        #No invoices currently exist
        self.assertFalse(self.policy.invoices)
        #Invoices should be made when the class is initiated
        pa = PolicyAccounting(self.policy.id)
        #There is 1 invoice in total before updating
        self.assertEqual(len(self.policy.invoices), 1)

        #Call change billing schedule with Random option
        pa.change_billing_schedule("Annual")

        #There is 1 invoice in total after updating
        self.assertEqual(len(self.policy.invoices), 1)
        #None have been marked as deleted
        self.assertEqual(self.policy.invoices[0].deleted, False)
 def test_change_billing_schedule_a_m(self):
     self.policy.billing_schedule = "Annual"
     # No invoices currently exist
     self.assertFalse(self.policy.invoices)
     # Invoices should be made when the class is initiated
     pa = PolicyAccounting(self.policy.id)
     self.assertEquals(len(self.policy.invoices), 1)
     self.assertEquals(self.policy.invoices[0].amount_due,
                       self.policy.annual_premium / 1)
     # Make payment
     self.payments.append(
         pa.make_payment(self.policy.agent, date(2015, 1, 1), 1200))
     # Change billing schedule to Monthly
     pa.change_billing_schedule('Monthly')
     # Shoulnt be able to change schedule cause paid already, invoices should still be one
     self.assertEquals(len(self.policy.invoices), 1)
Example #10
0
 def test_quarterly_on_second_installment_bill_date_with_full_payment_after_change(
         self):
     """
     Same as above, buf after change in billing schedule.
     """
     self.policy.billing_schedule = "Monthly"
     pa = PolicyAccounting(self.policy.id)
     pa.change_billing_schedule("Quarterly")
     invoices = Invoice.query.filter_by(policy_id=self.policy.id)\
                             .filter(Invoice.deleted == False)\
                             .order_by(Invoice.bill_date).all()
     self.payments.append(
         pa.make_payment(contact_id=self.policy.named_insured,
                         date_cursor=invoices[1].bill_date,
                         amount=600))
     self.assertEquals(
         pa.return_account_balance(date_cursor=invoices[1].bill_date), 0)
Example #11
0
 def test_change_billing_schedule_q_m_np(self):
     """
      Test change billing schedule from quarterly to monthly
      when no payment made yet
     """
     self.policy.billing_schedule = "Quarterly"
     # No invoices currently exist
     self.assertFalse(self.policy.invoices)
     # Invoices should be made when the class is initiated
     pa = PolicyAccounting(self.policy.id)
     self.assertEquals(len(self.policy.invoices), 4)
     self.assertEquals(self.policy.invoices[1].amount_due,
                       self.policy.annual_premium / 4)
     # Change billing schedule
     pa.change_billing_schedule('Monthly')
     # invoices count should be 16 (4 old, 12 new)
     self.assertEquals(len(self.policy.invoices), 16)
Example #12
0
    def test_change_billing_schedule_quarterly_to_monthly(self):
        print "Testing change of billing schedule from quarterly to monthly...\n"
        self.policy.annual_premium = 1600
        self.policy.billing_schedule = 'Quarterly'

        pa = PolicyAccounting(self.policy.id)

        self.assertTrue(self.policy.invoices
                        )  # Check for invoices after PolicyAccounting creation

        first_invoice_paid = Invoice.query.filter_by(
            policy_id=self.policy.id).first()
        first_invoice_paid.amount_due = 0

        pa.change_billing_schedule("Monthly")
        db.session.rollback(
        )  # Rollback any changes made from the method to the database
Example #13
0
    def test_update_billing_schedule_annual_to_twopay(self):
        self.policy.billing_schedule = "Annual"
        #No invoices currently exist
        self.assertFalse(self.policy.invoices)
        #Invoices should be made when the class is initiated
        pa = PolicyAccounting(self.policy.id)
        #There is 1 invoice in total before updating
        self.assertEqual(len(self.policy.invoices), 1)

        #Call update billing schedule with Annual option
        pa.change_billing_schedule("Two-Pay")

        #There are 3 invoices in total after updating
        self.assertEqual(len(self.policy.invoices), 3)
        #1 is marked as deleted new invoices are not
        self.assertEqual(self.policy.invoices[0].deleted, True)
        self.assertEqual(self.policy.invoices[1].deleted, False)
        self.assertEqual(self.policy.invoices[2].deleted, False)
Example #14
0
    def test_update_billing_schedule_quartely_to_annual(self):
        self.policy.billing_schedule = "Quarterly"
        #No invoices currently exist
        self.assertFalse(self.policy.invoices)
        #Invoices should be made when the class is initiated
        pa = PolicyAccounting(self.policy.id)
        #There are 4 invoices in total before updating
        self.assertEqual(len(self.policy.invoices), 4)

        #Call update billing schedule with Annual option
        pa.change_billing_schedule("Annual")

        #There are 5 invoices in total after updating
        self.assertEqual(len(self.policy.invoices), 5)
        #4 are marked as deleted new invoice is not
        self.assertEqual(self.policy.invoices[0].deleted, True)
        self.assertEqual(self.policy.invoices[1].deleted, True)
        self.assertEqual(self.policy.invoices[2].deleted, True)
        self.assertEqual(self.policy.invoices[3].deleted, True)
        self.assertEqual(self.policy.invoices[4].deleted, False)
Example #15
0
 def test_change_billing_schedule_q_m_p(self):
     """
      Test change billing schedule from quarterly to monthly
      when already paid first invoices
     """
     self.policy.billing_schedule = "Quarterly"
     # No invoices currently exist
     self.assertFalse(self.policy.invoices)
     # Invoices should be made when the class is initiated
     pa = PolicyAccounting(self.policy.id)
     self.assertEquals(len(self.policy.invoices), 4)
     self.assertEquals(self.policy.invoices[1].amount_due,
                       self.policy.annual_premium / 4)
     # Make payment
     self.payments.append(
         pa.make_payment(self.policy.agent, date(2015, 1, 1), 300))
     # Change billing schedulte to Monthly
     pa.change_billing_schedule('Monthly')
     # Assert that total 13 invoices exist (4 old, 9 new)
     self.assertEquals(len(self.policy.invoices), 13)
Example #16
0
    def test_change_billing_schedule(self):
        self.policy.billing_schedule = "Two-Pay"
        self.assertFalse(self.policy.invoices)
        pa = PolicyAccounting(self.policy.id)

        self.assertEquals(len(self.policy.invoices), 2)

        # Change the billing cycle to monthly
        pa.change_billing_schedule("Monthly")

        # Now we should have 2 + 12 = 14 invoices
        self.assertEquals(len(self.policy.invoices), 14)

        # 2 invoices should be deleted and should have
        # amount_due = 1200/2 = 600
        deleted_invoices = [i for i in pa.policy.invoices if i.deleted]
        for invoice in deleted_invoices:
            self.assertEquals(invoice.amount_due, 600)

        # 12 invoices should not be deleted and should have
        # amount_due = 1200/12 = 100
        new_invoices = [i for i in pa.policy.invoices if not i.deleted]
        for invoice in new_invoices:
            self.assertEquals(invoice.amount_due, 100)
Example #17
0
class TestChangeBillingSchedule(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()

    @classmethod
    def tearDownClass(cls):
        db.session.delete(cls.test_insured)
        db.session.delete(cls.test_agent)
        db.session.commit()

    def setUp(self):
        self.policy = Policy("Test Policy", date(2015, 1, 1), 1200)
        self.policy.named_insured = self.test_insured.id
        self.policy.agent = self.test_agent.id
        self.policy.billing_schedule = "Quarterly"

        db.session.add(self.policy)
        db.session.commit()

        self.pa = PolicyAccounting(self.policy.id)
        invoice = self.policy.invoices[0]
        self.payment = self.pa.make_payment(
            contact_id=self.policy.named_insured,
            date_cursor=invoice.bill_date,
            amount=invoice.amount_due,
        )

    def tearDown(self):
        for invoice in self.policy.invoices:
            db.session.delete(invoice)
        db.session.delete(self.payment)
        db.session.delete(self.policy)
        db.session.commit()

    def test_valid_billing_schedule(self):
        self.assertEquals(self.pa.return_account_balance(), 900)
        self.assertEquals(len(self.policy.invoices), 4)
        old_invoices = self.policy.invoices
        self.pa.change_billing_schedule("Monthly")
        self.assertEquals(self.pa.return_account_balance(), 900)
        self.assertEquals(len(self.policy.invoices), 16)
        self.assertEquals(self.policy.billing_schedule, "Monthly")
        for invoice in self.policy.invoices:
            if invoice not in old_invoices:
                self.assertEquals(invoice.amount_due, 100)
                self.assertEquals(invoice.policy_id, self.policy.id)
                self.assertEquals(invoice.deleted, False)
        for invoice in old_invoices:
            self.assertEquals(invoice.deleted, True)

    def test_invalid_billing_schedule(self):
        self.assertEquals(self.pa.return_account_balance(), 900)
        self.assertEquals(len(self.policy.invoices), 4)
        old_invoices = self.policy.invoices
        self.pa.change_billing_schedule("Invalid")
        self.assertEquals(self.pa.return_account_balance(), 900)
        self._old_data_remains_unchanged(old_invoices)

    def test_empty_billing_schedule(self):
        self.assertEquals(self.pa.return_account_balance(), 900)
        old_invoices = self.policy.invoices
        self.assertEquals(len(self.policy.invoices), 4)
        self.pa.change_billing_schedule()
        self.assertEquals(self.pa.return_account_balance(), 900)
        self._old_data_remains_unchanged(old_invoices)

    def test_same_billing_schedule(self):
        self.assertEquals(self.pa.return_account_balance(), 900)
        self.assertEquals(len(self.policy.invoices), 4)
        old_invoices = self.policy.invoices
        self.pa.change_billing_schedule("Quarterly")
        self.assertEquals(self.pa.return_account_balance(), 900)
        self._old_data_remains_unchanged(old_invoices)

    def _old_data_remains_unchanged(self, old_invoices):
        self.assertEquals(len(self.policy.invoices), 4)
        self.assertEquals(self.policy.billing_schedule, "Quarterly")
        self.assertEquals(old_invoices, self.policy.invoices)