Giter Site home page Giter Site logo

niched-back-end's Introduction

DRP 15 - Server

Requirements

Running the app locally

First download and set up MongoDB locally by following the tutorial:

https://medium.com/swlh/get-up-and-running-with-mongodb-in-under-5-minutes-abc8770b1ef8#:~:text=Open%20the%20terminal%2C%20and%20navigate,version%20and%20mongod%20%2D%2Dversion%20.

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

Testing locally

IMPORTANT: Again, use development database as before!

Running unit tests

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

niched-back-end's People

Contributors

hoangvu01 avatar zhao-xuan avatar ggwg avatar lruki avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.