示例#1
0
 def test_set_value_does_not_set_user_entered_flag(self):
     f = self.create_field()
     bf = BoundField(f, StubModel())
     bf.set_value(Decimal("100.1"), user_entered=False)
     self.assertEquals(Decimal("100.1"), bf.value)
     self.assertEquals(True, bf.has_value)
     self.assertEquals(False, bf.has_user_entered_value)
示例#2
0
 def test_set_value_does_not_set_user_entered_flag(self):
     f = self.create_field()
     bf = BoundField(f , StubModel())
     bf.set_value(Decimal("100.1"),user_entered=False)
     self.assertEquals(Decimal("100.1"), bf.value)
     self.assertEquals(True, bf.has_value)
     self.assertEquals(False, bf.has_user_entered_value)
示例#3
0
 def test_set_value_converts_datatype_and_set_value_flag(self):
     f = self.create_field()
     bf = BoundField(f , StubModel())
     bf.set_value("100.1")
     self.assertEquals(Decimal("100.1"), bf.value)
     self.assertEquals(True, bf.has_value)
     self.assertEquals(True, bf.has_user_entered_value)
示例#4
0
 def test_set_value_converts_datatype_and_set_value_flag(self):
     f = self.create_field()
     bf = BoundField(f, StubModel())
     bf.set_value("100.1")
     self.assertEquals(Decimal("100.1"), bf.value)
     self.assertEquals(True, bf.has_value)
     self.assertEquals(True, bf.has_user_entered_value)
示例#5
0
 def test_set_value_unsets_value_on_none(self):
     f = self.create_field()
     bf = BoundField(f , StubModel())
     bf.set_value(Decimal("100.1"))
     bf.set_value(None)
     self.assertEquals( None, bf.value)
     self.assertEquals( False, bf.has_value)
     self.assertEquals( False, bf.has_user_entered_value)
示例#6
0
 def test_recalc(self):
     f = self.create_field()
     bf = BoundField(f , StubModel())
     self.assertEquals(True, bf.recalc() )
     self.assertEquals(Decimal("123"), bf.value)
     bf.set_value("101")
     self.assertEquals(False, bf.recalc() )
     self.assertEquals(Decimal("101"), bf.value)
示例#7
0
 def test_map_to_and_from_domain_when_no_mapper(self):
     f = Field(name="f1", datatype=Decimal)
     bf = BoundField(f, StubModel())
     bf.set_value("123")
     bf.map_to_domain()
     bf.set_value("456")
     bf.map_from_domain()
     self.assertEqual(Decimal("456"), bf.value)
    def test_map_object_value_to_when_none(self):

        so = StubObj()
        bf = BoundField(Field("field2", str), None)    
        bf.set_value(None)
        
        model = VanillaModel()
        model._map_object_value(so, bf, bf.TO, finder)
        self.assertEquals(so.field2, None)
    def test_map_object_value_basic_to(self):

        so = StubObj()
        bf = BoundField(Field("field1", str), None)
        bf.set_value('some value')

        model = VanillaModel()
        model._map_object_value(so, bf, bf.TO, finder)
        self.assertEquals(so.field1, 'Found some value')
    def test_map_object_value_basic_to(self):

        so = StubObj()
        bf = BoundField(Field("field1", str), None)    
        bf.set_value('some value')
        
        model = VanillaModel()
        model._map_object_value(so, bf, bf.TO, finder)
        self.assertEquals(so.field1, 'Found some value')
    def test_map_object_value_to_when_none(self):

        so = StubObj()
        bf = BoundField(Field("field2", str), None)
        bf.set_value(None)

        model = VanillaModel()
        model._map_object_value(so, bf, bf.TO, finder)
        self.assertEquals(so.field2, None)
示例#12
0
 def test_map_to_and_from_domain_when_no_mapper(self):
     f = Field(name="f1",  datatype=Decimal )
     bf = BoundField(f , StubModel())
     bf.set_value("123")
     bf.map_to_domain()
     bf.set_value("456")
     bf.map_from_domain()
     self.assertEqual(Decimal("456"), bf.value)
示例#13
0
 def test_set_value_produces_readable_errors_when_conversion_failed_date(
         self):
     bf = BoundField(Field(name="f1", datatype=datetime.date), StubModel())
     self.assertRaisesRegex(
         DataTypeConversionError,
         "Invalid value >2012-13-12< needs to be YYYY-MM-DD format",
         bf.set_value, "2012-13-12")
示例#14
0
 def test_bimd_method_checks_argument_count(self):
     f = self.create_field()
     m = StubModel()
     bf = BoundField(f, m)
     self.assertRaisesRegex(
         InvalidModelError,
         "Wrong number of arguments to calc_meth method.  Expected 3 got 1",
         bf._bind_method, 'calculation_method', m, 3)
示例#15
0
 def test_map_to_and_from_domain_using_model_proxy(self):
     f = self.create_field()
     m = StubModel()
     bf = BoundField(f, m)
     bf.set_value("123")
     bf.map_to_domain()
     self.assertEqual(Decimal("123"), m.domain_value)
     m.domain_value = Decimal('456')
     bf.map_from_domain()
     self.assertEqual(Decimal("456"), bf.value)
    def test_map_object_value_basic_from(self):

        so = StubObj()
        bf = BoundField(Field("field1", str), None)

        model = VanillaModel()
        actual = model._map_object_value(so, bf, bf.FROM, finder)
        expect = "a name"
        self.assertEquals(expect, actual)
    def test_map_object_value_from_when_none(self):

        so = StubObj()
        bf = BoundField(Field("field1", str), None)
        so.field1 = None

        model = VanillaModel()
        actual = model._map_object_value(so, bf, bf.FROM, finder)
        expect = None
        self.assertEquals(expect, actual)
