Exemplo n.º 1
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'}
     )
Exemplo n.º 2
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'}
     )
Exemplo n.º 3
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')
Exemplo n.º 4
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})
Exemplo n.º 5
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'}
     )
Exemplo n.º 6
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'}
     )
Exemplo n.º 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)
Exemplo n.º 8
0
 def test_get_value(self):
     instance = fields.HStoreField()
     instance.bind('test', None)
     self.assertEqual(instance.get_value({'test': 'value'}), 'value')
Exemplo n.º 9
0
 def test_init_raises_assertion_error_for_child_without_source(self):
     with self.assertRaises(AssertionError):
         fields.HStoreField(child=fields.CharField(source='value'))
Exemplo n.º 10
0
 def test_init_raises_assertion_error_for_defined_child_as_a_class(self):
     with self.assertRaises(AssertionError):
         fields.HStoreField(child=fields.CharField)