Example #1
0
 def test_output_fallback(self):
     field = DecimalField(required=True, decimal_places=1, output='no_valid_output')
     field.set_value(23.4)
     field.validate()
     self.assertEqual(field, 23.4)
     self.assertEqual(field.to_python(), decimal.Decimal('23.4'))
     self.assertEqual(field.to_native(), 23.4)
Example #2
0
 def test_string_output(self):
     field = DecimalField(required=True, decimal_places=2, output=DecimalField.OUTPUT_AS_STRING)
     field.set_value(23.42)
     field.validate()
     self.assertEqual(field, '23.42')
     self.assertEqual(field.to_python(), decimal.Decimal('23.42'))
     self.assertEqual(field.to_native(), '23.42')
Example #3
0
 def test_output_fallback(self):
     field = DecimalField(required=True,
                          decimal_places=1,
                          output='no_valid_output')
     field.set_value(23.4)
     field.validate()
     self.assertEqual(field, 23.4)
     self.assertEqual(field.to_python(), decimal.Decimal('23.4'))
     self.assertEqual(field.to_native(), 23.4)
Example #4
0
 def test_string_output(self):
     field = DecimalField(required=True,
                          decimal_places=2,
                          output=DecimalField.OUTPUT_AS_STRING)
     field.set_value(23.42)
     field.validate()
     self.assertEqual(field, '23.42')
     self.assertEqual(field.to_python(), decimal.Decimal('23.42'))
     self.assertEqual(field.to_native(), '23.42')
Example #5
0
    def test_default(self):
        field = DecimalField(required=True, default=23.23)
        field.validate()
        self.assertEqual(field.to_python(), decimal.Decimal('23.23'))
        self.assertEqual(field.to_native(), 23.23)

        field = DecimalField(required=True, default=decimal.Decimal('123.123'))
        field.validate()
        self.assertEqual(field.to_python(), decimal.Decimal('123.123'))
        self.assertEqual(field.to_native(), 123.123)
Example #6
0
    def test_default(self):
        field = DecimalField(required=True, default=23.23)
        field.validate()
        self.assertEqual(field.to_python(), decimal.Decimal('23.23'))
        self.assertEqual(field.to_native(), 23.23)

        field = DecimalField(required=True, default=decimal.Decimal('123.123'))
        field.validate()
        self.assertEqual(field.to_python(), decimal.Decimal('123.123'))
        self.assertEqual(field.to_native(), 123.123)
Example #7
0
    def test_decimal_places(self):
        field = DecimalField(required=True, decimal_places=1, max_value=24.5, min_value=22.1)
        field.set_value(23.4)
        field.validate()
        self.assertEqual(field, 23.4)
        self.assertEqual(field.to_python(), decimal.Decimal('23.4'))
        self.assertEqual(field.to_native(), 23.4)

        field = DecimalField(required=True, decimal_places=5)
        field.set_value(decimal.Decimal('9.4'))
        field.validate()
        self.assertEqual(field.to_python(), decimal.Decimal('9.40000'))
        self.assertEqual(field.to_native(), 9.40000)
Example #8
0
    def test_decimal_places(self):
        field = DecimalField(required=True,
                             decimal_places=1,
                             max_value=24.5,
                             min_value=22.1)
        field.set_value(23.4)
        field.validate()
        self.assertEqual(field, 23.4)
        self.assertEqual(field.to_python(), decimal.Decimal('23.4'))
        self.assertEqual(field.to_native(), 23.4)

        field = DecimalField(required=True, decimal_places=5)
        field.set_value(decimal.Decimal('9.4'))
        field.validate()
        self.assertEqual(field.to_python(), decimal.Decimal('9.40000'))
        self.assertEqual(field.to_native(), 9.40000)
Example #9
0
 def test_set_value_string(self):
     field = DecimalField(required=True, decimal_places=2)
     field.set_value('23.23')
     field.validate()
     self.assertEqual(field.to_python(), decimal.Decimal('23.23'))
     self.assertEqual(field.to_native(), 23.23)
Example #10
0
 def test_set_value_string(self):
     field = DecimalField(required=True, decimal_places=2)
     field.set_value('23.23')
     field.validate()
     self.assertEqual(field.to_python(), decimal.Decimal('23.23'))
     self.assertEqual(field.to_native(), 23.23)