Testing

Software Testing Methodology

Overview

The Plant Adaptation Hub backend employs a rigorous, multi-layered testing strategy to ensure system reliability, security, and data integrity. Our comprehensive test suite demonstrates the robustness of the platform through automated testing of all critical components.

Test Results Summary

Quantitative Metrics

  • Total Tests Executed: 38
  • Tests Passed: 38 (100% success rate)
  • Test Execution Time: 4.53 seconds
  • Average Test Duration: 119 milliseconds
  • Test Coverage: Comprehensive across authentication, API endpoints, database, and external services

Test Categories

The test suite is organized into three primary categories:

  1. Integration Tests (16 tests) - End-to-end API validation with real database.
  2. Unit Tests (22 tests) - Individual component validation using mocks.
  3. Live Deployment Tests (2 tests) - Production environment validation via https://www.camelina-hub.org.

Detailed Test Analysis

Integration Testing Layer

Live Deployment Integration Tests

Test CaseDurationDescription
test_studies_list_live1.299sValidates study listing functionality in production environment
test_health_check_live0.029sVerifies health monitoring endpoint availability

Real Database API Integration Tests

Test CaseDurationDescription
test_studies_endpoint_real_db0.236sValidates study data retrieval with actual database
test_assays_endpoint_real_db0.096sTests assay data retrieval and filtering
test_blast_search_mixed0.071sValidates BLAST sequence search with mixed inputs
test_get_ontologies_real_db0.161sTests ontology term lookup and matching
test_health_endpoint_public0.058sVerifies public health check accessibility
test_invalid_token_rejection0.040sEnsures proper rejection of invalid authentication tokens

Unit Testing Layer

Authentication System Tests

Test CaseDurationDescription
test_root_endpoint0.028sValidates API root endpoint accessibility
test_auth_missing_credentials0.028sTests authentication with missing credentials
test_auth_invalid_credentials0.029sValidates rejection of incorrect credentials
test_auth_success0.041sTests successful authentication flow
test_auth_guest_user0.040sValidates guest user authentication
test_auth_admin_expiry0.320sTests admin token expiry configuration
test_auth_server_error0.029sValidates error handling during authentication failures

Configuration Validation Tests

Test CaseDurationDescription
test_secret_key_loaded0.002sValidates secure key loading
test_database_config_loaded0.002sTests database configuration parsing
test_minio_config_loaded0.002sValidates MinIO storage configuration
test_jwt_config_loaded0.002sTests JWT token configuration
test_testing_environment0.002sValidates test environment setup

Database Connection Tests

Test CaseDurationDescription
test_get_db_connection_success0.002sValidates successful database connection
test_get_db_connection_retry_logic0.005sTests connection retry mechanism
test_get_db_connection_max_retries_exceeded0.003sValidates graceful failure after max retries
test_get_user_with_db_error0.002sTests user retrieval error handling

Token Validation Tests

Test CaseDurationDescription
test_validate_token_endpoint_missing_token0.031sTests token validation without token
test_validate_token_endpoint_valid_token_guest0.029sValidates guest token verification
test_validate_token_endpoint_expired_token0.030sTests expired token rejection
test_validate_token_endpoint_disabled_guest0.029sValidates disabled guest account handling
test_token_required_decorator_options0.028sTests CORS preflight request handling
test_token_validation_malformed_token0.029sValidates rejection of malformed tokens

Performance Analysis

Test Execution Efficiency

  • Fastest Test: 2ms (configuration validation tests)
  • Slowest Test: 1.299s (live deployment integration test)
  • Average Test Speed: 119ms
  • 95th Percentile: 236ms

Critical Path Performance

  1. Authentication Flow: Complete authentication test suite executes in 0.525s.
  2. Database Operations: Connection and query tests complete in 0.012s.
  3. API Endpoints: Full integration test suite completes in 1.774s.

Testing Methodology

Test Architecture

The testing architecture is built upon the pytest framework and follows a modular design:

  • Mocking: unittest.mock is utilized in unit tests to isolate service logic from external dependencies (PostgreSQL, MinIO, and Subprocess calls).
  • Environment Isolation: A dedicated conftest.py ensures that test environment variables (JWT secrets, test database credentials) are used exclusively during execution.
  • JWT Verification: Real token signing and verification logic are tested to ensure that the @secure and @token_required decorators correctly enforce Role-Based Access Control (RBAC).
  • E2E Validation: Live deployment tests utilize the requests library to perform real-world handshakes with the production API, ensuring that network configurations and SSL certificates are valid.