This directory contains all unit and integration tests for the PARTs WebAPI project, organized following Django pytest best practices.
Tests are organized by Django app to mirror the src/ directory structure:
tests/
├── conftest.py # Shared fixtures available to all tests
├── README.md # This file
│
├── admin/ # Admin app tests
│ └── test_admin_comprehensive.py
│
├── alerts/ # Alerts app tests
│ ├── test_alerts_comprehensive.py
│ └── test_alerts_util_definitions.py
│
├── attendance/ # Attendance app tests
│ ├── test_attendance_comprehensive.py
│ └── test_attendance_integration.py
│
├── form/ # Form builder app tests
│ ├── test_form_integration.py
│ ├── test_form_util_comprehensive.py
│ └── test_form_views_comprehensive.py
│
├── general/ # General utilities tests
│ ├── test_general_cloudinary.py
│ ├── test_general_security.py
│ ├── test_general_send_message.py
│ └── test_general_util.py
│
├── public/ # Public API tests
│ ├── test_public_api_status.py
│ └── test_public_comprehensive.py
│
├── scouting/ # Scouting system tests
│ ├── test_scouting_admin_comprehensive.py
│ ├── test_scouting_field_comprehensive.py
│ ├── test_scouting_pit_comprehensive.py
│ ├── test_scouting_portal_comprehensive.py
│ ├── test_scouting_simple.py
│ ├── test_scouting_util_extended.py
│ ├── test_scouting_views_extended.py
│ └── test_strategizing_comprehensive.py
│
├── sponsoring/ # Sponsoring app tests
│ └── test_sponsoring_comprehensive.py
│
├── tba/ # The Blue Alliance integration tests
│ ├── test_tba_integration.py
│ ├── test_tba_util_comprehensive.py
│ ├── test_tba_util_extended.py
│ └── test_tba_views_comprehensive.py
│
├── user/ # User app tests
│ ├── test_user_auth_comprehensive.py
│ ├── test_user_comprehensive.py
│ ├── test_user_integration.py
│ ├── test_user_util_extended.py
│ ├── test_user_views_extended.py
│ └── test_user_coverage.py
│
├── project/ # Project-level tests (URLs, apps config, etc.)
│ ├── test_api_urls.py
│ ├── test_apps_comprehensive.py
│ ├── test_bulk_modules.py
│ └── test_manage_py.py
│
└── misc/ # Cross-cutting coverage tests
└── test_coverage_misc.py
Note: Each app directory contains a test_<app>_coverage.py file with additional coverage tests that were extracted from the misc folder.
pytestpytest tests/user/
pytest tests/scouting/pytest tests/user/test_user_comprehensive.pypytest tests/user/test_user_comprehensive.py::TestUserViewspytest tests/user/test_user_comprehensive.py::TestUserViews::test_user_profile_getpytest --cov=src --cov-report=term-missingpytest -k "test_user"When adding tests for a new feature:
-
Place test files in the appropriate app directory under
tests/<app_name>/ -
Follow naming conventions:
- Test files:
test_<component>_<type>.py - Test classes:
Test<ComponentName> - Test methods:
test_<what>_<when>_<expected>
- Test files:
-
Use shared fixtures from
conftest.py:api_client- DRF API clienttest_user- Standard test useradmin_user- Admin userauthenticated_api_client- Pre-authenticated API client
-
Example test structure:
import pytest
from unittest.mock import patch
@pytest.mark.django_db
class TestMyFeature:
"""Tests for my feature."""
def test_success_case(self, api_client, test_user):
"""Test the happy path."""
api_client.force_authenticate(user=test_user)
response = api_client.get('/api/endpoint/')
assert response.status_code == 200
def test_error_case(self, api_client):
"""Test error handling."""
response = api_client.get('/api/endpoint/')
assert response.status_code == 401This test suite follows Django pytest best practices:
- Mirror app structure: Tests are organized to match the
src/directory - One app per directory: Each Django app has its own test subdirectory
- Shared fixtures: Common test setup lives in
conftest.py - Clear naming: Test files clearly indicate what they test
- No init.py files: Test directories don't have
__init__.pyto avoid namespace conflicts with app modules
See TESTING.md in the repository root for:
- Coverage roadmap
- Testing best practices
- CI/CD configuration
- Tools and resources