Skip to content

Commit

Permalink
chore: Update README about tests
Browse files Browse the repository at this point in the history
- Add test database in scripts
- Modify travis conf to use test database
  • Loading branch information
iamareebjamal committed May 7, 2020
1 parent 8decac5 commit ac78523
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
8 changes: 6 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
DATABASE_URL=postgresql://open_event_user:opev_pass@127.0.0.1:5432/oevent
DATABASE_URL=postgresql://open_event_user:opev_pass@localhost:5432/oevent
INTEGRATE_SOCKETIO=false
TEST_DATABASE_URL=postgresql://open_event_user:[email protected]:5432/opev_test
TEST_DATABASE_URL=postgresql://open_event_user:opev_pass@localhost:5432/opev_test

# If using fast docker test DB, uncomment following line
# TEST_DATABASE_URL=postgresql://test:test@localhost:5433/test

APP_CONFIG=config.DevelopmentConfig

POSTGRES_USER=open_event_user
Expand Down
9 changes: 3 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ dist: bionic

services:
- docker
- postgresql

addons:
postgresql: "12"
Expand All @@ -13,7 +12,6 @@ addons:
- python3-dev
- libssl-dev
- libffi-dev
- postgresql-12-postgis-2.5

python: 3.7

Expand All @@ -26,15 +24,14 @@ env:
- APP_CONFIG="config.TestingConfig" SECRET_KEY="super secret key" PATH=$PATH:${HOME}/google-cloud-sdk/bin

before_script:
- psql -c 'create database test;' -U postgres
- export DATABASE_URL=postgresql://postgres@localhost:5432/test
- export TEST_DATABASE_URL=postgresql://postgres@localhost:5432/test
- ./scripts/test_db.sh
- export DATABASE_URL=postgresql://test:test@localhost:5433/test
- export TEST_DATABASE_URL=postgresql://test:test@localhost:5433/test
- bash scripts/test_multiple_heads.sh

script:
- pytest tests -v --cov=.


after_success:
- 'bash <(curl -s https://codecov.io/bash)'
- bash scripts/push_api_docs.sh
Expand Down
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,23 +224,21 @@ python manage.py module -n all -s off

#### Running unit tests

* Open Event uses Postgres database for testing. So set `DATABASE_URL` as a postgres database. Here is an example.
* If you have docker installed and want to run tests faster, run

```sh
export DATABASE_URL=postgresql://test_user:[email protected]:5432/opev_test
# format is postgresql://USERNAME:PASSWORD@ADDRESS/DATABASE_NAME
export APP_CONFIG=config.TestingConfig
```shell script
./scripts/test_db.sh
```

* Then go to the project directory and run the following command:
```
python3 -m unittest discover tests/
And set appropriate value of `TEST_DATABASE` in `.env`

```shell script
TEST_DATABASE_URL=postgresql://test:test@localhost:5433/test
```
* It will run each test one by one.

* You can also use the following command to run tests using nosetests:
* Then go to the project directory and run the following command:
```
nosetests tests/
pytest tests/
```

#### Running robot framework tests
Expand Down Expand Up @@ -283,7 +281,7 @@ We have the following branches :
* **development**
All development goes on in this branch. If you're making a contribution, please make a pull request to _development_.
All PRs must pass a build check and a unit-test check on Travis (https://open-event-api-dev.herokuapp.com - Is running off of the development branch. It is hosted on Heroku.)

* **master**
This contains shipped code. After significant features/bug-fixes are accumulated on development, we make a version update and make a release. (https://api.eventyay.com - Is running off of the `master` branch. Hosted on Google Cloud Platform (Google Container Engine + Kubernetes).)
* **gh-pages**
Expand Down
4 changes: 4 additions & 0 deletions scripts/test_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
docker run -d -e POSTGRES_PASSWORD=test -e POSTGRES_USER=test \
--mount type=tmpfs,destination=/var/lib/postgresql/data \
--rm -p 5433:5432 --name opev-test-db postgis/postgis:12-3.0-alpine

0 comments on commit ac78523

Please sign in to comment.