예제 #1
0
    def test_validate_enforces_decimals(self):
        field = DecimalField()

        expect(field.validate(1.0)).to_be_true()
        expect(field.validate("1.5")).to_be_true()
        expect(field.validate("qwe")).to_be_false()
        expect(field.validate(None)).to_be_true()
예제 #2
0
    def test_to_son_with_different_rounding(self):
        field = DecimalField(precision=4, rounding=ROUND_DOWN)

        expect(field.to_son(10.023493924)).to_equal(u'10.0234')
        expect(field.to_son("10.5682999")).to_equal(u'10.5682')

        field = DecimalField(precision=4, rounding=ROUND_UP)

        expect(field.to_son(10.023493924)).to_equal(u'10.0235')
        expect(field.to_son("10.5682999")).to_equal(u'10.5683')
예제 #3
0
    def test_to_son_with_different_rounding(self):
        field = DecimalField(precision=4, rounding=ROUND_DOWN)

        expect(field.to_son(10.023493924)).to_equal(u'10.0234')
        expect(field.to_son("10.5682999")).to_equal(u'10.5682')

        field = DecimalField(precision=4, rounding=ROUND_UP)

        expect(field.to_son(10.023493924)).to_equal(u'10.0235')
        expect(field.to_son("10.5682999")).to_equal(u'10.5683')
예제 #4
0
    def test_to_son_with_different_precision(self):
        field = DecimalField(precision=4)

        expect(field.to_son(10.023423924)).to_equal(u'10.0234')
        expect(field.to_son("10.56823239")).to_equal(u'10.5682')
예제 #5
0
    def test_validate_enforces_max_value(self):
        field = DecimalField(max_value=Decimal(5.4))

        expect(field.validate(5.3)).to_be_true()
        expect(field.validate(5.5)).to_be_false()
        expect(field.validate("5.2")).to_be_true()
예제 #6
0
    def test_from_son(self):
        field = DecimalField()

        expect(field.from_son(u"10.0230")).to_equal(Decimal("10.02"))
        expect(field.from_son(u"10.56948")).to_equal(Decimal("10.57"))
        expect(field.from_son(None)).to_be_null()
예제 #7
0
    def test_to_son(self):
        field = DecimalField()

        expect(field.to_son(10.0230)).to_equal(u'10.02')
        expect(field.to_son("10.56823")).to_equal(u'10.57')
        expect(field.to_son(None)).to_be_null()
예제 #8
0
 def test_create_decimal_field(self):
     field = DecimalField(db_field="test", min_value=10.5, max_value=200.6)
     expect(field.db_field).to_equal("test")
     expect(field.min_value).to_equal(Decimal(10.5))
     expect(field.max_value).to_equal(Decimal(200.6))
예제 #9
0
    def test_to_son_with_different_precision(self):
        field = DecimalField(precision=4)

        expect(field.to_son(10.023423924)).to_equal(u'10.0234')
        expect(field.to_son("10.56823239")).to_equal(u'10.5682')
예제 #10
0
    def test_validate_enforces_max_value(self):
        field = DecimalField(max_value=Decimal(5.4))

        expect(field.validate(5.3)).to_be_true()
        expect(field.validate(5.5)).to_be_false()
        expect(field.validate("5.2")).to_be_true()
예제 #11
0
    def test_validate_enforces_decimals(self):
        field = DecimalField()

        expect(field.validate(1.0)).to_be_true()
        expect(field.validate("1.5")).to_be_true()
        expect(field.validate("qwe")).to_be_false()
예제 #12
0
    def test_from_son(self):
        field = DecimalField()

        expect(field.from_son(u"10.0230")).to_equal(Decimal("10.02"))
        expect(field.from_son(u"10.56948")).to_equal(Decimal("10.57"))
예제 #13
0
    def test_to_son(self):
        field = DecimalField()

        expect(field.to_son(10.0230)).to_equal(u'10.02')
        expect(field.to_son("10.56823")).to_equal(u'10.57')