Skip to content

Commit

Permalink
Add support for running tests with Postgres
Browse files Browse the repository at this point in the history
This adds support for setting the DATABASE_URL environment variable to run tests
with database engines other than sqlite3 locally. It also configures the CI
build to run the tests with Postgres.
  • Loading branch information
Dan Tao committed Jul 14, 2018
1 parent 1071c63 commit 1be78f4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
19 changes: 14 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@ python:
- "3.6"

matrix:
include:
- python: 3.6
env: TOXENV=i18n
include:
- python: 3.6
env: TOXENV=i18n

install:
- pip install tox tox-travis
- pip install tox tox-travis

services:
postgresql

before_script:
- psql -c 'create database waffle_test;' -U postgres

env:
- DATABASE_URL=postgres://postgres@localhost:5432/waffle_test

script:
- tox
- tox
11 changes: 11 additions & 0 deletions test_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys


# Make filepaths relative to settings.
Expand Down Expand Up @@ -28,6 +29,16 @@
}
}

if 'DATABASE_URL' in os.environ:
try:
import dj_database_url
import psycopg2
DATABASES['default'] = dj_database_url.config()
except ImportError:
print('Using the DATABASE_URL variable requires dj-database-url and '
'psycopg2. Try:\n\npip install -r travis.txt')
sys.exit(1)

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ deps =
django111: Django>=1.11,<2.0
django20: Django>=2.0,<2.1
-rtravis.txt
passenv = DATABASE_URL
commands =
./run.sh test

Expand Down
2 changes: 2 additions & 0 deletions travis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# versions.
mock==1.3.0
Jinja2>=2.7.1
dj-database-url==0.5.0
django-jinja>=2.1,<3
psycopg2>=2.7.5

transifex-client

0 comments on commit 1be78f4

Please sign in to comment.