Ejemplo n.º 1
0
 def test_to_internal_value_for_binary_json(self):
     instance = fields.JSONField(binary=True)
     self.assertEqual(
         instance.to_internal_value(b'{"key": [0.0, 1, [2, {}]]}'),
         {"key": [0.0, 1, [2, {}]]})
Ejemplo n.º 2
0
 def test_to_representation_for_binary_json(self):
     instance = fields.JSONField(binary=True)
     self.assertEqual(
         instance.to_representation({'key': [0.0, 1, [2, {}]]}),
         b'{"key": [0.0, 1, [2, {}]]}')
Ejemplo n.º 3
0
    def test_run_validation_raises_validation_error_for_binary_json(self):
        instance = fields.JSONField(binary=True)

        with self.assertRaises(ValidationError):
            instance.run_validation("{'key': \"str)")
Ejemplo n.º 4
0
 def test_to_representation(self):
     instance = fields.JSONField()
     self.assertEqual(
         instance.to_representation({'key': [0.0, 1, [2, 'nested', {}]]}),
         {'key': [0.0, 1, [2, 'nested', {}]]})
Ejemplo n.º 5
0
    def test_to_internal_value_raises_validation_error_for_a_wrong_type(self):
        instance = fields.JSONField()

        with self.assertRaises(ValidationError):
            instance.to_internal_value(set())
Ejemplo n.º 6
0
 def test_to_internal_value(self):
     instance = fields.JSONField()
     self.assertEqual(
         instance.to_internal_value({'key': [0.0, 1, [2, 'nested', {}]]}),
         {'key': [0.0, 1, [2, 'nested', {}]]})
Ejemplo n.º 7
0
    def test_run_validation_raises_validation_error(self):
        instance = fields.JSONField()

        with self.assertRaises(ValidationError):
            instance.run_validation({'key': [1, '2', [3, set()]]})