Example #1
0
 def test_to_internal_non_existent_id(self):
     """Tests an id of a non-existent object raises an exception."""
     model = MagicMock()
     model.objects().all.get.return_value = ObjectDoesNotExist
     field = NestedRelatedField(model)
     with pytest.raises(ValidationError):
         field.to_internal_value({})
Example #2
0
 def test_to_internal_str(self):
     """Tests that model instances are returned for a dict with an 'id' key."""
     model = MagicMock()
     field = NestedRelatedField(model)
     uuid_ = uuid4()
     assert field.to_internal_value(str(uuid_))
     assert model.objects.all().get.call_args_list == [call(pk=uuid_)]
Example #3
0
 def test_to_internal_uuid(self):
     """Tests that model instances are returned for a UUID."""
     model = Mock()
     field = NestedRelatedField(model)
     uuid_ = uuid4()
     assert field.to_internal_value(uuid_)
     assert model.objects.all().get.call_args_list == [call(pk=uuid_)]
Example #4
0
 def test_to_internal_wrong_type(self):
     """Tests that a non-dict value raises an exception."""
     model = MagicMock()
     field = NestedRelatedField(model)
     with pytest.raises(ValidationError):
         field.to_internal_value([])
Example #5
0
 def test_to_internal_no_id(self):
     """Tests that a dict without an id raises an exception."""
     model = MagicMock()
     field = NestedRelatedField(model)
     with pytest.raises(ValidationError):
         field.to_internal_value({})
Example #6
0
 def test_to_internal_invalid_id(self):
     """Tests that a dict with an invalid UUID raises an exception."""
     model = MagicMock()
     field = NestedRelatedField(model)
     with pytest.raises(ValidationError):
         field.to_internal_value({'id': 'xxx'})