Ejemplo n.º 1
0
    def test_can_send_reminder(self):
        handler = MockLoggingHandler()
        makebills_logger.addHandler(handler)
        now = datetime.now()
        can_send = can_send_reminder(now)
        self.assertFalse(can_send, "Should fail if no payments exist")
        criticals = len(handler.messages['critical'])
        self.assertEqual(criticals, 1, "One log message")
        makebills_logger.removeHandler(handler)

        handler = MockLoggingHandler()
        makebills_logger.addHandler(handler)
        month_ago = datetime.now() - timedelta(days=30)
        p = Payment(billingcycle=self.cycle,
                    amount=5,
                    payment_day=month_ago,
                    transaction_id="test_can_send_reminder_1")
        p.save()
        two_weeks_ago = datetime.now() - timedelta(days=14)
        can_send = can_send_reminder(two_weeks_ago)
        self.assertFalse(can_send, "Should fail if payment is old")
        criticals = len(handler.messages['critical'])
        self.assertEqual(criticals, 0,
                         "No critical log messages, got %d" % criticals)
        makebills_logger.removeHandler(handler)

        p = Payment(billingcycle=self.cycle,
                    amount=5,
                    payment_day=now,
                    transaction_id="test_can_send_reminder_2")
        p.save()
        can_send = can_send_reminder(month_ago)
        self.assertTrue(can_send, "Should be true with recent payment")
Ejemplo n.º 2
0
    def test_can_send_reminder(self):
        handler = MockLoggingHandler()
        makebills_logger.addHandler(handler)
        now = datetime.now()
        can_send = can_send_reminder(now)
        self.assertFalse(can_send, "Should fail if no payments exist")
        criticals = len(handler.messages['critical'])
        self.assertEqual(criticals, 1, "One log message")
        makebills_logger.removeHandler(handler)

        handler = MockLoggingHandler()
        makebills_logger.addHandler(handler)
        month_ago = datetime.now() - timedelta(days=30)
        p = Payment(billingcycle=self.cycle, amount=5, payment_day=month_ago,
            transaction_id="test_can_send_reminder_1")
        p.save()
        two_weeks_ago = datetime.now() - timedelta(days=14)
        can_send = can_send_reminder(two_weeks_ago)
        self.assertFalse(can_send, "Should fail if payment is old")
        criticals = len(handler.messages['critical'])
        self.assertEqual(criticals, 0, "No critical log messages, got %d" % criticals)
        makebills_logger.removeHandler(handler)

        p = Payment(billingcycle=self.cycle, amount=5, payment_day=now,
            transaction_id="test_can_send_reminder_2")
        p.save()
        can_send = can_send_reminder(month_ago)
        self.assertTrue(can_send, "Should be true with recent payment")
Ejemplo n.º 3
0
    def test_membership_no_approved_time(self):
        "makebills: approved_time with no entries"
        membership = create_dummy_member('N')
        membership.status = 'A'
        membership.save()

        handler = MockLoggingHandler()
        makebills_logger.addHandler(handler)
        self.assertRaises(MembershipNotApproved, create_billingcycle, membership)

        criticals = handler.messages["critical"]
        self.assertTrue(len(criticals) > 0)

        logged = False
        for critical in criticals:
            if "is missing the approved timestamp. Cannot send bill" in critical:
                logged = True
                break
        self.assertTrue(logged)
        membership.delete()
        makebills_logger.removeHandler(handler)
Ejemplo n.º 4
0
    def test_membership_no_approved_time(self):
        "makebills: approved_time with no entries"
        membership = create_dummy_member('N')
        membership.status = 'A'
        membership.save()

        handler = MockLoggingHandler()
        makebills_logger.addHandler(handler)
        self.assertRaises(MembershipNotApproved, create_billingcycle,
                          membership)

        criticals = handler.messages["critical"]
        self.assertTrue(len(criticals) > 0)

        logged = False
        for critical in criticals:
            if "is missing the approved timestamp. Cannot send bill" in critical:
                logged = True
                break
        self.assertTrue(logged)
        membership.delete()
        makebills_logger.removeHandler(handler)
Ejemplo n.º 5
0
    def test_no_cycle_created(self):
        "makebills: no cycles after an expired membership, should log a warning"
        m = self.membership
        makebills()

        c = m.billingcycle_set.all()[0]
        c.end = datetime.now() - timedelta(hours=1)
        c.save()

        handler = MockLoggingHandler()
        makebills_logger.addHandler(handler)
        makebills()
        makebills_logger.removeHandler(handler)

        warnings = handler.messages["warning"]
        self.assertTrue(len(warnings) > 0)

        logged = False
        for warning in warnings:
            if "no new billing cycle created for" in warning:
                logged = True
                break

        self.assertTrue(logged)
Ejemplo n.º 6
0
    def test_no_cycle_created(self):
        "makebills: no cycles after an expired membership, should log a warning"
        m = self.membership
        makebills()

        c = m.billingcycle_set.all()[0]
        c.end = datetime.now() - timedelta(hours=1)
        c.save()

        handler = MockLoggingHandler()
        makebills_logger.addHandler(handler)
        makebills()
        makebills_logger.removeHandler(handler)

        warnings = handler.messages["warning"]
        self.assertTrue(len(warnings) > 0)

        logged = False
        for warning in warnings:
            if "no new billing cycle created for" in warning:
                logged = True
                break

        self.assertTrue(logged)