def test_run_validation_raises_validation_error_for_gt_max_value(self): instance = fields.DecimalField(max_digits=5, decimal_places=2, max_value=90) with self.assertRaises(ValidationError): instance.run_validation(99)
def test_quantize(self): instance = fields.DecimalField(max_digits=10, decimal_places=5) value = Decimal('12345.0') self.assertEqual(instance.quantize(value), value)
def test_to_representation_without_coerce_to_string(self): instance = fields.DecimalField(max_digits=10, decimal_places=5, coerce_to_string=False) value = Decimal('12345.0') self.assertEqual(instance.to_representation(value), value)
def test_to_representation_with_decimal_as_a_string(self): instance = fields.DecimalField(max_digits=10, decimal_places=5) self.assertEqual(instance.to_representation('12345.0'), '12345.00000')
def test_to_internal_value_raises_validation_error_for_infinity(self): instance = fields.DecimalField(max_digits=10, decimal_places=5) with self.assertRaises(ValidationError): instance.to_internal_value(float('inf')) # positive infinite instance.to_internal_value(-float('inf')) # negative infinite
def test_to_internal_value_raises_validation_error_for_NaN(self): instance = fields.DecimalField(max_digits=10, decimal_places=5) with self.assertRaises(ValidationError): instance.to_internal_value('NaN')
def test_to_internal_value(self): instance = fields.DecimalField(max_digits=10, decimal_places=5) self.assertEqual(instance.to_internal_value(12345.0), Decimal('12345.0'))
def test_validate_precision_raise_validation_exc_max_whole_digits(self): instance = fields.DecimalField(max_digits=9, decimal_places=7) with self.assertRaises(ValidationError): instance.validate_precision(Decimal('1234500.0'))
def test_validate_precision_with_fraction(self): instance = fields.DecimalField(max_digits=7, decimal_places=5) value = Decimal('0.01234') self.assertEqual(instance.validate_precision(value), value)
def test_validate_precision_with_digittuple(self): instance = fields.DecimalField(max_digits=7, decimal_places=2) value = Decimal('12345.0') self.assertEqual(instance.validate_precision(value), value)
def test_validate_precision_with_exponent(self): instance = fields.DecimalField(max_digits=5, decimal_places=0) value = Decimal('12345') self.assertEqual(instance.validate_precision(value), value)
def test_run_validation(self): instance = fields.DecimalField(max_digits=5, decimal_places=2) self.assertEqual(instance.run_validation(99), 99)
def test_init_with_not_defined_max_whole_digits(self): instance = fields.DecimalField(max_digits=None, decimal_places=None) self.assertIsNone(instance.max_digits) self.assertIsNone(instance.decimal_places) self.assertIsNone(instance.max_whole_digits)
def test_init_default(self): instance = fields.DecimalField(max_digits=5, decimal_places=2) self.assertEqual(instance.max_digits, 5) self.assertEqual(instance.decimal_places, 2) self.assertEqual(instance.max_whole_digits, 3)