def test_create_unsupported(self): """ Test a POST (create) request with a resource that does not support that type or request. Asserts that MethodNotSupportedException is raised. """ mock_resource = MagicMock() mock_resource.SUPPORTED_METHODS = () manager = ResourceManager(mock_resource, MagicMock()) with pytest.raises(MethodNotSupportedException): manager.create()
def test_create_id_already_exists(self): """ Tests that once an object is created, create method can not be called again. Asserts that ObjectAlreadyCreatedException is raised. """ mock_resource = MagicMock() mock_resource.SUPPORTED_METHODS = ("POST",) mock_resource.id = MagicMock() manager = ResourceManager(mock_resource, MagicMock()) with pytest.raises(ObjectAlreadyCreatedException): manager.create()
def test_create(self, monkeypatch): """ Tests a successful POST (create) method. Asserts that handle_response is called with the correct Response object. """ mock_resource = MagicMock() mock_client = MagicMock() mock_response = MagicMock() mock_client.post = MagicMock(return_value=mock_response) mock_resource.SUPPORTED_METHODS = ("POST",) mock_resource.id = None manager = ResourceManager(mock_resource, mock_client) monkeypatch.setattr(manager, "handle_response", MagicMock()) manager.create() # TODO test that this is called with correct path and params mock_client.post.assert_called_once() manager.handle_response.assert_called_once_with(mock_response)