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
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""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

View File

@ -18,13 +18,15 @@
# 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/>.
"""Settings for testing."""
import os
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
# include app
INSTALLED_APPS += (
INSTALLED_APPS += ( # pylint: disable=undefined-variable
'atreal_openads',
)