Ejemplo n.º 1
0
    def test_on_enter(self):
        models.Event.objects.all().delete()
        models.UserReviewStatus.objects.filter(
            review=self.review
        ).delete()
        models.Reminder.objects.all().update(active=True)
        self.review.state = 'notastate'
        self.review.save(update_fields=['state'])
        mail.outbox = []

        self.state.on_enter(self.review, demo_machine.Open())
        self.review.refresh_from_db()
        self.assertEqual(self.review.state, constants.ABORTED)
        event = models.Event.objects.get()
        self.assertEqual(event.event_type.code, models.EventType.DEMO_ABORTED)
        self.assertEqual(
            event.user,
            self.review.creator_set.active().get().user
        )

        reminders = models.Reminder.objects.filter(
            review=self.review, active=False
        )
        # 3 reviewers, 1 creator
        self.assertEqual(reminders.count(), 4)

        # 2 followers, 3 reviewers
        self.assertEqual(len(mail.outbox), 5)
        self.hook_patch_run.assert_called_once_with(
            constants.ABORTED
        )
Ejemplo n.º 2
0
    def test_on_enter(self):
        self.review.state = 'notastate'
        self.review.save(update_fields=['state'])

        self.state.on_enter(self.review, demo_machine.Open())
        self.review.refresh_from_db()
        self.assertEqual(self.review.state, constants.DRAFT)
        self.hook_patch_run.assert_not_called()
Ejemplo n.º 3
0
 def test_change_state_same_state(self):
     self.assertFalse(self.machine.change_state(constants.OPEN))
     self.review.refresh_from_db()
     self.assertEqual(self.machine.previous_state, None)
     self.assertEqual(self.machine.state, demo_machine.Open())
     self.assertEqual(self.review.state, constants.OPEN)
Ejemplo n.º 4
0
 def test_change_state_new_state(self):
     self.assertTrue(self.machine.change_state(constants.CLOSED))
     self.review.refresh_from_db()
     self.assertEqual(self.machine.previous_state, demo_machine.Open())
     self.assertEqual(self.machine.state, demo_machine.Closed())
     self.assertEqual(self.review.state, constants.CLOSED)
Ejemplo n.º 5
0
 def test_init(self):
     self.assertEqual(self.machine.review, self.review)
     self.assertEqual(self.machine.state, demo_machine.Open())
     self.assertEqual(self.machine.previous_state, None)
Ejemplo n.º 6
0
 def setUp(self):
     super(TestOpenState, self).setUp()
     self.state = demo_machine.Open()