Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arturmkr committed Feb 17, 2024
1 parent 03db571 commit 37f7a94
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ coverage.xml
.hypothesis/
.pytest_cache/
coverage.out
report.json
report.json
htmlcov
24 changes: 23 additions & 1 deletion tests/unit/test_api_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

0 comments on commit 37f7a94

Please sign in to comment.