Exemplo n.º 1
0
    def test_accounting_single_record_removal(self):
        """
        1. Buy a class
        2. Schedule it
        3. Move to the future
        4. Account it
        5. Dangerously_cancel() it
        6. Check if account record has gone
        """

        entry = self._create_entry()
        c = self._buy_a_lesson()
        self._schedule(c, entry)

        entry = c.timeline  # get a new timeline entry

        with freeze_time('2032-09-15 15:00'):  # now entry is in past
            bill_timeline_entries()
            ev = AccEvent.objects.by_originator(entry).first()
            self.assertIsNotNone(ev)

            entry.delete(src='dangerous-cancellation')
            with self.assertRaises(ObjectDoesNotExist):
                ev.refresh_from_db(
                )  # the accounting event should be dropped while unscheduling the last class

            c.refresh_from_db()
            self.assertFalse(c.is_scheduled)
            self.assertFalse(c.is_fully_used)
Exemplo n.º 2
0
    def test_bypass_already_billed_originators(self):
        bill_timeline_entries()

        self.entry.is_finished = False
        self.entry.save()
        bill_timeline_entries()
        self.assertEqual(AccEvent.objects.count(), 1)

        ev = AccEvent.objects.all()[0]
        self.assertEqual(ev.event_type, 'class')
Exemplo n.º 3
0
    def test_class_marked_as_used(self):
        c = self._buy_a_lesson()
        entry = self._create_entry()

        self._schedule(c, entry)

        c.refresh_from_db()
        self.assertTrue(c.is_scheduled)

        bill_timeline_entries()  # run the periodic task by hand

        with self.assertRaises(ObjectDoesNotExist):
            entry.refresh_from_db()

        c.refresh_from_db()
        self.assertTrue(c.is_fully_used)

        self.assertEqual(AccEvent.objects.count(), 1)
Exemplo n.º 4
0
    def test_warn_logging(self):
        """
        Try to double-bill the same timeline entry
        """
        with patch('timeline.models.Entry._Entry__self_delete_if_needed') as self_delete:  # disable self-deletion (the entry is in past here!)
            self_delete.return_value = False

            bill_timeline_entries()

            self.entry._Entry__update_slots = MagicMock()  # disable timeslot updating — the entry needs to have slots for beeing billed
            self.entry.is_finished = False
            self.entry.save()

            with patch('accounting.tasks.logger') as logger:
                logger.warning = MagicMock()
                bill_timeline_entries()

                self.assertEqual(logger.warning.call_count, 1)
Exemplo n.º 5
0
    def test_multiple_classes(self):
        """
        The same as above but with two classes to check how account record deletion works
        when entry autodeletion is not invoked.
        """
        self.lesson = mixer.blend(lessons.MasterClass, host=self.host, slots=5)

        entry = self._create_entry()

        entry.slots = 5
        entry.save()

        c = self._buy_a_lesson()
        self._schedule(c, entry)

        self.customer = create_customer()  # create another customer
        c1 = self._buy_a_lesson()
        self._schedule(c1, entry)
        entry.refresh_from_db(
        )  # we have the same entry here because the lesson is hosted

        with freeze_time('2032-09-15 15:00'):  # now entry is in past
            bill_timeline_entries()
            ev = AccEvent.objects.by_originator(entry).first()
            self.assertIsNotNone(ev)

            entry.delete(src='dangerous-cancellation')

            with self.assertRaises(ObjectDoesNotExist):
                ev.refresh_from_db(
                )  # the accounting event should be dropped while unscheduling the last class

            c.refresh_from_db()
            c1.refresh_from_db()

            self.assertFalse(c.is_scheduled)
            self.assertFalse(c.is_fully_used)
            self.assertFalse(c1.is_scheduled)
            self.assertFalse(c1.is_fully_used)
Exemplo n.º 6
0
 def test_event_creation(self):
     self.assertEqual(AccEvent.objects.count(), 0)
     bill_timeline_entries()
     self.assertEqual(AccEvent.objects.count(), 1)
Exemplo n.º 7
0
    def test_timeline_entry_marking(self):
        bill_timeline_entries()
        self.entry.refresh_from_db()

        self.assertTrue(self.entry.is_finished)