-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial tests, coverage and code-quality configuration
- Loading branch information
Showing
8 changed files
with
142 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[run] | ||
omit = | ||
tests/* | ||
[report] | ||
fail_under = 100 | ||
show_missing = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
sudo: false | ||
language: python | ||
python: | ||
- "2.6" | ||
- "2.7" | ||
- "3.3" | ||
- "3.4" | ||
- "3.5" | ||
install: pip install tox-travis | ||
script: tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include .coveragerc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
CREATE TABLE friend( | ||
id SERIAL NOT NULL PRIMARY KEY, | ||
name VARCHAR(100) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
alter table friend add column gender VARCHAR(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import psycopg2 | ||
import pytest | ||
import sys | ||
from schema_migrations import MigrationController, STATUS_OK, STATUS_PENDING | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def databases(request): | ||
db_base = 'schema_migrations_{0}{1}{2}'.format(*sys.version_info) | ||
database_names = [ | ||
'{0}_{1}'.format(db_base, i) for i in range(3) | ||
] | ||
def create(): | ||
conn = psycopg2.connect( | ||
user='postgres' | ||
) | ||
conn.set_isolation_level(0) | ||
cur = conn.cursor() | ||
for db in database_names: | ||
cur.execute('CREATE DATABASE {name}'.format(name=db)) | ||
conn.close() | ||
|
||
def drop(): | ||
conn = psycopg2.connect( | ||
user='postgres' | ||
) | ||
conn.set_isolation_level(0) | ||
cur = conn.cursor() | ||
for db in database_names: | ||
cur.execute('DROP DATABASE IF EXISTS {name}'.format(name=db)) | ||
conn.close() | ||
|
||
drop() | ||
create() | ||
|
||
request.addfinalizer(drop) | ||
|
||
return { | ||
name:'postgresql://postgres@localhost:5432/{name}'.format(name=name) | ||
for name in database_names | ||
} | ||
|
||
|
||
class TestSchemaMigrations: | ||
def test_migrations(self, databases): | ||
groups = dict( | ||
test='./tests/migrations/' | ||
) | ||
mc = MigrationController(databases=databases, groups=groups) | ||
|
||
migrations = mc.list()['test'] # test group | ||
assert len(migrations) == 2 | ||
for m in migrations: | ||
assert m['status']['all'] == STATUS_PENDING | ||
dbs = m['status']['databases'] | ||
assert len(dbs.keys()) == 3 | ||
|
||
for db_status in dbs.values(): | ||
assert db_status == False | ||
|
||
mc.migrate() | ||
mc.close() | ||
|
||
mc2 = MigrationController(databases=databases, groups=groups) | ||
|
||
migrations = mc2.list()['test'] # test group | ||
assert len(migrations) == 2 | ||
for m in migrations: | ||
assert m['status']['all'] == STATUS_OK | ||
dbs = m['status']['databases'] | ||
assert len(dbs.keys()) == 3 | ||
|
||
for db_status in dbs.values(): | ||
assert db_status == True | ||
|
||
mc2.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[tox] | ||
envlist = py27, py33, py34, py35, flake8, isort | ||
[testenv] | ||
deps= | ||
pytest | ||
commands=py.test | ||
[testenv:py35] | ||
deps= | ||
pytest | ||
coverage | ||
pytest-cov | ||
commands=py.test --cov {envsitepackagesdir}/schema_migrations --cov-config .coveragerc | ||
[testenv:flake8] | ||
deps = | ||
flake8 | ||
mccabe | ||
commands = flake8 --max-complexity 10 schema_migrations | ||
[testenv:isort] | ||
basepython = python2.7 | ||
deps = isort | ||
commands = isort -rc -c schema_migrations | ||
[tox:travis] | ||
2.7 = py27 | ||
3.3 = py33 | ||
3.4 = py34 | ||
3.5 = py35, flake8, isort |