-
Notifications
You must be signed in to change notification settings - Fork 0
For Developers
This is a guide for project developer and repository maintainer to set up environment and start developing.
Clone the repository and change directories into the repository.
git clone [email protected]:berkeley-cdss/seating.git
cd seating
Create and activate a virtual environment.
Windows:
python3 -m venv venv
./venv/Scripts/activate
Mac:
python3 -m venv venv
source venv/bin/activate
You should install from both requirements.txt
and requirements-dev.txt
.
Make sure you are in the virtual environment.
pip install -r requirements.txt
pip install -r requirements-dev.txt
requirements.txt
includes psycopg2
which may have trouble installing. You may run the below to address this.
pip install psycopg2-binary
Copy the .env.example
file to .env
and fill in the environment variables.
See .env.example
for a list of environment variables and explanations.
You will need a few API keys and secrets. See the section on external Services for more details.
Make sure you are in the virtual environment!
For development, we are using a local sqlite3
database. Hence, no need to configure any server or connection string.
You only need to initialize the database once.
flask resetdb
flask run
Open localhost:5000. You should be able to see the app running locally.
Try clicking into a course offering and create an exam.
Use this demo Google Sheet to import rooms and students, and trying out assigning seatings.
To use the full functionality of the app, you will need to set up the following external services.
This section covers the bare minimum that is needed for functionality of the app.
This is for user authentication and data fetching of courses, students, etc.
Contact School LTI team to register your app and client ID and secret.
This is for Google Sheets API to bulk import rooms and students
Setup a GCP Project and create a service account with the role Project Editor
.
There are two ways to provide service account credentials to the app. In any case you will need to download the service account key as a JSON file from GCP Dashboard first, and set GCP_SA_CRED_TYPE
to either file
or env
.
- Use credentials file
- Download the service account key as a JSON file from GCP Dashboard and save it to root directory of the repo as
gcp-service-account-credentials.json
. - Set the environment variable
GCP_SA_CRED_TYPE
tofile
. - Set the environment variable
GCP_SA_CRED_FILE
togcp-service-account-credentials.json
. - You could of course use a different file path, but make sure you set the environment variable accordingly and never commit the file to version control. The default name of
gcp-service-account-credentials.json
is already in.gitignore
.
- Download the service account key as a JSON file from GCP Dashboard and save it to root directory of the repo as
- Use environment variables
- Sometimes, using a credentials file is not convenient (on GitHub Action/Heroku for example). You can also encode the content of the downloaded JSON file into a base64 string and supply it via an environment variable.
- Download the service account key as a JSON file from GCP Dashboard.
- Encode the content of the JSON file into a base64 string.
base64 -w 0 path/to/your/service-account-file.json
- Set the environment variable
GCP_SA_CRED_TYPE
toenv
. - Set the environment variable
GCP_SA_CRED_VALUE
to the base64 string you just obtained.
Right now, on GitHub, GCP service account credential uses my personal account (which, should not be the case). If I graduate or if it expires you should get a new one. We should consider shifting to department service account at some point in the future.
This is for sending emails to students about their seat assignments.
We have not yet decided on a SMTP server to use. For now, you can use your own Gmail account SMTP server.
Right now, on GitHub, it is using my own personal Gmail account (which, should not be the case). If I graduate or if it expires you should get a new one. We should consider shifting to department service account at some point in the future.
The following are related not to functionality but to devops aspects.
We use heroku for staging environment. You can use any staging environment. This integration is not instusive and you do not need to remove anything from the repo if you move away from Heroku.
Right now, we have a Heroku staging environment which uses my personal account (which, should not be the case). If I graduate or if it expires you should get a new one. We should consider shifting to department service account at some point in the future.
We integrated Codecov for testing coverage report in Github CI. We have already set up the relevant workflow step and put in the Github Repository secret CODECOV_TOKEN
, using my personal account (which, should not be the case). If the token expires or if I graduate, make sure to get a new CodeCov account and get a new token. We should consider shifting to department service account at some point in the future.
We integrated Sentry for server monitoring. We have already integrated it and the only relevant piece of codes are in the root __init__.py
. If that dsn expires of if I graduate, make sure to get a new account and new token. We should consider shifting to department service account at some point in the future. We should also apply to Open Source credential for Sentry.
# intialize database
flask initdb
# drop database
flask dropdb
# seed database
flask seeddb
# reset database (drop, init, seed)
flask resetdb
# run linting check
flask lint
# run unit tests
flask unit
# run e2e tests
flask e2e
# run a11y tests
flask a11y
# run all tests (unit, e2e, a11y)
flask test
# run security audit
flask audit
This repo is equipped with some typical testing scaffoldings you might expect to find in a full-stack application:
- Test runner:
pytest
- Coverage:
pytest-cov
, which usescoverage.py
under the hood - HTTP request stubbing:
responses
- Seeding database from fixture files:
flask-fixtures
- Webdriver for UI/e2e tests:
selenium
There are a few other aspects worth noting:
- Canvas OAuth
We did not use responses
library to stub out Auth API Call. Instead, when MOCK_CANVAS
env var is set to True
, our app would connect to a fake local OAuth2 server instead of the actual Canvas OAuth2 server. It still completes the entire OAuth2 flow but draws user information from server/services/canvas/fake_data/fake_users.json
.
- Canvas API
We did not use responses
library to stub out Canvas API as we are using the canvasapi
library instead of calling HTTP endpoints directly. What we did is to use a fake CanvasClient
when MOCK_CANVAS
env var is set to True
, which draws information from server/services/canvas/fake_data
.
We provide three ways to test the email feature. For details see here.
We are using GitHub Action for CI and Heroku for staging environment.
At some point we should deploy this app properly, following department guidelines.