code style (#33563)
This commit is contained in:
parent
c5a247cb67
commit
570722b01a
|
@ -1,20 +1,32 @@
|
|||
# hobo - portal to configure and deploy applications
|
||||
# Copyright (C) 2015-2016 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
import os
|
||||
import threading
|
||||
import random
|
||||
import pytest
|
||||
|
||||
from django.apps import apps
|
||||
import django.conf
|
||||
from django.core.handlers.base import BaseHandler
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
import django.db
|
||||
from django.core.cache import cache, caches
|
||||
from django.test import override_settings
|
||||
|
||||
from tenant_schemas.utils import tenant_context
|
||||
|
||||
import utilities
|
||||
from hobo.theme.utils import set_theme, get_themes
|
||||
|
||||
|
||||
def test_tenant_middleware(tenants, client, settings):
|
||||
settings.ALLOWED_HOSTS.append('invalid.example.net')
|
||||
|
@ -27,6 +39,7 @@ def test_tenant_middleware(tenants, client, settings):
|
|||
assert res.status_code != 404
|
||||
assert res.wsgi_request.tenant.schema_name == tenant.schema_name
|
||||
|
||||
|
||||
def test_tenant_json_settings(tenants, settings):
|
||||
settings.clear_tenants_settings()
|
||||
|
||||
|
@ -39,7 +52,6 @@ def test_tenant_json_settings(tenants, settings):
|
|||
assert django.conf.settings.UPDATE_ME == {'x': 1}
|
||||
assert django.conf.settings.EXTEND_ME == [1]
|
||||
|
||||
|
||||
# check that for each tenant it contains the tenant domain
|
||||
# it's set by the tenants fixture in conftest.py
|
||||
for tenant in tenants:
|
||||
|
@ -56,8 +68,6 @@ def test_tenant_json_settings(tenants, settings):
|
|||
|
||||
|
||||
def test_tenant_template_vars(tenants, settings, client):
|
||||
from hobo.multitenant.models import Tenant
|
||||
|
||||
django.conf.settings.clear_tenants_settings()
|
||||
|
||||
with utilities.patch_default_settings(settings,
|
||||
|
@ -80,9 +90,8 @@ def test_tenant_template_vars(tenants, settings, client):
|
|||
with pytest.raises(AttributeError):
|
||||
django.conf.settings.TEMPLATE_VARS
|
||||
|
||||
def test_tenant_settings_vars(tenants, settings, client):
|
||||
from hobo.multitenant.models import Tenant
|
||||
|
||||
def test_tenant_settings_vars(tenants, settings, client):
|
||||
django.conf.settings.clear_tenants_settings()
|
||||
|
||||
with utilities.patch_default_settings(settings,
|
||||
|
@ -108,6 +117,7 @@ def test_tenant_settings_vars(tenants, settings, client):
|
|||
assert django.conf.settings.LOCAL2 == [tenant.domain_url, 7, 8]
|
||||
assert django.conf.settings.LOCAL3 == {'a': tenant.domain_url, 'b': 2}
|
||||
|
||||
|
||||
def test_tenant_cors_settings(tenants, settings, client):
|
||||
settings.clear_tenants_settings()
|
||||
|
||||
|
@ -127,13 +137,13 @@ def test_tenant_cors_settings(tenants, settings, client):
|
|||
with pytest.raises(AttributeError):
|
||||
django.conf.settings.CORS_ORIGIN_WHITELIST
|
||||
|
||||
def test_tenant_theme_settings(tenants, settings, client):
|
||||
from hobo.multitenant.models import Tenant
|
||||
|
||||
def test_tenant_theme_settings(tenants, settings, client):
|
||||
django.conf.settings.clear_tenants_settings()
|
||||
|
||||
with utilities.patch_default_settings(settings,
|
||||
TENANT_SETTINGS_LOADERS=('hobo.multitenant.settings_loaders.TemplateVars',
|
||||
with utilities.patch_default_settings(
|
||||
settings, TENANT_SETTINGS_LOADERS=(
|
||||
'hobo.multitenant.settings_loaders.TemplateVars',
|
||||
'hobo.multitenant.settings_loaders.ThemeSettings')):
|
||||
old_value = os.environ['DJANGO_SETTINGS_MODULE']
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'fake.settings'
|
||||
|
@ -144,6 +154,7 @@ def test_tenant_theme_settings(tenants, settings, client):
|
|||
assert django.conf.settings.HELLO == 'world'
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = old_value
|
||||
|
||||
|
||||
def test_multithreading(tenants, settings, client):
|
||||
|
||||
settings.clear_tenants_settings()
|
||||
|
@ -151,7 +162,7 @@ def test_multithreading(tenants, settings, client):
|
|||
TENANT_SETTINGS_LOADERS=('hobo.multitenant.settings_loaders.TemplateVars',)):
|
||||
|
||||
def f(tenant=None):
|
||||
if not tenant is None:
|
||||
if tenant is not None:
|
||||
assert hasattr(settings, 'TEMPLATE_VARS')
|
||||
assert settings.TEMPLATE_VARS['test_url'] == tenant.get_base_url()
|
||||
else:
|
||||
|
@ -174,6 +185,7 @@ def test_multithreading(tenants, settings, client):
|
|||
t3.start()
|
||||
t3.join()
|
||||
|
||||
|
||||
def test_cache(tenants, client):
|
||||
# Clear caches
|
||||
caches._caches.caches = {}
|
||||
|
@ -227,7 +239,9 @@ def test_known_services(tenants, settings):
|
|||
assert hasattr(settings, 'KNOWN_SERVICES')
|
||||
assert 'authentic' in settings.KNOWN_SERVICES
|
||||
assert 'other' in settings.KNOWN_SERVICES['authentic']
|
||||
assert (set(['url', 'backoffice-menu-url', 'title', 'orig', 'verif_orig', 'secret', 'template_name', 'variables', 'secondary'])
|
||||
assert (set(['url', 'backoffice-menu-url', 'title', 'orig',
|
||||
'verif_orig', 'secret', 'template_name', 'variables',
|
||||
'secondary'])
|
||||
== set(settings.KNOWN_SERVICES['authentic']['other'].keys()))
|
||||
assert (settings.KNOWN_SERVICES['authentic']['other']['url']
|
||||
== hobo_json['services'][2]['base_url'])
|
||||
|
@ -236,17 +250,15 @@ def test_known_services(tenants, settings):
|
|||
assert (settings.KNOWN_SERVICES['authentic']['other']['title']
|
||||
== hobo_json['services'][2]['title'])
|
||||
assert settings.KNOWN_SERVICES['authentic']['other']['orig'] == tenant.domain_url
|
||||
assert (settings.KNOWN_SERVICES['authentic']['other']['verif_orig'] ==
|
||||
'other.example.net')
|
||||
assert (settings.KNOWN_SERVICES['authentic']['other']['verif_orig']
|
||||
== 'other.example.net')
|
||||
key1 = hobo_json['services'][0]['secret_key']
|
||||
key2 = hobo_json['services'][2]['secret_key']
|
||||
assert (settings.KNOWN_SERVICES['authentic']['other']['secret'] ==
|
||||
KnownServices.shared_secret(key1, key2))
|
||||
assert (settings.KNOWN_SERVICES['authentic']['other']['secret']
|
||||
== KnownServices.shared_secret(key1, key2))
|
||||
|
||||
|
||||
def test_unique_cookies(tenants, settings):
|
||||
from hobo.multitenant.settings_loaders import KnownServices
|
||||
|
||||
settings.clear_tenants_settings()
|
||||
|
||||
cookie_names = set()
|
||||
|
|
Loading…
Reference in New Issue