Projet

Général

Profil

0001-set-TENANT_BASE-earlier-in-tests-22892.patch

Emmanuel Cazenave, 29 mars 2018 15:04

Télécharger (5,15 ko)

Voir les différences:

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(-)
tests_authentic/conftest.py
1 1
import os
2
import tempfile
3 2
import shutil
4 3
import json
5 4

  
6 5
import pytest
7 6

  
8 7

  
9
@pytest.fixture
10
def tenant_base(request, settings):
11
    base = tempfile.mkdtemp('combo-tenant-base')
12
    settings.TENANT_BASE = base
13

  
14
    def fin():
15
        shutil.rmtree(base)
16
    request.addfinalizer(fin)
17
    return base
8
@pytest.fixture(scope='session', autouse=True)
9
def clean_tenant_base():
10
    # Setup part of the fixture
11
    yield
12
    # Teardown part of the fixture
13
    from django.conf import settings
14
    shutil.rmtree(settings.TENANT_BASE)
18 15

  
19 16

  
20 17
@pytest.fixture(scope='function')
21
def tenant(transactional_db, request, settings, tenant_base):
18
def tenant(transactional_db, request, settings):
22 19
    from hobo.multitenant.models import Tenant
23
    base = tenant_base
20
    base = settings.TENANT_BASE
24 21

  
25 22
    @pytest.mark.django_db
26 23
    def make_tenant(name):
tests_authentic/settings.py
2 2
import __builtin__ as builtin
3 3
from mock import mock_open, patch
4 4
import os
5
import tempfile
5 6

  
6 7
# Debian defaults
7 8
DEBUG = False
......
12 13
with patch.object(builtin, 'file', mock_open(read_data='xxx')):
13 14
    execfile(os.environ['DEBIAN_CONFIG_COMMON'])
14 15

  
16
TENANT_BASE = tempfile.mkdtemp('authentic-tenant-base')
17

  
15 18
# Add the XForwardedForMiddleware
16 19
MIDDLEWARE_CLASSES = ('authentic2.middleware.XForwardedForMiddleware',) + MIDDLEWARE_CLASSES
17 20

  
tests_authentic/test_hobo_deploy.py
19 19
    return settings.HOBO_SKELETONS_DIR
20 20

  
21 21

  
22
def test_hobo_deploy(tenant_base, settings, mocker, skeleton_dir):
22
def test_hobo_deploy(settings, mocker, skeleton_dir):
23 23
    from django.core.management import call_command
24 24

  
25 25
    # Create skeleton roles.json
......
307 307
    assert tenant.domain_url == 'sso.example.net'
308 308
    assert tenant.schema_name == 'sso_example_net'
309 309
    tenant_directory = tenant.get_directory()
310
    assert tenant_directory == os.path.join(tenant_base, tenant.domain_url)
310
    assert tenant_directory == os.path.join(settings.TENANT_BASE, tenant.domain_url)
311 311
    assert os.path.exists(os.path.join(tenant_directory, 'saml.crt'))
312 312
    assert os.path.exists(os.path.join(tenant_directory, 'saml.key'))
313 313

  
tests_passerelle/conftest.py
1
import os
2
import tempfile
3 1
import shutil
4
import json
5 2

  
6 3
import pytest
7 4

  
8
@pytest.fixture
9
def tenant_base(request, settings):
10
    base = tempfile.mkdtemp('passerelle-tenant-base')
11
    settings.TENANT_BASE = base
12
    def fin():
13
        shutil.rmtree(base)
14
    request.addfinalizer(fin)
15
    return tenant_base
5

  
6
@pytest.fixture(scope='session', autouse=True)
7
def clean_tenant_base():
8
    # Setup part of the fixture
9
    yield
10
    # Teardown part of the fixture
11
    from django.conf import settings
12
    shutil.rmtree(settings.TENANT_BASE)
tests_passerelle/settings.py
2 2
import __builtin__ as builtin
3 3
from mock import mock_open, patch
4 4
import os
5
import tempfile
5 6

  
6 7
# Debian defaults
7 8
DEBUG = False
......
14 15
with patch.object(builtin, 'file', mock_open(read_data='xxx')):
15 16
    execfile(os.environ['DEBIAN_CONFIG_COMMON'])
16 17

  
18
TENANT_BASE = tempfile.mkdtemp('passerelle-tenant-base')
19

  
17 20
# suds logs are buggy
18 21
LOGGING['loggers']['suds'] = {
19 22
        'level': 'ERROR',
tests_passerelle/test_deploy.py
6 6
import StringIO
7 7

  
8 8

  
9
def test_deploy_specifics(db, tenant_base):
9
def test_deploy_specifics(db):
10 10
    hobo_json = {
11 11
        'variables': {
12 12
            'hobo_test_variable': True,
13
-