Пример #1
0
    def test_to_internal_value_raises_validation_error_for_empty_list(self):
        instance = fields.ListField(
            child=fields.IntegerField(), allow_empty=False
        )

        with self.assertRaises(ValidationError):
            instance.to_internal_value([])
Пример #2
0
    def test_get_value_returns_empty_value(self):

        class FakeModelSerializer(object):
            partial = True
            parent = None

        instance = fields.ListField(child=fields.IntegerField())
        instance.bind('test', FakeModelSerializer())
        self.assertEqual(instance.get_value({'key': [1, 2, 3]}), empty)
Пример #3
0
 def test_to_representation_without_child_instance(self):
     instance = fields.ListField()
     self.assertEqual(
         instance.to_representation([1, '2', True, [4, 5, 6]]),
         [1, '2', True, [4, 5, 6]]
     )
Пример #4
0
    def test_to_iternal_value_without_child_instance_raises_an_error(self):
        instance = fields.ListField()

        with self.assertRaises(ValidationError):
            instance.to_internal_value('value')
Пример #5
0
 def test_to_iternal_value_without_child_instance(self):
     instance = fields.ListField()
     self.assertEqual(
         instance.to_internal_value([1, '2', True, [4, 5, 6]]),
         [1, '2', True, [4, 5, 6]]
     )
Пример #6
0
 def test_to_representation_for_string_list(self):
     instance = fields.ListField(child=fields.IntegerField())
     self.assertEqual(
         instance.to_representation(['1', '2', '3']),
         [1, 2, 3]
     )
Пример #7
0
 def test_to_representation(self):
     instance = fields.ListField(child=fields.IntegerField())
     self.assertEqual(instance.to_representation([1, 2, 3]), [1, 2, 3])
Пример #8
0
    def test_to_internal_value_raises_validation_error_for_wrong_value(self):
        instance = fields.ListField(child=fields.IntegerField())

        with self.assertRaises(ValidationError):
            instance.to_internal_value([1, 2, 'error'])
Пример #9
0
 def test_to_internal_value_for_list_with_integer_as_a_string(self):
     instance = fields.ListField(child=fields.IntegerField())
     self.assertEqual(
         instance.to_internal_value(['1', '2', '3']),
         [1, 2, 3]
     )
Пример #10
0
 def test_to_internal_value_for_integer_list(self):
     instance = fields.ListField(child=fields.IntegerField())
     self.assertEqual(instance.to_internal_value([1, 2, 3]), [1, 2, 3])
Пример #11
0
 def test_to_internal_value_empty_list(self):
     instance = fields.ListField(child=fields.IntegerField())
     self.assertEqual(instance.to_internal_value([]), [])
Пример #12
0
 def test_get_value(self):
     instance = fields.ListField(child=fields.IntegerField())
     instance.bind('test', None)
     self.assertEqual(instance.get_value({'test': [1, 2, 3]}), [1, 2, 3])
Пример #13
0
    def test_init_raises_assertion_error_for_child_without_source(self):

        with self.assertRaises(AssertionError):
            fields.ListField(child=fields.IntegerField(source='value'))
Пример #14
0
    def test_init_raises_assertion_error_for_defined_child_as_a_class(self):

        with self.assertRaises(AssertionError):
            fields.ListField(child=fields.IntegerField)