Skip to content

Commit

Permalink
improve testing developer ux
Browse files Browse the repository at this point in the history
- Setup a docker-compose file
- Use same DB settings for development & CI
- Add development notes in readme
  • Loading branch information
rsyring committed Oct 7, 2021
1 parent 1282bcd commit b687c72
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ jobs:
build:
docker:
- image: level12/python-test-multi
- image: postgres:9.6
- image: postgres:12
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: kegauth_tests
POSTGRES_HOST_AUTH_METHOD: trust
steps:
- checkout

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ tags
.pytest_cache
dist/
build/
.env
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ include .circleci/config.yml
include .circleci/pytest.ini
exclude keg_auth_ta-config.py coverage.xml .coverage
exclude pyp.ini
include docker-compose.yml
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.1'

services:
keg-auth-pg:
image: postgres:12-alpine
container_name: keg-auth-pg
environment:
POSTGRES_DB: kegauth_tests
POSTGRES_HOST_AUTH_METHOD: trust
ports:
# Can use a .env to customize, but that will only work when running docker-compose in the
# same directory as this file. You can also use an override file if desired.
- '${KEG_AUTH_DB_IP:-127.0.0.1}:${KEG_AUTH_DB_PORT:-5432}:5432'
5 changes: 3 additions & 2 deletions keg_auth_ta-config-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@


class DevProfile(object):
SQLALCHEMY_DATABASE_URI = 'postgresql://postgres:@localhost:5432/keg_auth_ta'
MAIL_DEFAULT_SENDER = ''
SERVER_NAME = 'localhost:5000'
# SQLALCHEMY_DATABASE_URI = 'postgresql://postgres@localhost/postgres'


class TestProfile(object):
SQLALCHEMY_DATABASE_URI = 'postgresql://postgres:@localhost:5432/__tests__'
# SQLALCHEMY_DATABASE_URI = 'postgresql://postgres@localhost/kegauth_tests'
pass
8 changes: 4 additions & 4 deletions keg_auth_ta/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class DefaultProfile(object):

# These three just get rid of warnings on the console.
KEG_KEYRING_ENABLE = False
SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:'
SQLALCHEMY_DATABASE_URI = 'postgresql://postgres@localhost/postgres'
SQLALCHEMY_TRACK_MODIFICATIONS = False

SITE_NAME = 'Keg Auth Demo'
Expand All @@ -22,9 +22,9 @@ class TestProfile(object):

MAIL_DEFAULT_SENDER = 'sender@example.com'

# These settings reflect what is needed in CI. For local development, use
# keg_auth_ta-config.py to override.
SQLALCHEMY_DATABASE_URI = 'postgresql://postgres:password@localhost/postgres'
# These settings reflect what is needed in CI & when using docker compose.
# Use keg_auth_ta-config.py to override if needed.
SQLALCHEMY_DATABASE_URI = 'postgresql://postgres@localhost/kegauth_tests'


class TestProfileUserArgs(config.TestProfile, TestProfile):
Expand Down
16 changes: 16 additions & 0 deletions readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,19 @@ Links
* Issue tracker: https://github.com/level12/keg-auth/issues
* Keg framework: https://github.com/level12/keg
* Questions & comments: http://groups.google.com/group/blazelibs


Development
-----------

To run this project's tests:

- Copy keg_auth_ta-config-example.py -> keg_auth_ta-config.py, update as needed
- Override database addr &/or port with environment vars or docker compose override if needed.
- `docker-compose up [-d]`
- `tox ...`

There is a test application defined that can be ran like:

- `cd keg_auth_ta`
- `python app.py ...`

0 comments on commit b687c72

Please sign in to comment.