Example #1
0
    def test_to_field_value__if_type_set__should_return_value_of_this_type(
            self, datatype, value, expect):
        obj = Field('my_name', datatype)

        res = obj.to_field_value(value)

        assert res == expect and type(res) == type(expect)
Example #2
0
    def test_to_field_value__on_all_defaults__should_return_the_same_string(
            self):
        obj = Field('my_name')

        res = obj.to_field_value('value1')

        assert res == 'value1'
Example #3
0
    def test_to_field_value__if_get_cb_returns_value_not_of_datatype__should_also_cast_to_datatype(
            self, datatype, value, get_cb, expect):
        set_cb = Mock()
        validation_cb = Mock()
        obj = Field('my_name', datatype, get_cb, set_cb, validation_cb)

        res = obj.to_field_value(value)

        assert res == expect and type(res) == type(expect)
        set_cb.assert_not_called()
        validation_cb.assert_not_called()
Example #4
0
    def test_to_field_value__if_get_cb_returns_none__should_return_none(
            self, datatype, value):
        set_cb = Mock()
        validation_cb = Mock()
        obj = Field('my_name', datatype, lambda _: None, set_cb, validation_cb)

        res = obj.to_field_value(value)

        assert res is None
        set_cb.assert_not_called()
        validation_cb.assert_not_called()