Testing and Deployment (March 2022)
Testing
I have set up the testing infrastructure, which creates a mock database with sqllite. We set up our database connection in src/api/database.py. If we are running tests, we create an sqllite database file in ‘src/tests/data’ and use that for our database URL, otherwise we use the production database URL defined by the DB_URL environment variable, which is set in our environments.env file in the deployment directory.
For system tests, we use pytest with FastAPI’s test client. Before running our tests, we populate our sqllite test database with the schema defined in ‘src/models’. We then override the authentication dependency of our endpoints, that way we don’t have to deal with tokens and it allows the tests to be extendable if we switch to using an external authentication provider which may charge per request or calling it may take time. We then have a series of tests for each endpoint that test each branch and edge case. For unit tests we use setUp and tearDown methods to set up independent data in a mock database for testing, and have a series of tests which tests each of our crud util functions.
Deployment
I have now re-deployed the system onto Linode using an NGINX reverse proxy to handle web traffic, there are also now no docker ports exposed to the internet as all containers communicate over a docker network, and I have made it so only localhost can access exposed ports, I then just installed NGINX onto Linode and set up a reverse proxy which redirects traffic from port 80 to port 3000. We have also performed user testing with 3 members of our cohort after approval from our client. everything is working as it should, there were just a few suggestions on design.