This repository has been archived on 2023-02-22. You can view files and clone it, but cannot push or open issues or pull requests.
passerelle-atreal-openads/tests/conftest.py

68 lines
1.5 KiB
Python

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):
settings.MEDIA_ROOT = str(tmpdir.mkdir('media'))
@pytest.fixture
def app(request):
wtm = django_webtest.WebTestMixin()
wtm._patch_settings()
request.addfinalizer(wtm._unpatch_settings)
cache.clear()
return django_webtest.DjangoTestApp()
@pytest.fixture
def endpoint_dummy_cache(monkeypatch):
from django.core.cache import caches
import passerelle.views
monkeypatch.setattr(
passerelle.views, 'cache', caches['dummy'])
@urlmatch()
def internal_server_error(url, request):
return response(500, 'Internal server error')
@pytest.fixture
def mock_500():
with HTTMock(internal_server_error):
yield None
@pytest.fixture
def relax_openssl(tmpdir):
'''OpenSSL default configuration has been really strict for some years,
this fixture set a temporary really permisive ciphers list.'''
import os
openssl_cnf_path = tmpdir / 'openssl.cnf'
with openssl_cnf_path.open('w') as fd:
fd.write(u'''
[default_conf]
ssl_conf = ssl_sect
[ssl_sect]
system_default = system_default_sect
[system_default_sect]
CipherString = ALL''')
old_value = os.environ.get('OPENSSL_CONF', None)
try:
os.environ['OPENSSL_CONF'] = str(openssl_cnf_path)
yield
finally:
if old_value is None:
del os.environ['OPENSSL_CONF']
else:
os.environ['OPENSSL_CONF'] = old_value