First download and set up MongoDB locally by following the tutorial:
You can run the server locally as followed:
# Create a new virtual environment
python3 -m venv env
source env/bin/activate
# Install required packages
pip3 install -r requirements.txt
IMPORTANT: Do not use production database when running locally!
export DB_CONNECTION_STRING=<dev database connection string>
Note: When testing on local database, set it to something like
DB_CONNECTION_STRING="mongodb://127.0.0.1:27017/"
And for MongoDB Atlas, do something like
"mongodb+srv://:@cluster0.jqoga.mongodb.net/?retryWrites=true&w=majority"
uvicorn --port <port_number> --workers 8 niched.main:app
#replace <port_number> with a port number to run the web app on, different to the database's port number
IMPORTANT: Again, use development database as before!
Unit tests should not connect to the database or communicate with the 'outside world'
# Create a new virtual environment
python3 -m venv env
source env/bin/activate
pip3 install -r requirements.txt
export PYTHONPATH=.
pytest --cov-report term-missing:skip-covered --cov=niched/ test/unit_tests/
When running integration tests, use dev database! You can also create your own database locally, and then connect to this database in development stage.
To create a local mongoDB, follow this guide!
# Create a new virtual environment
python3 -m venv env
source env/bin/activate
pip3 install -r requirements.txt
export PYTHONPATH=.
export DB_CONNECTION_STRING=<database connection string>
export DB_DATABASE="develop"
pytest --cov-report term-missing:skip-covered --cov=niched/ test/integration_tests/
For example, to run the server locally, set DB_CONNECTION_STRING
to mongodb://127.0.0.1:27017/
Pytest has more options for reports, see the page for more information!
To run GitLab-CI test pipelines:
gitlab-runner exec docker unit-test
gitlab-runner exec docker integration-test