def test_to_internal_value(self): instance = fields.HStoreField(child=fields.CharField()) self.assertEqual(instance.to_internal_value({ 'a': 1, 'b': '2' }), { 'a': '1', 'b': '2' })
def test_to_representation(self): instance = fields.HStoreField(child=fields.CharField()) self.assertEqual(instance.to_representation({ 'a': 1, 'b': '2' }), { 'a': '1', 'b': '2' })
def test_to_representation_without_child_instance(self): instance = fields.HStoreField() self.assertEqual( instance.to_representation({ 'a': 1, 'b': [1, 2], 'c': 'c' }), { 'a': '1', 'b': '[1, 2]', 'c': 'c' })
def test_to_iternal_value_without_child_instance(self): instance = fields.HStoreField() self.assertEqual( instance.to_internal_value({ 'a': 1, 'b': [1, 2], 'c': 'c' }), { 'a': '1', 'b': '[1, 2]', 'c': 'c' })
def test_to_iternal_value_without_child_instance_raises_an_error(self): instance = fields.HStoreField() with self.assertRaises(ValidationError): instance.to_internal_value('value')
def test_to_internal_value_raises_validation_error_for_a_wrong_value(self): instance = fields.HStoreField(child=fields.CharField()) with self.assertRaises(ValidationError): instance.to_internal_value({'key': None})
def test_get_value_returns_empty_value(self): instance = fields.HStoreField(child=fields.CharField()) instance.bind('test', None) self.assertEqual(instance.get_value({'key': 'value'}), empty)
def test_get_value(self): instance = fields.HStoreField() instance.bind('test', None) self.assertEqual(instance.get_value({'test': 'value'}), 'value')
def test_init_raises_assertion_error_for_child_without_source(self): with self.assertRaises(AssertionError): fields.HStoreField(child=fields.CharField(source='value'))
def test_init_raises_assertion_error_for_defined_child_as_a_class(self): with self.assertRaises(AssertionError): fields.HStoreField(child=fields.CharField)