示例#1
0
 def test_to_internal_value(self):
     instance = fields.HStoreField(child=fields.CharField())
     self.assertEqual(instance.to_internal_value({
         'a': 1,
         'b': '2'
     }), {
         'a': '1',
         'b': '2'
     })
示例#2
0
 def test_to_representation(self):
     instance = fields.HStoreField(child=fields.CharField())
     self.assertEqual(instance.to_representation({
         'a': 1,
         'b': '2'
     }), {
         'a': '1',
         'b': '2'
     })
示例#3
0
 def test_to_representation_without_child_instance(self):
     instance = fields.HStoreField()
     self.assertEqual(
         instance.to_representation({
             'a': 1,
             'b': [1, 2],
             'c': 'c'
         }), {
             'a': '1',
             'b': '[1, 2]',
             'c': 'c'
         })
示例#4
0
 def test_to_iternal_value_without_child_instance(self):
     instance = fields.HStoreField()
     self.assertEqual(
         instance.to_internal_value({
             'a': 1,
             'b': [1, 2],
             'c': 'c'
         }), {
             'a': '1',
             'b': '[1, 2]',
             'c': 'c'
         })
示例#5
0
    def test_to_iternal_value_without_child_instance_raises_an_error(self):
        instance = fields.HStoreField()

        with self.assertRaises(ValidationError):
            instance.to_internal_value('value')
示例#6
0
    def test_to_internal_value_raises_validation_error_for_a_wrong_value(self):
        instance = fields.HStoreField(child=fields.CharField())

        with self.assertRaises(ValidationError):
            instance.to_internal_value({'key': None})
示例#7
0
 def test_get_value_returns_empty_value(self):
     instance = fields.HStoreField(child=fields.CharField())
     instance.bind('test', None)
     self.assertEqual(instance.get_value({'key': 'value'}), empty)
示例#8
0
 def test_get_value(self):
     instance = fields.HStoreField()
     instance.bind('test', None)
     self.assertEqual(instance.get_value({'test': 'value'}), 'value')
示例#9
0
 def test_init_raises_assertion_error_for_child_without_source(self):
     with self.assertRaises(AssertionError):
         fields.HStoreField(child=fields.CharField(source='value'))
示例#10
0
 def test_init_raises_assertion_error_for_defined_child_as_a_class(self):
     with self.assertRaises(AssertionError):
         fields.HStoreField(child=fields.CharField)