Example #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'}
     )
Example #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'}
     )
Example #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')
Example #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})
Example #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'}
     )
Example #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'}
     )
Example #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)
Example #8
0
 def test_get_value(self):
     instance = fields.HStoreField()
     instance.bind('test', None)
     self.assertEqual(instance.get_value({'test': 'value'}), 'value')
Example #9
0
 def test_init_raises_assertion_error_for_child_without_source(self):
     with self.assertRaises(AssertionError):
         fields.HStoreField(child=fields.CharField(source='value'))
Example #10
0
 def test_init_raises_assertion_error_for_defined_child_as_a_class(self):
     with self.assertRaises(AssertionError):
         fields.HStoreField(child=fields.CharField)