-
Notifications
You must be signed in to change notification settings - Fork 0
Test/ci switch to pytest with coverage #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # I Don't Need It | ||
|
|
||
| [](https://github.com/recursive-one/idontneedit/actions/workflows/ci.yml) | ||
| [](https://codecov.io/gh/recursive-one/idontneedit) | ||
| [](https://www.python.org/downloads/) | ||
| [](https://www.djangoproject.com/) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import pytest | ||
| from django.urls import reverse | ||
| from unittest.mock import patch | ||
|
|
||
| # Use pytest-django's built-in `client` fixture | ||
|
|
||
|
|
||
| @pytest.mark.django_db | ||
| class TestHealthCheck: | ||
| """Test suite for health check endpoint.""" | ||
|
|
||
| def test_health_check_success(self, client): | ||
| """Test that health check returns 200 when database is connected.""" | ||
| response = client.get(reverse("health_check")) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response["Content-Type"] == "application/json" | ||
|
|
||
| data = response.json() | ||
| assert data["status"] == "healthy" | ||
| assert data["database"] == "connected" | ||
|
|
||
| def test_health_check_database_failure(self, client): | ||
| """Test that health check returns 503 when database connection fails.""" | ||
| with patch("config.views.connection") as mock_connection: | ||
| mock_connection.cursor.return_value.__enter__.return_value.execute.side_effect = Exception( | ||
| "Database connection failed" | ||
| ) | ||
|
|
||
| response = client.get(reverse("health_check")) | ||
|
|
||
| assert response.status_code == 503 | ||
|
|
||
| data = response.json() | ||
| assert data["status"] == "unhealthy" | ||
| assert data["database"] == "disconnected" | ||
|
|
||
| def test_health_check_only_allows_get(self, client): | ||
| """Test that health check endpoint only accepts GET requests.""" | ||
| response = client.post(reverse("health_check")) | ||
| assert response.status_code == 405 | ||
|
|
||
| response = client.put(reverse("health_check")) | ||
| assert response.status_code == 405 | ||
|
|
||
| response = client.delete(reverse("health_check")) | ||
| assert response.status_code == 405 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,4 +15,46 @@ dependencies = [ | |
| dev = [ | ||
| "black>=25.11.0", | ||
| "pre-commit>=4.5.0", | ||
| "pytest>=8.3.4", | ||
| "pytest-django>=4.9.0", | ||
| "pytest-cov>=6.0.0", | ||
| ] | ||
|
|
||
| [tool.pytest.ini_options] | ||
| DJANGO_SETTINGS_MODULE = "config.settings" | ||
| python_files = ["test_*.py", "*_test.py", "tests.py"] | ||
| addopts = [ | ||
| "--strict-markers", | ||
| "--strict-config", | ||
| "--cov=config", | ||
| "--cov-report=term-missing", | ||
| "--cov-report=html", | ||
| "--cov-report=xml", | ||
| ] | ||
|
|
||
| [tool.coverage.run] | ||
| source = ["."] | ||
|
Comment on lines
+29
to
+36
|
||
| omit = [ | ||
| "*/tests/*", | ||
| "*/test_*.py", | ||
| "*_test.py", | ||
| "*/migrations/*", | ||
| "manage.py", | ||
| "*/wsgi.py", | ||
| "*/asgi.py", | ||
| "*/__pycache__/*", | ||
| "*/.venv/*", | ||
| "*/venv/*", | ||
| ] | ||
|
|
||
| [tool.coverage.report] | ||
| exclude_lines = [ | ||
| "pragma: no cover", | ||
| "def __repr__", | ||
| "raise AssertionError", | ||
| "raise NotImplementedError", | ||
| "if __name__ == .__main__.:", | ||
| "if TYPE_CHECKING:", | ||
| "class .*\\bProtocol\\):", | ||
| "@(abc\\.)?abstractmethod", | ||
| ] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
test-covandtest-cov-xmltargets override the coverage report settings defined inpyproject.toml(lines 30-32). The pyproject.toml already configures--cov-report=term-missing,--cov-report=html, and--cov-report=xmlin theaddoptssection. These Makefile targets should either:--cov-reportflags and rely on pyproject.toml defaults, or--no-covto disable coverage and then re-enable specific reports if customization is needed.The current implementation may produce duplicate reports.