Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allocation tests #432

Merged
merged 7 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,26 @@ A specific test of an app can also be executed - `python manage.py test sharing_

Or a specific test case can also be executed - `python manage.py test sharing_portal.tests.test_git_parser`

Todo: Currently, running test cases that require a DB connection does not work. This needs to be fixed


#### Writing tests that require a DB connection

Currently, automatic setup and teardown of the test DB is not supported. To run tests that require a DB connection, we are required to manually manage

To guarantee the idempotence of DB tests, any tests that save records to the DB should delete the records gracefully upon finishing execution to avoid spillover into the results of the next tests.

#### Deploying tests that require a DB connection

Upon running test cases, Django tries to create a test DB with an identical schema to the production DB; Django however encounters migrations issues and fails the creation. To circumvent this issue, we manually create and mantain the test DB as follows:
- Create a dump of the production dev DB by running the following command in the DB deployment container:
- `mysqldump -u chameleon_dev -p*specifypasswordhere* PROD_DB_NAME > PROD_DB_NAME_TODAYSDATETIME.sql`
- Create a new test DB by appending "_test" to the prod DB name and load the prod DB dump onto the newly created test DB:
- `mysql --user chameleon_dev -p*specifypasswordhere* CREATE DATABASE *PROD_DB_NAME*_test`
- `mysqldump -u chameleon_dev -p*specifypasswordhere* TEST_DB_NAME < PROD_DB_NAME_TODAYSDATETIME.sql`
- Ensure all migrations run properly on the test DB using:
- `./manage.py migrate --database TEST_DB_NAME`
- **(Important)** Run **ALL** db tests tests with the --keepdb flag as follows to prevent Django's auto setup and teardown of the test DB:
- `sudo docker exec portal ./manage.py test allocations.tests --keepdb`

## Deployment

Expand Down
Loading
Loading