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