Skip to content

Commit

Permalink
chore: add basic testing config
Browse files Browse the repository at this point in the history
  • Loading branch information
ocamilomontealegre committed Nov 1, 2024
1 parent 5881457 commit fcd8b62
Show file tree
Hide file tree
Showing 5 changed files with 273 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ __pycache__/
build/
.python-version
logs/

# Test
.coverage
197 changes: 196 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 22 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,35 @@ injector = "^0.22.0"
black = "^24.10.0"
flake8 = "^7.1.1"
pre-commit = "^4.0.1"
pytest = "^8.3.3"
pytest-cov = "^6.0.0"
httpx = "^0.27.2"

[tool.black]
line-length = 88
target-version = ["py310", "py311", "py312"]
check = true

[tool.pytest.ini_options]
testpaths = ["test"]
pythonpath = "src"
addopts = "--cov=app --cov-report=term-missing --cov-report=html --cov-report=xml"

[tool.coverage.run]
command_line = "-m pytest"

[tool.coverage.report]
include = ["python_coverage_demo/*.py"]
show_missing = true

[tool.poetry.scripts]
start = "commands:start"
lint = "commands:lint"
format = "commands:format"
start = "scripts:start"
lint = "scripts:lint"
format = "scripts:format"
e2e_test = "scripts:test_e2e"
unit_test = "scripts:test_unit"
test = "scripts:test_all"


[build-system]
requires = ["poetry-core"]
Expand Down
25 changes: 25 additions & 0 deletions commands.py → scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,28 @@ def format() -> None:
print(f"Formatting failed with error code {e.returncode}: {error_message}")
except Exception as e:
print(f"An unexpected error occurred: {e}")


def test_e2e() -> None:
"""Run e2e tests"""
try:
check_call(["pytest", "test/e2e/"])
except Exception as e:
print(f"An unexpected error occurred: {e}")


def test_unit() -> None:
"""Run e2e tests"""
try:
check_call(["pytest", "test/unit/"])
except Exception as e:
print(f"An unexpected error occurred: {e}")


def test_all() -> None:
"""Run e2e tests"""
try:
test_unit()
test_all()
except Exception as e:
print(f"An unexpected error occurred: {e}")
27 changes: 27 additions & 0 deletions test/e2e/src/health/health_controller_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
from src.health.controllers.health_controller import HealthController
from src.health.services.health_service import HealthService


@pytest.fixture
def app() -> FastAPI:
app = FastAPI()
health_service = HealthService()
health_controller = HealthController(health_service)
app.include_router(health_controller.get_router(), prefix="/api/v1/health")
return app


@pytest.fixture
def client(app: FastAPI) -> TestClient:
"""Create a TestClient for the app"""
return TestClient(app)


def test_health_check(client: TestClient):
"""Test the health check endpoint for a successful response."""
response = client.get("/api/v1/health")

assert response.status_code == 200

0 comments on commit fcd8b62

Please sign in to comment.