def test_validity_duration_field_to_representation(self): """Test ValidityDurationField.to_representation()""" ga_factory = FakeGreenAssessmentFactory(organization=self.org) green_assessment = ga_factory.get_green_assessment( validity_duration=365) field = ValidityDurationField() result = field.to_representation(green_assessment.validity_duration) self.assertEqual(result, 365)
def test_validity_duration_field_to_internal_value(self): """Test ValidityDurationField.to_internal_value()""" field = ValidityDurationField() result = field.to_internal_value(365) expected = datetime.timedelta(365) self.assertEqual(result, expected) result = field.to_internal_value('365') self.assertEqual(result, expected) result = field.to_internal_value(None) expected = None self.assertEqual(result, expected) self.assertRaises(ValidationError, field.to_internal_value, 1.54) self.assertRaises(ValidationError, field.to_internal_value, 'ten') self.assertRaises(ValidationError, field.to_internal_value, 0) self.assertRaises(ValidationError, field.to_internal_value, -10)