From 90cf6518e43b658e7d5d3ae3b8f36db7cc166c17 Mon Sep 17 00:00:00 2001 From: Emmanuel Cazenave Date: Thu, 29 Mar 2018 14:58:39 +0200 Subject: [PATCH] set TENANT_BASE earlier in tests (#22892) So that it is already available when the test database si created. --- tests_authentic/conftest.py | 21 +++++++++------------ tests_authentic/settings.py | 3 +++ tests_authentic/test_hobo_deploy.py | 4 ++-- tests_passerelle/conftest.py | 19 ++++++++----------- tests_passerelle/settings.py | 3 +++ tests_passerelle/test_deploy.py | 2 +- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tests_authentic/conftest.py b/tests_authentic/conftest.py index 2f82b9b..6498284 100644 --- a/tests_authentic/conftest.py +++ b/tests_authentic/conftest.py @@ -1,26 +1,23 @@ import os -import tempfile import shutil import json import pytest -@pytest.fixture -def tenant_base(request, settings): - base = tempfile.mkdtemp('combo-tenant-base') - settings.TENANT_BASE = base - - def fin(): - shutil.rmtree(base) - request.addfinalizer(fin) - return base +@pytest.fixture(scope='session', autouse=True) +def clean_tenant_base(): + # Setup part of the fixture + yield + # Teardown part of the fixture + from django.conf import settings + shutil.rmtree(settings.TENANT_BASE) @pytest.fixture(scope='function') -def tenant(transactional_db, request, settings, tenant_base): +def tenant(transactional_db, request, settings): from hobo.multitenant.models import Tenant - base = tenant_base + base = settings.TENANT_BASE @pytest.mark.django_db def make_tenant(name): diff --git a/tests_authentic/settings.py b/tests_authentic/settings.py index 27d7d42..fd84d0a 100644 --- a/tests_authentic/settings.py +++ b/tests_authentic/settings.py @@ -2,6 +2,7 @@ import os.path import __builtin__ as builtin from mock import mock_open, patch import os +import tempfile # Debian defaults DEBUG = False @@ -12,6 +13,8 @@ PROJECT_NAME = 'authentic2-multitenant' with patch.object(builtin, 'file', mock_open(read_data='xxx')): execfile(os.environ['DEBIAN_CONFIG_COMMON']) +TENANT_BASE = tempfile.mkdtemp('authentic-tenant-base') + # Add the XForwardedForMiddleware MIDDLEWARE_CLASSES = ('authentic2.middleware.XForwardedForMiddleware',) + MIDDLEWARE_CLASSES diff --git a/tests_authentic/test_hobo_deploy.py b/tests_authentic/test_hobo_deploy.py index cef15c8..753cbfe 100644 --- a/tests_authentic/test_hobo_deploy.py +++ b/tests_authentic/test_hobo_deploy.py @@ -19,7 +19,7 @@ def skeleton_dir(request, settings): return settings.HOBO_SKELETONS_DIR -def test_hobo_deploy(tenant_base, settings, mocker, skeleton_dir): +def test_hobo_deploy(settings, mocker, skeleton_dir): from django.core.management import call_command # Create skeleton roles.json @@ -307,7 +307,7 @@ def test_hobo_deploy(tenant_base, settings, mocker, skeleton_dir): assert tenant.domain_url == 'sso.example.net' assert tenant.schema_name == 'sso_example_net' tenant_directory = tenant.get_directory() - assert tenant_directory == os.path.join(tenant_base, tenant.domain_url) + assert tenant_directory == os.path.join(settings.TENANT_BASE, tenant.domain_url) assert os.path.exists(os.path.join(tenant_directory, 'saml.crt')) assert os.path.exists(os.path.join(tenant_directory, 'saml.key')) diff --git a/tests_passerelle/conftest.py b/tests_passerelle/conftest.py index 998f75c..be2bd26 100644 --- a/tests_passerelle/conftest.py +++ b/tests_passerelle/conftest.py @@ -1,15 +1,12 @@ -import os -import tempfile import shutil -import json import pytest -@pytest.fixture -def tenant_base(request, settings): - base = tempfile.mkdtemp('passerelle-tenant-base') - settings.TENANT_BASE = base - def fin(): - shutil.rmtree(base) - request.addfinalizer(fin) - return tenant_base + +@pytest.fixture(scope='session', autouse=True) +def clean_tenant_base(): + # Setup part of the fixture + yield + # Teardown part of the fixture + from django.conf import settings + shutil.rmtree(settings.TENANT_BASE) diff --git a/tests_passerelle/settings.py b/tests_passerelle/settings.py index 17d1bb2..0e21802 100644 --- a/tests_passerelle/settings.py +++ b/tests_passerelle/settings.py @@ -2,6 +2,7 @@ import os.path import __builtin__ as builtin from mock import mock_open, patch import os +import tempfile # Debian defaults DEBUG = False @@ -14,6 +15,8 @@ PROJECT_NAME = 'passerelle' with patch.object(builtin, 'file', mock_open(read_data='xxx')): execfile(os.environ['DEBIAN_CONFIG_COMMON']) +TENANT_BASE = tempfile.mkdtemp('passerelle-tenant-base') + # suds logs are buggy LOGGING['loggers']['suds'] = { 'level': 'ERROR', diff --git a/tests_passerelle/test_deploy.py b/tests_passerelle/test_deploy.py index e8a03ec..5a819f9 100644 --- a/tests_passerelle/test_deploy.py +++ b/tests_passerelle/test_deploy.py @@ -6,7 +6,7 @@ from django.core.management import call_command import StringIO -def test_deploy_specifics(db, tenant_base): +def test_deploy_specifics(db): hobo_json = { 'variables': { 'hobo_test_variable': True, -- 2.16.2