Skip to content
This repository was archived by the owner on Mar 13, 2020. It is now read-only.

Commit 574c186

Browse files
ChintanRavalseanbudd
authored andcommitted
Run tests using a restricted test user instead of admin (#26)
1 parent 2a6f430 commit 574c186

File tree

7 files changed

+30
-43
lines changed

7 files changed

+30
-43
lines changed

.travis.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ language: python
33
python: 3.7
44
env:
55
- PIPENV_VERBOSITY=-1
6-
7-
services: docker
6+
services: postgresql
87
before_install:
9-
- docker pull postgres
10-
- docker run -p 5432:5432 -e POSTGRES_PASSWORD=travisci -d postgres
11-
8+
- psql -d postgres -U postgres -c "SELECT version() as PostgreSQL_VERSION;"
9+
- psql -d postgres -U postgres -a -v ON_ERROR_STOP=1 -f ./tests/integration/setup-part1.sql
10+
- psql -d integration_test_db -U postgres -a -v ON_ERROR_STOP=1 -f ./tests/integration/setup-part2.sql
1211
install: make install_deps
1312
script:
1413
- make test_unit

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
install_deps:
33
pip install pipenv --upgrade
44
pipenv install --dev
5-
alembic -c dpo/alembic.ini -x postgresql+psycopg2://postgres:travisci@localhost:5432/postgres upgrade head
5+
alembic -c dpo/alembic.ini -x postgresql+psycopg2://integration_test_user:integration_test_password@localhost:5432/integration_test_db upgrade head
66

77
# Run unit tests
88
test_unit:
@@ -13,4 +13,4 @@ test_integration:
1313
./tests/integration/test_integration.sh
1414

1515
test_downgrade_schema:
16-
alembic -c dpo/alembic.ini -x postgresql+psycopg2://postgres:travisci@localhost:5432/postgres downgrade base
16+
alembic -c dpo/alembic.ini -x postgresql+psycopg2://integration_test_user:integration_test_password@localhost:5432/integration_test_db downgrade base

README.md

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ Once the virtual environment has been activated, please refer to [usage](#Usage)
9898

9999
## Testing
100100

101-
To run integration tests locally, it is highly recommended that [Docker](https://www.docker.com/) is installed.
102-
103101
### Unit Tests
104102

105103
To run unit tests, run the following command:
@@ -110,37 +108,18 @@ $ pytest
110108

111109
### Integration Tests
112110

113-
Before running integration tests, please ensure the following information is configured correctly:
114-
115-
- `tests/integration/test_integration.sh:8`
116-
117-
Please ensure that the database connection string points to a valid PostgreSQL instance with valid parameters.
118-
119-
To run integration tests, run the following command:
120-
121-
```
122-
$ ./tests/integration/test_integration.sh
123-
```
124-
125-
#### Docker
126-
127-
If Docker is installed, running tests is as simple as running the following commands:
128-
129-
```
130-
$ docker pull postgres
131-
$ docker run --name stubdatabase -p 5432:5432 -e POSTGRES_PASSWORD=travisci -d postgres
132-
$ make test_integration
133-
$ docker stop stubdatabase
134-
$ docker remove stubdatabase
135-
```
136-
137-
#### Local PostgreSQL
138-
139-
If a local instance of PostgreSQL is installed, run integration tests with the following command:
140-
141-
```
142-
$ make test_integration
143-
```
111+
- Install PostgreSQL 9.6+
112+
- Execute below scripts to setup test db and user
113+
```
114+
./tests/integration/setup-part1.sql
115+
./tests/integration/setup-part2.sql
116+
alembic -c dpo/alembic.ini -x postgresql+psycopg2://integration_test_user:integration_test_password@localhost:5432/integration_test_db upgrade head
117+
```
118+
- To run integration tests, run either of the following commands:
119+
```
120+
$ make test_integration
121+
$ ./tests/integration/test_integration.sh
122+
```
144123

145124
#### Notes
146125

dpo/alembic/versions/c5c34dd0b8f2_refactor_schema_to_support_steps_and_.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def upgrade():
7979
id, created_on, last_updated_on, status, created_on, last_updated_on, execution_time_ms
8080
FROM dpo.fe9eed6d812f_execution
8181
''')
82-
op.execute('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";')
8382
op.execute(
8483
'''
8584
INSERT INTO dpo.execution_step (
@@ -165,7 +164,6 @@ def downgrade():
165164
execution_id, created_on, updated_on, status, execution_time_ms
166165
FROM dpo.c5c34dd0b8f2_execution
167166
''')
168-
op.execute('DROP EXTENSION IF EXISTS "uuid-ossp";')
169167
op.execute(
170168
'''
171169
INSERT INTO dpo.execution_model (

tests/integration/setup-part1.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- create db
2+
CREATE DATABASE integration_test_db;

tests/integration/setup-part2.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- create extensions
2+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
3+
4+
-- create user
5+
CREATE USER integration_test_user WITH ENCRYPTED PASSWORD 'integration_test_password';
6+
7+
-- setup user
8+
GRANT CONNECT ON DATABASE integration_test_db TO integration_test_user;
9+
GRANT CREATE ON DATABASE integration_test_db TO integration_test_user;

tests/integration/test_integration.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -e
55

66
# Bootstrap
77
dpo="pipenv run python -m dpo"
8-
dpo_conn_str="postgresql+psycopg2://postgres:travisci@localhost:5432/postgres"
8+
dpo_conn_str="postgresql+psycopg2://integration_test_user:integration_test_password@localhost:5432/integration_test_db"
99
modelDirectory="./tests/integration/models"
1010
loadModelDirectory="$modelDirectory/load"
1111
transformModelDirectory="$modelDirectory/transform"

0 commit comments

Comments
 (0)