Example #1
0
    def test_charge_cannot_be_closed_without_end_time(self):
        start_datetime = timezone.make_aware(
            datetime(2019, 1, 1, hour=8, minute=0, second=0))

        charge = Charge(project=self.project,
                        start_time=start_datetime,
                        closed=True)

        # Should raise a keyed validation error
        with self.assertRaises(ValidationError) as context_manager:
            charge.full_clean()

        self.assertValidationMessagePresent(
            context_manager.exception.error_dict,
            field='closed',
            error_code='cannot_close_without_end_time')

        # Should raise a generic validation error if the end time field
        # is excluded
        with self.assertRaises(ValidationError) as context_manager:
            charge.full_clean(exclude=('closed', ))

        self.assertValidationMessagePresent(
            context_manager.exception.error_dict,
            field='__all__',
            error_code='cannot_close_without_end_time')
Example #2
0
    def test_charge_project_must_be_active_project(self):
        start_datetime = timezone.make_aware(
            datetime(2019, 1, 1, hour=8, minute=0, second=0))

        inactive_project = Project(name='Test 2',
                                   active=False).validate_and_save()

        charge = Charge(project=inactive_project,
                        start_time=start_datetime,
                        end_time=start_datetime + timedelta(hours=1))

        with self.assertRaises(ValidationError) as context_manager:
            charge.full_clean()

        self.assertValidationMessagePresent(
            context_manager.exception.error_dict,
            field='project',
            error_code='project_must_be_active')