-
Python 3.12 or newer (required for development)
- Install it from the Python official website.
- Verify installation:
Ensure the version is
python --version
3.12.x.
-
Docker & Docker Compose (required for database and production setup)
- Install Docker from the Docker official website.
- Install Docker Compose by following the instructions on the Docker Compose installation page.
- Verify installation:
docker --version docker-compose --version
If you encounter an error similar to the following when running the application:
ImportError: dlopen(.../_psycopg.cpython-312-darwin.so, 0x0002): Library not loaded: @rpath/libpq.5.dylib
It means that the PostgreSQL client library (libpq) is not found. To fix this issue on macOS, run the following command to install libpq via Homebrew:
brew install libpqThis should resolve the missing library error.
-
Clone the repository:
git clone https://github.com/PBL-Akatsuki/backend.git
-
Navigate to the project root directory:
cd backend -
Start PostgreSQL and pgAdmin (via Docker Compose):
docker-compose up -d postgres pgadmin
- This starts the database and pgAdmin services. You can access pgAdmin at http://localhost:8080.
- Use these credentials to log in:
- Email:
admin@example.com - Password:
admin
- Email:
-
Set up a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r app/requirements.txt
-
Run the FastAPI application with hot reload:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
- The API will be available at http://localhost:8000.
- The Swagger UI (API documentation) is available at http://localhost:8000/docs.
-
Clone the repository:
git clone https://github.com/PBL-Akatsuki/backend.git
-
Navigate to the project root directory:
cd backend -
Build the Docker image:
docker-compose up --build -d
-
Access the FastAPI application:
- The API will be available at http://localhost:8000.
- The Swagger UI (API documentation) is available at http://localhost:8000/docs.
Run all tests:
PYTHONPATH=. pytest -v tests/This will run all the test cases in the tests/ directory. It includes tests for:
- User creation and authentication.
- Retrieving user information.
- Database operations like adding, updating, and deleting users.
To check test coverage:
PYTHONPATH=. pytest --cov=app tests/This will show how much of your code is covered by the tests.
-
User Routes:
- Test user creation (
/signup). - Test user login (
/login). - Test user deletion (
/delete-user/{id}). - Test user updates (
/update-user/{id}).
- Test user creation (
-
Database Operations:
- Verify database integration for CRUD operations.
-
Edge Cases:
- Attempting to create a user with missing fields.
- Logging in with invalid credentials.
- Deleting a non-existent user.
- Hot Reload: FastAPI runs with
uvicorn --reloadfor automatic code reload on changes. - Database & pgAdmin: PostgreSQL and pgAdmin run via Docker Compose to avoid local installation.
- Dockerized Deployment: FastAPI, PostgreSQL, and pgAdmin run inside containers.
- Tests are implemented using
pytestto ensure the reliability of the application. - Covers both happy paths and edge cases to prevent regressions and ensure robustness.