diff --git a/module_build_service/config.py b/module_build_service/config.py index 3176eab8..dc7be4d9 100644 --- a/module_build_service/config.py +++ b/module_build_service/config.py @@ -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 diff --git a/test-requirements.txt b/test-requirements.txt index 3037df67..31d20101 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,4 +1,5 @@ copr mock nose +pytest vcrpy diff --git a/tests/test_views/test_views.py b/tests/test_views/test_views.py index d6f0ec1a..b09e0cf8 100644 --- a/tests/test_views/test_views.py +++ b/tests/test_views/test_views.py @@ -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) diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..e6b6fb78 --- /dev/null +++ b/tox.ini @@ -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}