3.5 KiB
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 configurationtest_integration_auth.py- Authentication endpoints (register, login, logout, etc.)test_integration_rooms.py- Room management endpointstest_integration_bookings.py- Booking creation and managementtest_integration_payments.py- Payment and invoice endpointstest_integration_services.py- Service and service booking endpointstest_integration_promotions.py- Promotion code validation and managementtest_integration_reviews.py- Review endpointstest_integration_users.py- User management endpointstest_integration_favorites.py- Favorite rooms endpointstest_integration_health.py- Health check and monitoring endpointstest_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 testclient- Test client without authenticationauthenticated_client- Test client with user authenticationadmin_client- Test client with admin authenticationstaff_client- Test client with staff authenticationtest_user,test_admin_user,test_staff_user- Test userstest_room,test_room_type- Test room datatest_booking- Test bookingtest_service,test_promotion- Test services and promotions
Test Coverage
The integration tests cover:
-
Authentication & Authorization
- User registration
- Login/logout
- Token refresh
- Password management
- Role-based access control
-
Rooms
- Listing rooms with filters
- Room availability search
- Room details
- Room management (admin)
-
Bookings
- Creating bookings
- Viewing bookings
- Updating booking status
- Canceling bookings
- Booking with promotions
-
Payments & Invoices
- Payment creation
- Payment status updates
- Invoice generation
- Invoice retrieval
-
Services
- Service listing
- Service bookings
- Service management
-
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.integrationfor 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:
- Ensure all dependencies are installed:
pip install -r requirements.txt - Check that the database models are properly imported
- Verify that the test database can be created (SQLite should work out of the box)
- Check for any missing environment variables (though tests should work with defaults)