示例#18
0
 def test_can_create(self):
     f = self.create_field()
     m = StubModel()
     bf = BoundField(f, m)
     self.assertEquals(m.calc_meth, bf.calculation_method)
     self.assertEquals(m.val_meth, bf.validation_method)
     self.assertEquals(m.mapper, bf.domain_mapping_method)
     self.assertEquals(f, bf.definition)
     self.assertEquals('f1', bf.name)
     self.assertEquals(None, bf.value)
     self.assertEquals(False, bf.has_value)
     self.assertEquals(False, bf.has_user_entered_value)
示例#19
0
 def test_map_to_and_from_domain_using_model_proxy(self):
     f = self.create_field()
     m = StubModel()
     bf = BoundField( f , m)
     bf.set_value("123")
     bf.map_to_domain()
     self.assertEqual(Decimal("123"), m.domain_value)
     m.domain_value = Decimal('456')
     bf.map_from_domain()
     self.assertEqual(Decimal("456"), bf.value)
示例#20
0
 def test_set_value_unsets_value_on_none(self):
     f = self.create_field()
     bf = BoundField(f, StubModel())
     bf.set_value(Decimal("100.1"))
     bf.set_value(None)
     self.assertEquals(None, bf.value)
     self.assertEquals(False, bf.has_value)
     self.assertEquals(False, bf.has_user_entered_value)
示例#21
0
    def test_map_to_and_from_domain_using_direct_syntax(self):
        class DomainObject:
            f1 = 'aaa'

        do = DomainObject()
        f = Field(name="f1", datatype=Decimal, domain_mapping="do.f1")
        m = StubModel()
        m.get_domain_object = lambda name: do
        bf = BoundField(f, m)
        bf.set_value("123")
        bf.map_to_domain()
        self.assertEqual(Decimal("123"), do.f1)
        do.f1 = Decimal("456")
        bf.map_from_domain()
        self.assertEqual(Decimal("456"), bf.value)
示例#22
0
 def test_recalc(self):
     f = self.create_field()
     bf = BoundField(f, StubModel())
     self.assertEquals(True, bf.recalc())
     self.assertEquals(Decimal("123"), bf.value)
     bf.set_value("101")
     self.assertEquals(False, bf.recalc())
     self.assertEquals(Decimal("101"), bf.value)
示例#23
0
 def test_map_to_and_from_domain_using_direct_syntax(self):
     
     class DomainObject:
         f1 = 'aaa'
         
     do = DomainObject()
     f = Field(name="f1",  datatype=Decimal, domain_mapping="do.f1" )
     m = StubModel()
     m.get_domain_object = lambda name: do
     bf = BoundField( f , m)
     bf.set_value("123")
     bf.map_to_domain()
     self.assertEqual(Decimal("123"), do.f1)
     do.f1 = Decimal("456")
     bf.map_from_domain()
     self.assertEqual(Decimal("456"), bf.value)
示例#24
0
 def bind_fields(self):
     for field_name in self.FIELD_DEPENDS:
         setattr(self, field_name,
                 BoundField(FieldFactory.get_field(field_name), self))
示例#25
0
 def test_set_date_fields_as_string(self):
     f = Field(name="f1",  datatype=datetime.date )
     bf = BoundField(f , StubModel())
     bf.set_value("2015-01-02")
     self.assertEquals(date(2015,1,2), bf.value)
示例#26
0
 def test_validate(self):
     f = self.create_field()
     bf = BoundField(f, StubModel())
     self.assertEquals('Validation Error', bf.validate())
示例#27
0
 def test_validate_when_val_meth_is_not_set(self):
     f = Field(name="f1", datatype=Decimal)
     bf = BoundField(f, StubModel())
     self.assertEquals(None, bf.validate())
示例#28
0
 def test_validate_when_val_meth_is_not_set(self):
     f = Field(name="f1",  datatype=Decimal )
     bf = BoundField(f , StubModel())
     self.assertEquals( None, bf.validate() )
示例#29
0
 def test_validate(self):
     f = self.create_field()
     bf = BoundField(f , StubModel())
     self.assertEquals( 'Validation Error', bf.validate() )
示例#30
0
 def test_recalc_when_calc_method_is_none(self):
     f = Field(name="f1",  datatype=Decimal )
     bf = BoundField(f , StubModel())
     self.assertEquals(False, bf.recalc() )
     self.assertEquals(None, bf.value)
示例#31
0
 def test_bind_domain_mapping_method_when_no_mapping(self):
     f = Field(name="f1", datatype=Decimal)
     bf = BoundField(f, StubModel())
     self.assertEquals(None, bf.domain_mapping_method)
示例#32
0
 def test_recalc_when_calc_method_is_none(self):
     f = Field(name="f1", datatype=Decimal)
     bf = BoundField(f, StubModel())
     self.assertEquals(False, bf.recalc())
     self.assertEquals(None, bf.value)
示例#33
0
 def test_set_date_fields_as_string(self):
     f = Field(name="f1", datatype=datetime.date)
     bf = BoundField(f, StubModel())
     bf.set_value("2015-01-02")
     self.assertEquals(date(2015, 1, 2), bf.value)
示例#34
0
 def test_set_value_produces_readable_errors_when_conversion_failed_decimal(
         self):
     bf = BoundField(Field(name="f1", datatype=Decimal), StubModel())
     self.assertRaisesRegex(DataTypeConversionError,
                            "Invalid value >abv< needs to be Numeric",
                            bf.set_value, "abv")