From 37f7a943e82de657de7bdb33df8e5aee07f00f3c Mon Sep 17 00:00:00 2001 From: amkrtychian Date: Sat, 17 Feb 2024 22:53:05 +0200 Subject: [PATCH] add tests --- .gitignore | 3 ++- tests/unit/test_api_exceptions.py | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index abe0a48..4be9df2 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ coverage.xml .hypothesis/ .pytest_cache/ coverage.out -report.json \ No newline at end of file +report.json +htmlcov \ No newline at end of file diff --git a/tests/unit/test_api_exceptions.py b/tests/unit/test_api_exceptions.py index 2da6ebc..14aae28 100644 --- a/tests/unit/test_api_exceptions.py +++ b/tests/unit/test_api_exceptions.py @@ -5,7 +5,7 @@ from fastapi.testclient import TestClient from app import app -from exceptions import ResourceNotFoundException +from exceptions import ResourceNotFoundException, ResourceBlockException, ResourceReleaseException from resource_service import create_resource_service client = TestClient(app) @@ -20,3 +20,25 @@ def test_get_resource_not_found(): assert response.status_code == 404 assert "not found" in response.text + + +def test_block_resource_exception(): + mock_service = Mock() + mock_service.block_resource.side_effect = ResourceBlockException("1") + app.dependency_overrides[create_resource_service] = lambda: mock_service + + response = client.put("/resources/1/block", json={"description": "Blocking attempt"}) + + assert response.status_code == 400 + assert "cannot be blocked" in response.text + + +def test_release_resource_exception(): + mock_service = Mock() + mock_service.release_resource.side_effect = ResourceReleaseException("1") + app.dependency_overrides[create_resource_service] = lambda: mock_service + + response = client.put("/resources/1/release") + + assert response.status_code == 400 + assert "cannot be released" in response.text