Files
Hotel-Booking/Backend/src/tests/README.md
Iliyan Angelov cf97df9aeb updates
2025-11-28 20:24:58 +02:00

3.5 KiB

Integration Tests

This directory contains comprehensive integration tests for the Hotel Booking API backend.

Overview

The integration tests cover all major API endpoints and test the entire backend functionality end-to-end. Tests use an in-memory SQLite database to ensure fast execution and isolation between tests.

Test Structure

  • conftest.py - Pytest fixtures and test configuration
  • test_integration_auth.py - Authentication endpoints (register, login, logout, etc.)
  • test_integration_rooms.py - Room management endpoints
  • test_integration_bookings.py - Booking creation and management
  • test_integration_payments.py - Payment and invoice endpoints
  • test_integration_services.py - Service and service booking endpoints
  • test_integration_promotions.py - Promotion code validation and management
  • test_integration_reviews.py - Review endpoints
  • test_integration_users.py - User management endpoints
  • test_integration_favorites.py - Favorite rooms endpoints
  • test_integration_health.py - Health check and monitoring endpoints
  • test_integration_other_endpoints.py - Other endpoints (banners, pages, etc.)

Running Tests

Run all integration tests:

cd Backend
pytest src/tests/ -v -m integration

Run specific test file:

pytest src/tests/test_integration_auth.py -v

Run with coverage:

pytest src/tests/ -v -m integration --cov=src --cov-report=html

Run specific test:

pytest src/tests/test_integration_auth.py::TestAuthEndpoints::test_register_user -v

Test Fixtures

The conftest.py file provides several useful fixtures:

  • db_session - Database session for each test
  • client - Test client without authentication
  • authenticated_client - Test client with user authentication
  • admin_client - Test client with admin authentication
  • staff_client - Test client with staff authentication
  • test_user, test_admin_user, test_staff_user - Test users
  • test_room, test_room_type - Test room data
  • test_booking - Test booking
  • test_service, test_promotion - Test services and promotions

Test Coverage

The integration tests cover:

  1. Authentication & Authorization

    • User registration
    • Login/logout
    • Token refresh
    • Password management
    • Role-based access control
  2. Rooms

    • Listing rooms with filters
    • Room availability search
    • Room details
    • Room management (admin)
  3. Bookings

    • Creating bookings
    • Viewing bookings
    • Updating booking status
    • Canceling bookings
    • Booking with promotions
  4. Payments & Invoices

    • Payment creation
    • Payment status updates
    • Invoice generation
    • Invoice retrieval
  5. Services

    • Service listing
    • Service bookings
    • Service management
  6. Other Features

    • Reviews
    • Favorites
    • Promotions
    • User management
    • Health checks

Notes

  • Tests use an in-memory SQLite database for speed and isolation
  • Each test gets a fresh database session
  • Tests are marked with @pytest.mark.integration for easy filtering
  • Some endpoints may return 404 if not yet implemented - tests handle this gracefully
  • Authentication is tested with different user roles (guest, staff, admin)

Troubleshooting

If tests fail:

  1. Ensure all dependencies are installed: pip install -r requirements.txt
  2. Check that the database models are properly imported
  3. Verify that the test database can be created (SQLite should work out of the box)
  4. Check for any missing environment variables (though tests should work with defaults)