def test_set_status_returns_false_when_not_set(self):
        '''
        Test that the set_status method returns false when it hasn't updated the status.
        '''
        test_ticket = Ticket(user=self.test_user,
                             title='Fail To Set Status',
                             content='Test content')
        test_ticket.save()

        test_ticket.set_status('doing')
        self.assertFalse(test_ticket.set_status('approved'))
    def test_set_status_sets_status_field_to_now(self):
        '''
        Test that the set_status method sets the apropriate field to the current time.
        '''
        test_ticket = Ticket(user=self.test_user,
                             title='Set Status Time',
                             content='Test content')
        test_ticket.save()

        before = timezone.now()
        test_ticket.set_status('doing')
        after = timezone.now()
        self.assertGreaterEqual(test_ticket.doing, before)
        self.assertLessEqual(test_ticket.doing, after)
    def test_set_status_sets_all_unset_previous_status_fields(self):
        '''
        Test that the set status method sets all previous unset status fields to the current time,
        but leaves set ones as they are.
        '''
        test_ticket = Ticket(user=self.test_user,
                             title='Fail To Set Status',
                             content='Test content')

        past_date = timezone.now() - timedelta(days=1)
        test_ticket.approved = past_date
        test_ticket.save()

        test_ticket.set_status('done')

        test_ticket = Ticket.objects.get(id=test_ticket.id)
        self.assertEqual(test_ticket.approved, past_date)
        self.assertIsNotNone(test_ticket.doing)
        self.assertIsNotNone(test_ticket.done)
    def test_set_status_changes_status(self):
        '''
        Test that the set_status method updates an Ticket's status.
        '''
        test_ticket = Ticket(user=self.test_user,
                             title='Set Status',
                             content='Test content')
        test_ticket.save()

        test_ticket = Ticket.objects.get(id=test_ticket.id)
        self.assertEqual('awaiting approval', test_ticket.status)

        test_ticket.set_status('approved')
        test_ticket = Ticket.objects.get(id=test_ticket.id)
        self.assertEqual('approved', test_ticket.status)

        test_ticket.set_status('doing')
        test_ticket = Ticket.objects.get(id=test_ticket.id)
        self.assertEqual('doing', test_ticket.status)

        test_ticket.set_status('done')
        test_ticket = Ticket.objects.get(id=test_ticket.id)
        self.assertEqual('done', test_ticket.status)