Skip to content

Commit

Permalink
Merge f36ef1f into 0bdb234
Browse files Browse the repository at this point in the history
  • Loading branch information
devkral committed Jan 14, 2020
2 parents 0bdb234 + f36ef1f commit bdadc78
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 37 deletions.
22 changes: 14 additions & 8 deletions .travis.yml
Expand Up @@ -10,12 +10,11 @@ python:
- "pypy3"
- "nightly"


services:
- mysql
- postgresql
- mongodb
addons:
postgresql: "10"

env:
matrix:
Expand Down Expand Up @@ -48,18 +47,25 @@ matrix:
install: pip install tox
script: tox -e $TOX_ENV
- python: "3.7"
env: ENV=functional
env: TOX_ENV=functional
install:
- pip install tox
- export PYTHON='coverage run -a'
before_install:
- mysql -e 'CREATE DATABASE test;'
- psql -c 'CREATE DATABASE test;' -U postgres
script:
- DATABASE_URL=sqlite:////tmp/db.sqlite tox -e functional
- DATABASE_URL=mysql://travis:@localhost/test tox -e functional
- DATABASE_URL=postgres://postgres:@localhost/test tox -e functional
- CONNECTOR=dbbackup.db.postgresql.PgDumpBinaryConnector DATABASE_URL=postgres://postgres:@localhost/test tox -e functional
- tox -e $TOX_ENV
- DB_ENGINE=django.db.backends.mysql DB_USER=travis DB_HOST=localhost DB_NAME=test tox -e $TOX_ENV
- DB_ENGINE=django.db.backends.postgresql DB_USER=postgres DB_HOST=localhost DB_NAME=test tox -e $TOX_ENV
- CONNECTOR=dbbackup.db.postgresql.PgDumpBinaryConnector DB_ENGINE=django.db.backends.postgresql DB_USER=postgres DB_HOST=localhost DB_NAME=test tox -e $TOX_ENV
- python: "3.7"
env: TOX_ENV=functional-mongodb
install:
- pip install tox
- export PYTHON='coverage run -a'
script:
- DB_ENGINE=djongo DB_NAME=test tox -e $TOX_ENV
exclude:
- python: "nightly"
env: DJANGO=1.11
Expand All @@ -80,6 +86,6 @@ matrix:
- python: "3.5"
env: DJANGO=master
allow_failures:
- python: "pypy3"
- python: "nightly"
- env: DJANGO=master
- env: TOX_ENV=functional-mongodb
3 changes: 2 additions & 1 deletion dbbackup/db/base.py
Expand Up @@ -16,7 +16,8 @@
'django.db.backends.postgresql': 'dbbackup.db.postgresql.PgDumpConnector',
'django.db.backends.postgresql_psycopg2': 'dbbackup.db.postgresql.PgDumpConnector',
'django.db.backends.oracle': None,
'django_mongodb_engine': 'dbbackup.db.mongo.MongoDumpConnector',
'django_mongodb_engine': 'dbbackup.db.mongodb.MongoDumpConnector',
'djongo': 'dbbackup.db.mongodb.MongoDumpConnector',
'django.contrib.gis.db.backends.postgis': 'dbbackup.db.postgresql.PgDumpGisConnector',
'django.contrib.gis.db.backends.mysql': 'dbbackup.db.mysql.MysqlDumpConnector',
'django.contrib.gis.db.backends.oracle': None,
Expand Down
1 change: 1 addition & 0 deletions dbbackup/tests/commands/test_dbrestore.py
Expand Up @@ -112,6 +112,7 @@ def test_no_given_db_multidb(self):


