Testing Documentation
Overview
The Digital Landscape application includes a comprehensive testing framework to ensure API endpoints function correctly and reliably. The testing suite focuses primarily on backend API validation, verifying that data is correctly retrieved, filtered, and processed according to specifications.
Testing Architecture
The testing framework is built using Python with pytest and follows these key principles:
- Isolated Tests: Each test function validates a specific endpoint or functionality
- Comprehensive Coverage: Tests cover all API endpoints and their various parameters
- Clear Documentation: Each test includes detailed docstrings explaining purpose and expectations
- Error Handling Validation: Tests verify proper error responses for invalid inputs
- Organized Structure: Tests are grouped by API type across multiple files
Test Structure
The tests are organized into three main files:
Test File | Endpoint Group | Description |
---|---|---|
test_main.py |
/api/* |
Core API endpoints (health, CSV, JSON, repository) |
test_admin.py |
/admin/api/* |
Admin API endpoints for banner management |
test_review.py |
/review/api/* |
Review API endpoints for tech radar updates |
Test Setup
Prerequisites
- Python 3.8 or higher
- Make (for using Makefile commands)
- Backend server running on localhost:5001
Installation
# Navigate to the testing directory
cd testing
# Create a virtual environment (recommended)
python3 -m venv venv
source venv/bin/activate
# Install dependencies
make setup
Running Tests
The testing framework provides several commands for running tests:
# Run all tests
make test
# Run only core API tests
make test-main
# Run only admin API tests
make test-admin
# Run only review API tests
make test-review
# Run a specific test
python3 -m pytest backend/test_main.py::test_name -v
# Example: Run only the health check test
python3 -m pytest backend/test_main.py::test_health_check -v
Test Categories
The test suite covers the following API endpoints:
Health Check Endpoint
Tests the /api/health
endpoint to verify server status and health metrics.
Test the health check endpoint functionality.
This test verifies that the health check endpoint is operational and returns the expected health status information about the server. It checks for the presence of essential health metrics and status indicators.
Endpoint
GET /api/health
Expects
- 200 status code
- JSON response containing:
- "healthy" status indicator
- Current timestamp
- Server uptime in seconds
- Memory usage statistics
- Process ID
Source code in testing/backend/test_main.py
Project Data Endpoint
Tests the /api/csv
endpoint that provides project data from CSV sources.
Test the CSV data endpoint functionality.
This test verifies that the CSV endpoint correctly returns parsed CSV data from the S3 bucket. It checks that the data is properly formatted and contains the expected structure.
Endpoint
GET /api/csv
Expects
- 200 status code
- JSON array response
- Non-empty data entries
- Each entry should be a dictionary with multiple fields
- No empty or malformed entries
Source code in testing/backend/test_main.py
Tech Radar Data Endpoint
Tests the /api/tech-radar/json
endpoint that provides Tech Radar configuration data.
Test the tech radar JSON endpoint functionality.
This test verifies that the tech radar endpoint correctly returns the radar configuration data from the S3 bucket. The data defines the structure and content of the technology radar visualization.
Endpoint
GET /api/tech-radar/json
Expects
- 200 status code
- JSON object response
- Non-empty configuration data
- Multiple configuration keys present
Source code in testing/backend/test_main.py
Repository Statistics Endpoints
Tests the /api/json
endpoint with various filtering parameters:
- No parameters (default behavior)
- Date filtering
- Archived status filtering
- Combined parameter filtering
- Invalid parameter handling
Test the JSON endpoint without query parameters.
This test verifies the default behavior of the JSON endpoint when no filters are applied. It checks that the endpoint returns complete repository statistics and metadata.
Endpoint
GET /api/json
Expects
- 200 status code
- JSON response containing:
- Repository statistics
- Language usage statistics
- Metadata information
- Complete stats structure with:
- Total repository count
- Private repository count
- Public repository count
- Internal repository count
Source code in testing/backend/test_main.py
Test the JSON endpoint with datetime filtering.
This test verifies that the endpoint correctly filters repository data based on a specified datetime parameter. It checks repositories modified within the last 7 days.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
datetime |
str
|
ISO formatted datetime string for filtering |
required |
Example
GET /api/json?datetime=2024-03-20T00:00:00Z
Expects
- 200 status code
- Filtered repository data
- Metadata containing the applied datetime filter
Source code in testing/backend/test_main.py
Repository Project Endpoints
Tests the /api/repository/project/json
endpoint with various parameters:
- Missing parameters (error handling)
- Single repository filtering
- Multiple repository filtering
- Date filtering
- Archived status filtering
- Combined parameter filtering
- Language statistics validation
Test the repository project JSON endpoint with a valid repository parameter.
This test verifies the endpoint's basic functionality when requesting data for a single repository. It checks the complete response structure including repository data, statistics, and metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repositories |
str
|
Name of the repository to query (e.g., "tech-radar") |
required |
Expects
- 200 status code
- JSON response with complete repository data
- Valid statistics for the repository
- Correct metadata including requested repository names
- Language statistics if available
Source code in testing/backend/test_main.py
Test the repository project JSON endpoint with multiple repositories.
This test verifies that the endpoint correctly handles requests for multiple repositories in a single call. It checks that all requested repositories are processed and included in the response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repositories |
str
|
Comma-separated list of repository names |
required |
Example
GET /api/repository/project/json?repositories=tech-radar,another-repo
Expects
- 200 status code
- Data for all requested repositories
- Metadata containing all requested repository names
- Aggregated statistics across all repositories
Source code in testing/backend/test_main.py
Tech Radar Update Endpoints
Tests the endpoints for updating Tech Radar data:
- Empty update handling
- Partial updates
- Invalid entry handling
- Structure validation
- Reference validation
Test the tech radar update endpoint with valid complete structure.
This test verifies that the endpoint correctly processes a complete tech radar update with valid structure for all components.
Endpoint
POST /review/api/tech-radar/update
Test Data
- Valid title
- Valid quadrants with required fields
- Valid rings with required fields
- Valid entries with required fields
Expects
- 200 status code
- Successful update confirmation
- Correct structure in stored data
Source code in testing/backend/test_review.py
Test the tech radar update endpoint with invalid structure.
This test verifies that the endpoint correctly validates the complete structure of the tech radar data, including title, quadrants, rings, and entries.
Endpoint
POST /review/api/tech-radar/update
Test Data
- Missing title
- Invalid quadrants structure
- Invalid rings structure
- Invalid entries structure
Expects
- 400 status code for each invalid case
- Appropriate error messages
- No changes to existing data
Source code in testing/backend/test_review.py
Admin Banner Management Endpoints
Tests the endpoints for managing banner messages:
- Banner retrieval
- Banner creation
- Banner visibility toggling
- Banner deletion
- Validation of requests
Test the admin banners endpoint for retrieving banner messages.
This test verifies that the endpoint correctly returns banner messages from the S3 bucket. It checks the structure of the response and ensures the messages array is present.
Endpoint
GET /admin/api/banners
Expects
- 200 status code
- JSON response containing a messages array
- Valid structure that can be parsed by the admin UI
Source code in testing/backend/test_admin.py
Test the admin banners update endpoint.
This test verifies that the endpoint correctly processes banner updates with valid data and saves them to the S3 bucket.
Endpoint
POST /admin/api/banners/update
Test Data
- Valid banner message
- Array of pages where the banner should appear
- Optional banner title and type
Expects
- 200 status code
- Success message confirming the banner was added
- Banner should be retrievable in subsequent GET requests
Source code in testing/backend/test_admin.py
Error Handling Tests
The test suite includes specific tests for error conditions:
- Invalid endpoints
- Invalid date parameters
- Missing required parameters
- Invalid data structures
Test error handling for invalid endpoints.
This test verifies that the server properly handles requests to non-existent endpoints by returning appropriate error status codes.
Example
GET /api/nonexistent
Expects
- Either 404 (Not Found) or 500 (Internal Server Error) status code
- Proper error handling for invalid routes
Source code in testing/backend/test_main.py
Test the JSON endpoint's handling of invalid date parameters.
This test verifies that the endpoint gracefully handles invalid datetime parameters without failing. It should ignore the invalid date and return unfiltered results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
datetime |
str
|
An invalid datetime string |
required |
Example
GET /api/json?datetime=invalid-date
Expects
- 200 status code (graceful handling)
- Null filter_date in metadata
- Valid response with unfiltered stats
- Complete language statistics
Source code in testing/backend/test_main.py
Code Quality
The testing framework includes tools for maintaining code quality:
# Run linting checks
make lint
# Run specific linters
make ruff
make pylint
# Clean up cache files
make clean
Integration with Utilities
The tests validate the same endpoints used by the frontend utilities:
- Project Data Utility: Tests the
/api/csv
endpoint used byfetchCSVFromS3()
- Repository Data Utility: Tests the
/api/repository/project/json
endpoint used byfetchRepositoryData()
- Tech Radar Data Utility: Tests the
/api/tech-radar/json
endpoint used byfetchTechRadarJSONFromS3()
- Admin Utilities: Tests the
/admin/api/banners*
endpoints used by the admin interface for banner management
This ensures that the data providers for the DataContext are functioning correctly and returning the expected data structures.