def test_get_attribute_raises_not_implemented_error(self): class FakeObject(object): def __init__(self, pk): self.pk = pk obj = FakeObject(10) instance = RelatedField(read_only=True) instance.bind('pk', None) with self.assertRaises(NotImplementedError): self.assertEqual(instance.get_attribute(obj), obj.pk)
def test_to_internal_value_raises_error_for_empty_value(self): child_instance = RelatedField(read_only=True) instance = ManyRelatedField( child_relation=child_instance, allow_empty=False ) with self.assertRaises(ValidationError): instance.to_internal_value([])
def test_get_value_returns_empty_value(self): child_instance = RelatedField(read_only=True) instance = ManyRelatedField(child_relation=child_instance) instance.bind('pk_list', None) self.assertEqual( instance.get_value({'pks': [1, 2, 3]}), empty )
def test_get_attribute_raises_not_implemented_error(self): class FakeObject(object): def __init__(self, pk): self.pk = pk def __str__(self): return str(self.pk) child_instance = RelatedField(read_only=True) instance = ManyRelatedField(child_relation=child_instance) with self.assertRaises(NotImplementedError): instance.get_attribute(FakeObject(10))
def test_run_validation_raises_skip_field_exception_for_empty_string(self): instance = RelatedField(read_only=True) with self.assertRaises(SkipField): instance.run_validation('')
def test_run_validation(self): instance = RelatedField(read_only=True) with self.assertRaises(SkipField): value = object() instance.run_validation(value)
def test_init_raises_assertion_error_for_read_only_field(self): with self.assertRaises(AssertionError): RelatedField(read_only=False)
def test_init_raises_assertion_error_for_not_specified_queryset(self): with self.assertRaises(AssertionError): RelatedField()
def test_to_internal_value_raises_error_for_not_a_list_argument(self): child_instance = RelatedField(read_only=True) instance = ManyRelatedField(child_relation=child_instance) with self.assertRaises(ValidationError): instance.to_internal_value(object())
def test_use_pk_only_optimization_returns_False(self): instance = RelatedField(read_only=True) self.assertFalse(instance.use_pk_only_optimization())
def test_get_queryset_raises_not_implemented_error(self): instance = RelatedField(read_only=True) with self.assertRaises(NotImplementedError): instance.get_queryset()