introduce tox & pytest as well as other stuff (flake8, bandit and prepare for future automated build&release steps)

This commit is contained in:
Filip Valder
2017-03-30 12:52:07 +02:00
parent 7fb73da3b7
commit e6d80c0293
4 changed files with 63 additions and 9 deletions

View File

@@ -66,7 +66,7 @@ def init_config(app):
if 'MBS_CONFIG_SECTION' in app.request.environ:
config_section = app.request.environ['MBS_CONFIG_SECTION']
# TestConfiguration shall only be used for running tests, otherwise...
if any(['nosetests' in arg or 'noserunner.py' in arg for arg in sys.argv]):
if any(['nosetests' in arg or 'noserunner.py' in arg or 'py.test' in arg or 'pytest.py' in arg for arg in sys.argv]):
config_section = 'TestConfiguration'
from conf import config
config_module = config

View File

@@ -1,4 +1,5 @@
copr
mock
nose
pytest
vcrpy

View File

@@ -173,14 +173,15 @@ class TestViews(unittest.TestCase):
def test_pagination_metadata(self):
rv = self.client.get('/module-build-service/1/module-builds/?per_page=8&page=2')
meta_data = json.loads(rv.data)['meta']
self.assertTrue(
'module-build-service/1/module-builds/?per_page=8&page=1' in meta_data['prev'])
self.assertTrue(
'module-build-service/1/module-builds/?per_page=8&page=3' in meta_data['next'])
self.assertTrue(
'module-build-service/1/module-builds/?per_page=8&page=4' in meta_data['last'])
self.assertTrue(
'module-build-service/1/module-builds/?per_page=8&page=1' in meta_data['first'])
print meta_data
self.assertIn(
meta_data['prev'].split('?', 1)[1], ['per_page=8&page=1', 'page=1&per_page=8'])
self.assertIn(
meta_data['next'].split('?', 1)[1], ['per_page=8&page=3', 'page=3&per_page=8'])
self.assertIn(
meta_data['last'].split('?', 1)[1], ['per_page=8&page=4', 'page=4&per_page=8'])
self.assertIn(
meta_data['first'].split('?', 1)[1], ['per_page=8&page=1', 'page=1&per_page=8'])
self.assertEquals(meta_data['total'], 30)
self.assertEquals(meta_data['per_page'], 8)
self.assertEquals(meta_data['pages'], 4)

52
tox.ini Normal file
View File

@@ -0,0 +1,52 @@
# Tox (http://tox.testrun.org/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.
[tox]
envlist = py27, coverage, flake8, bandit
[testenv]
sitepackages = True
install_command = pip install --force-reinstall --ignore-installed {packages}
deps = pytest
commands = py.test
[testenv:coverage]
basepython = python2
deps =
{[testenv]deps}
coverage
commands =
coverage run --parallel-mode -m pytest
coverage combine
coverage report --omit=.tox/* -m --skip-covered
[testenv:flake8]
basepython = python2
skip_install = true
deps = flake8
commands = flake8 --ignore E501,E731 --exit-zero
[testenv:bandit]
basepython = python2
skip_install = true
deps = bandit
commands =
/bin/bash -c "bandit -r $(find . -mindepth 1 -maxdepth 1 ! -name tests ! -name \.\* -type d -o -name \*.py) || exit 0"
[testenv:build]
basepython = python2
skip_install = true
deps = setuptools
commands = python setup.py sdist
[testenv:release]
basepython = python2
skip_install = true
deps =
{[testenv:build]deps}
twine
commands =
{[testenv:build]commands}
twine upload --skip-existing dist/* {posargs}