From 554f0e8409bbe21479140d3326a4502f01e92f6b Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 30 May 2019 09:09:16 +0200 Subject: [PATCH 5/6] tests_multitenant: add test on settings.json reloading (#33563) --- tests_multitenant/test_settings.py | 35 ++++++++++++++++++++++++++++++ tox.ini | 1 + 2 files changed, 36 insertions(+) diff --git a/tests_multitenant/test_settings.py b/tests_multitenant/test_settings.py index ffa3090..98ee238 100644 --- a/tests_multitenant/test_settings.py +++ b/tests_multitenant/test_settings.py @@ -14,6 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import datetime +import json import os import threading import random @@ -268,3 +270,36 @@ def test_unique_cookies(tenants, settings): cookie_names.add(settings.SESSION_COOKIE_NAME) assert len(cookie_names) == len(tenants) * 2 + + +def test_tenant_json_settings_reload(tenants, settings, freezer): + settings.clear_tenants_settings() + + with utilities.patch_default_settings(settings, + TENANT_SETTINGS_LOADERS=('hobo.multitenant.settings_loaders.SettingsJSON',)): + + # check EXTEND_ME has its base value + assert django.conf.settings.EXTEND_ME == [1] + + # check EXTEND_ME is extended + for tenant in tenants: + with tenant_context(tenant): + assert django.conf.settings.EXTEND_ME == [1, 2] + + # move 1 minute in the future + freezer.move_to(datetime.timedelta(seconds=60)) + + # update EXTEND_ME tenant value + for tenant in tenants: + with open(os.path.join(tenant.get_directory(), 'settings.json'), 'w') as fd: + json.dump({ + 'EXTEND_ME.extend': [3] + }, fd) + + # move 1 minute in the future + freezer.move_to(datetime.timedelta(seconds=60)) + + # check EXTEND_ME is still extended from base value + for tenant in tenants: + with tenant_context(tenant): + assert django.conf.settings.EXTEND_ME == [1, 3] diff --git a/tox.ini b/tox.ini index eae6a97..6a55bd8 100644 --- a/tox.ini +++ b/tox.ini @@ -55,6 +55,7 @@ deps: http://git.entrouvert.org/debian/django-tenant-schemas.git/snapshot/django-tenant-schemas-master.tar.gz httmock requests + pytest-freezegun commands = ./getlasso.sh hobo: py.test {env:COVERAGE:} {env:NOMIGRATIONS:} {posargs:tests/} -- 2.20.1