Exemple #1
0
 def test_to_representation_without_child_instance(self):
     instance = fields.DictField()
     self.assertEqual(
         instance.to_representation({'a': 1, 'b': [1, 2], 'c': 'c'}),
         {'a': 1, 'b': [1, 2], 'c': 'c'}
     )
Exemple #2
0
 def test_to_iternal_value_without_child_instance(self):
     instance = fields.DictField()
     self.assertEqual(
         instance.to_internal_value({'a': 1, 'b': [1, 2], 'c': 'c'}),
         {'a': 1, 'b': [1, 2], 'c': 'c'}
     )
Exemple #3
0
    def test_to_iternal_value_without_child_instance_raises_an_error(self):
        instance = fields.DictField()

        with self.assertRaises(ValidationError):
            instance.to_internal_value('value')
Exemple #4
0
    def test_to_internal_value_raises_validation_error_for_a_wrong_value(self):
        instance = fields.DictField(child=fields.CharField())

        with self.assertRaises(ValidationError):
            instance.to_internal_value({'key': None})
Exemple #5
0
 def test_to_representation(self):
     instance = fields.DictField(child=fields.CharField())
     self.assertEqual(
         instance.to_representation({'a': 1, 'b': '2'}),
         {'a': '1', 'b': '2'}
     )
Exemple #6
0
 def test_to_internal_value(self):
     instance = fields.DictField(child=fields.CharField())
     self.assertEqual(
         instance.to_internal_value({'a': 1, 'b': '2'}),
         {'a': '1', 'b': '2'}
     )
Exemple #7
0
 def test_get_value_returns_empty_value(self):
     instance = fields.DictField(child=fields.CharField())
     instance.bind('test', None)
     self.assertEqual(instance.get_value({'key': 'value'}), empty)
Exemple #8
0
 def test_get_value(self):
     instance = fields.DictField(child=fields.CharField())
     instance.bind('test', None)
     self.assertEqual(instance.get_value({'test': 'value'}), 'value')
Exemple #9
0
    def test_init_raises_assertion_error_for_child_without_source(self):

        with self.assertRaises(AssertionError):
            fields.DictField(child=fields.CharField(source='value'))
Exemple #10
0
    def test_init_raises_assertion_error_for_defined_child_as_a_class(self):

        with self.assertRaises(AssertionError):
            fields.DictField(child=fields.CharField)