diff --git a/tests/conftest.py b/tests/conftest.py index 6a895fe..e2aabbc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -18,29 +18,36 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +"""Configuration and fixtures for tests files.""" + import pytest + from httmock import urlmatch, HTTMock, response import django_webtest from django.core.cache import cache + @pytest.fixture(autouse=True) def media(settings, tmpdir): + """Set the media root to a temp dir created.""" settings.MEDIA_ROOT = str(tmpdir.mkdir('media')) @pytest.fixture def app(request): + """Return a Django WebTest application.""" wtm = django_webtest.WebTestMixin() - wtm._patch_settings() - request.addfinalizer(wtm._unpatch_settings) + wtm._patch_settings() # pylint: disable=protected-access + request.addfinalizer(wtm._unpatch_settings) # pylint: disable=protected-access cache.clear() return django_webtest.DjangoTestApp() @pytest.fixture def endpoint_dummy_cache(monkeypatch): + """Monkey patch the Django cache to a 'dummy' one for all passerelle views.""" from django.core.cache import caches import passerelle.views monkeypatch.setattr( @@ -48,12 +55,14 @@ def endpoint_dummy_cache(monkeypatch): @urlmatch() -def internal_server_error(url, request): +def internal_server_error(url, request): # pylint: disable=unused-argument + """Return an HTTP 500 error.""" return response(500, 'Internal server error') @pytest.fixture def mock_500(): + """Mock an Internal Server Error.""" with HTTMock(internal_server_error): yield None @@ -65,8 +74,8 @@ def relax_openssl(tmpdir): import os openssl_cnf_path = tmpdir / 'openssl.cnf' - with openssl_cnf_path.open('w') as fd: - fd.write(u''' + with openssl_cnf_path.open('w') as file_pt: + file_pt.write(u''' [default_conf] ssl_conf = ssl_sect @@ -84,4 +93,3 @@ CipherString = ALL''') del os.environ['OPENSSL_CONF'] else: os.environ['OPENSSL_CONF'] = old_value - diff --git a/tests/settings.py b/tests/settings.py index f9e5efc..157ecc7 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -18,13 +18,15 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +"""Settings for testing.""" + import os LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' # include app -INSTALLED_APPS += ( +INSTALLED_APPS += ( # pylint: disable=undefined-variable 'atreal_openads', )