@patch('dbbackup.management.commands._base.input', return_value='y')
@patch('dbbackup.management.commands.dbrestore.get_connector', return_value=MongoDumpConnector())
@patch('dbbackup.db.mongodb.MongoDumpConnector.restore_dump')
class DbMongoRestoreCommandRestoreBackupTest(TestCase):
def setUp(self):
Expand Down
11 changes: 7 additions & 4 deletions dbbackup/tests/settings.py
Expand Up @@ -3,7 +3,6 @@
"""
import os
import tempfile
import dj_database_url

DEBUG = False

Expand All @@ -25,9 +24,13 @@
'dbbackup.tests.testapp',
)

DATABASE = dj_database_url.config(default='sqlite:///%s' %
tempfile.mktemp())
DATABASES = {'default': DATABASE}
DATABASES = {'default': {
"ENGINE": os.environ.get('DB_ENGINE', "django.db.backends.sqlite3"),
"NAME": os.environ.get('DB_NAME', ":memory:"),
"USER": os.environ.get('DB_USER'),
"PASSWORD": os.environ.get('DB_PASSWORD'),
"HOST": os.environ.get('DB_HOST'),
}}
if os.environ.get('CONNECTOR'):
CONNECTOR = {'CONNECTOR': os.environ['CONNECTOR']}
DBBACKUP_CONNECTORS = {'default': CONNECTOR}
Expand Down
13 changes: 6 additions & 7 deletions docs/conf.py
Expand Up @@ -45,13 +45,12 @@
project = u'django-dbbackup'
copyright = u'2016, Michael Shepanski'

path = os.path.join(
os.path.split(
os.path.abspath(
os.path.dirname(__file__)
)
)[:-1]
)[0]
# basepath
path = os.path.dirname(
os.path.dirname(
os.path.abspath(__file__)
)
)

sys.path = [path] + sys.path
sys.path = [os.path.join(path, 'dbbackup')] + sys.path
Expand Down
25 changes: 21 additions & 4 deletions docs/contributing.rst
Expand Up @@ -84,12 +84,29 @@ DBBackup contains a test Django project at ``dbbackup.tests`` and its
``settings`` module. This configuration takes care of the following
environment variables:

**DATABASE_URL** - Default: ``'sqlite:///%s' % tempfile.mktemp()``
**DB_ENGINE** - Default: ``django.db.backends.sqlite3``

A URL representing the used database, see `DJ-Database-URL`_ for all the
available format.
Databank-Engine to use. See in django.db.backends for default backends.

**DB_NAME** - Default: ``:memory:``

Database name. Should be set correctly if an other db is used than sqlite3

**DB_USER** - Default: ``None``

DB Username

**DB_PASSWORD** - Default: ``None``

DB Password

**DB_HOST** - Default: ``None``

DB Host

Why is this more complicated than the earlier solution?
For mongodb tests dj-database-url had no ENGINE defined.

.. _`DJ-Database-URL`: https://github.com/kennethreitz/dj-database-url

**MEDIA_ROOT** - Default= ``tempfile.mkdtemp()``

Expand Down
15 changes: 9 additions & 6 deletions functional.sh
Expand Up @@ -46,25 +46,28 @@ test_media_results () {


main () {
if [[ -z "$DATABASE_URL" ]]; then
DATABASE_FILE="$(mktemp)"
export DATABASE_URL="sqlite:///$DATABASE_FILE"
if [[ -z "$DB_ENGINE" ]] || [[ "$DB_ENGINE" = "django.db.backends.sqlite3" ]]; then
if [[ -z "$DB_NAME" ]]; then
export DB_NAME="$(mktemp)"
fi
fi
export PYTHON=${PYTHON:-python}
export STORAGE="${STORAGE:-django.core.files.storage.FileSystemStorage}"
export STORAGE_LOCATION="/tmp/backups/"
export STORAGE_OPTIONS="${STORAGE_OPTIONS:-location=$STORAGE_LOCATION}"
export MEDIA_ROOT="/tmp/media/"

make_db_test
make_db_test
test_db_results

mkdir -p $STORAGE_LOCATION
mkdir -p $MEDIA_ROOT
make_media_test
make_media_test
test_media_results

[[ -n "$DATABASE_FILE" ]] && rm "$DATABASE_FILE"
if [[ -z "$DB_ENGINE" ]] || [[ "$DB_ENGINE" = "django.db.backends.sqlite3" ]]; then
rm "$DB_NAME"
fi
rm -rf "$MEDIA_ROOT"

return $((db_success + media_success))
Expand Down
6 changes: 2 additions & 4 deletions requirements-docs.txt
@@ -1,5 +1,3 @@
docutils<0.13.1
Sphinx==1.3.1
docutils<0.13.1 # https://github.com/sphinx-doc/sphinx/issues/3212
Sphinx
docutils
sphinx-django-command
dj-database-url
5 changes: 2 additions & 3 deletions requirements-tests.txt
@@ -1,10 +1,9 @@
pep8
flake8
pylint
mock
coverage<5
coverage
python-gnupg
django-storages
pytz
dj-database-url
testfixtures
mock
12 changes: 12 additions & 0 deletions tox.ini
Expand Up @@ -3,6 +3,8 @@ envlist = py{2.7,3.5,3.6,3.7,pypy}-django1.11,py{3.5,3.6,3.7,3.8,nightly}-django

[testenv]
passenv = *
setenv =
PYTHONDONTWRITEBYTECODE=1
basepython =
py2.7: python2.7
py3.5: python3.5
Expand Down Expand Up @@ -33,12 +35,22 @@ deps = -rrequirements-docs.txt
commands = make docs

[testenv:functional]
basepython = python
passenv = *
whitelist_externals = bash
deps =
-rrequirements-tests.txt
Django
mysqlclient
psycopg2
commands = {posargs:bash -x functional.sh}


[testenv:functional-mongodb]
basepython = python
passenv = *
whitelist_externals = bash
deps =
-rrequirements-tests.txt
djongo
commands = {posargs:bash -x functional.sh}

0 comments on commit bdadc78

Please sign in to comment.