Skip to content

Commit

Permalink
Merge pull request #101 from paulocheque/postgres
Browse files Browse the repository at this point in the history
Running tests on Postgres too
  • Loading branch information
paulocheque committed Jan 3, 2020
2 parents 4d60cd5 + d4c0216 commit 8b46382
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 39 deletions.
31 changes: 26 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,32 @@ matrix:
include:
# https://docs.djangoproject.com/en/1.11/ref/contrib/gis/install/
- python: 2.7
env: DJANGO=1.11
env:
- DJANGO=1.11
- python: 2.7
env:
- DJANGO=1.11
- DATABASE=_postgres
# https://docs.djangoproject.com/en/2.2/ref/contrib/gis/install/
- python: 3.6
env: DJANGO=2.2
env:
- DJANGO=2.2
- python: 3.6
env:
- DJANGO=2.2
- DATABASE=_postgres
# https://docs.djangoproject.com/en/3.0/ref/contrib/gis/install/
# https://docs.djangoproject.com/en/3.0/releases/3.0/#id2
- python: 3.7
env: DJANGO=3.0
env:
- DJANGO=3.0
- python: 3.8
env:
- DJANGO=3.0
- python: 3.8
env: DJANGO=3.0
env:
- DJANGO=3.0
- DATABASE=_postgres

before_script:
- export DJANGO_SETTINGS_MODULE=settings
Expand All @@ -42,14 +58,19 @@ before_script:
# postgis django backend requires these to exist
- psql -U postgres -c "create database cacheops"
- psql -U postgres -c "create database cacheops_slave"
# create db and user
- psql -c "CREATE DATABASE ddf;" -U postgres
- psql -c "CREATE USER ddf_user WITH PASSWORD 'ddf_pass';" -U postgres
- psql -c "ALTER USER ddf_user CREATEDB;" -U postgres
- psql -c "ALTER USER ddf_user WITH SUPERUSER;" -U postgres

install:
- pip install -r requirements.txt
- pip install psycopg2 pytest pytest-django coveralls
- pip install Django~=${DJANGO}.0

script:
- pytest --reuse-db --migrations --create-db
- pytest --create-db --reuse-db --no-migrations --ds=settings${DATABASE}

after_success:
- coveralls
23 changes: 21 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,31 @@ compile:
env/bin/python -OO -m compileall .

test:
clear ; env/bin/pytest --reuse-db --no-migrations
clear ; env/bin/pytest --create-db --reuse-db --no-migrations
# clear ; time env/bin/tox --parallel all -e django111-py27
# clear ; time env/bin/tox --parallel all -e django20-py37

config_postgres:
psql -U postgres -c "create extension postgis"
# set up postgresql
psql -U postgres -c "create role cacheops login superuser"
# postgis django backend requires these to exist
psql -U postgres -c "create database cacheops"
psql -U postgres -c "create database cacheops_slave"
# create db and user
psql -c "CREATE DATABASE ddf;" -U postgres
psql -c "CREATE USER ddf_user WITH PASSWORD 'ddf_pass';" -U postgres
psql -c "ALTER USER ddf_user CREATEDB;" -U postgres
psql -c "ALTER USER ddf_user WITH SUPERUSER;" -U postgres

test_postgres:
clear ; env/bin/pytest --reuse-db --no-migrations --ds=settings_postgres

test_mysql:
clear ; env/bin/pytest --reuse-db --no-migrations --ds=settings_mysql

cov:
clear ; env/bin/pytest --no-migrations --reuse-db --cov=django_dynamic_fixture
clear ; env/bin/pytest --create-db --reuse-db --no-migrations --cov=django_dynamic_fixture

coveralls:
clear ; env/bin/coveralls
Expand Down
3 changes: 1 addition & 2 deletions django_dynamic_fixture/tests/test_ddf.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,7 @@ def test_BadDataError(self):
self.fail()
except BadDataError as e:
assert 'IntegrityError' in str(e), str(e)
assert 'NULL' in str(e), str(e)

assert 'NULL' in str(e).upper(), str(e)

def test_InvalidConfigurationError(self):
try:
Expand Down
29 changes: 0 additions & 29 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,6 @@

DDF_TEST_GEODJANGO = False

# Postgres and PostGis
# > psql -d ddf -c "CREATE EXTENSION postgis;"
# > psql -d ddf -c "select postgis_lib_version();"
# DATABASES = {
# 'default': {
# # Postgis supports all Django features
# # createdb ddf
# 'ENGINE': 'django.contrib.gis.db.backends.postgis',
# 'NAME': 'ddf',
# 'USER': 'paulocheque', # please, change this if you want to run tests in your machine
# 'PASSWORD': '',
# 'HOST': 'localhost',
# 'PORT': 5432,
# }
# }

# MySQL
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.mysql',
# 'NAME': 'ddf',
# 'USER': 'paulocheque', # please, change this if you want to run tests in your machine
# 'PASSWORD': '',
# 'HOST': 'localhost',
# 'PORT': 3306,
# }
# }


# SQlite and SpatialLite
# brew install spatialite-tools
# brew install gdal
Expand Down
15 changes: 15 additions & 0 deletions settings_mysql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from settings import *

DDF_TEST_GEODJANGO = True

# MySQL
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ddf',
'USER': 'paulocheque', # please, change this if you want to run tests in your machine
'PASSWORD': '',
'HOST': 'localhost',
'PORT': 3306,
}
}
19 changes: 19 additions & 0 deletions settings_postgres.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from settings import *

DDF_TEST_GEODJANGO = True

# Postgres and PostGis
# > psql -d ddf -c "CREATE EXTENSION postgis;"
# > psql -d ddf -c "select postgis_lib_version();"
DATABASES = {
'default': {
# Postgis supports all Django features
# createdb ddf
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'ddf',
'USER': 'ddf_user', # please, change this if you want to run tests in your machine
'PASSWORD': 'ddf_pass',
'HOST': 'localhost',
'PORT': 5432,
}
}
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ deps =
django20: django>=2.0,<2.1
django30: django>=3.0,<3.1

commands = env/bin/pytest -n 3 --reuse-db --no-migrations
commands = env/bin/pytest -n 3 --create-db --reuse-db --no-migrations

0 comments on commit 8b46382

Please sign in to comment.