Esempio 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, {}]]}
     )
Esempio 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, {}]]}'
     )
Esempio 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)")
Esempio 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', {}]]}
     )
Esempio 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())
Esempio 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', {}]]}
     )
Esempio 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()]]})