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, {}]]})
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, {}]]}')
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)")
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', {}]]})
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())
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', {}]]})
def test_run_validation_raises_validation_error(self): instance = fields.JSONField() with self.assertRaises(ValidationError): instance.run_validation({'key': [1, '2', [3, set()]]})