Refactoring: fix all of the 'pylint' complaints for tests files (conftests, settings)

This commit is contained in:
Michael Bideau 2019-08-22 15:13:27 +00:00
parent 05280c153e
commit 9df996e5ad
2 changed files with 17 additions and 7 deletions

View File

@ -18,29 +18,36 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Configuration and fixtures for tests files."""
import pytest import pytest
from httmock import urlmatch, HTTMock, response from httmock import urlmatch, HTTMock, response
import django_webtest import django_webtest
from django.core.cache import cache from django.core.cache import cache
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def media(settings, tmpdir): def media(settings, tmpdir):
"""Set the media root to a temp dir created."""
settings.MEDIA_ROOT = str(tmpdir.mkdir('media')) settings.MEDIA_ROOT = str(tmpdir.mkdir('media'))
@pytest.fixture @pytest.fixture
def app(request): def app(request):
"""Return a Django WebTest application."""
wtm = django_webtest.WebTestMixin() wtm = django_webtest.WebTestMixin()
wtm._patch_settings() wtm._patch_settings() # pylint: disable=protected-access
request.addfinalizer(wtm._unpatch_settings) request.addfinalizer(wtm._unpatch_settings) # pylint: disable=protected-access
cache.clear() cache.clear()
return django_webtest.DjangoTestApp() return django_webtest.DjangoTestApp()
@pytest.fixture @pytest.fixture
def endpoint_dummy_cache(monkeypatch): def endpoint_dummy_cache(monkeypatch):
"""Monkey patch the Django cache to a 'dummy' one for all passerelle views."""
from django.core.cache import caches from django.core.cache import caches
import passerelle.views import passerelle.views
monkeypatch.setattr( monkeypatch.setattr(
@ -48,12 +55,14 @@ def endpoint_dummy_cache(monkeypatch):
@urlmatch() @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') return response(500, 'Internal server error')
@pytest.fixture @pytest.fixture
def mock_500(): def mock_500():
"""Mock an Internal Server Error."""
with HTTMock(internal_server_error): with HTTMock(internal_server_error):
yield None yield None
@ -65,8 +74,8 @@ def relax_openssl(tmpdir):
import os import os
openssl_cnf_path = tmpdir / 'openssl.cnf' openssl_cnf_path = tmpdir / 'openssl.cnf'
with openssl_cnf_path.open('w') as fd: with openssl_cnf_path.open('w') as file_pt:
fd.write(u''' file_pt.write(u'''
[default_conf] [default_conf]
ssl_conf = ssl_sect ssl_conf = ssl_sect
@ -84,4 +93,3 @@ CipherString = ALL''')
del os.environ['OPENSSL_CONF'] del os.environ['OPENSSL_CONF']
else: else:
os.environ['OPENSSL_CONF'] = old_value os.environ['OPENSSL_CONF'] = old_value

View File

@ -18,13 +18,15 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Settings for testing."""
import os import os
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC' TIME_ZONE = 'UTC'
# include app # include app
INSTALLED_APPS += ( INSTALLED_APPS += ( # pylint: disable=undefined-variable
'atreal_openads', 'atreal_openads',
) )