diff --git a/hobo/agent/common/management/commands/hobo_deploy.py b/hobo/agent/common/management/commands/hobo_deploy.py index 8fa1e84..e41ed96 100644 --- a/hobo/agent/common/management/commands/hobo_deploy.py +++ b/hobo/agent/common/management/commands/hobo_deploy.py @@ -10,6 +10,7 @@ from django.conf import settings from django.core.management.base import BaseCommand, CommandError from django.core.management import call_command, get_commands +from tenant_schemas.utils import tenant_context from hobo.multitenant.middleware import TenantMiddleware, TenantNotFound from hobo.theme.utils import get_theme @@ -192,4 +193,5 @@ class Command(BaseCommand): me = [x for x in hobo_environment.get('services') if x.get('this') is True][0] if 'import_template' in get_commands() and me.get('template_name'): - call_command('import_template', me['template_name']) + with tenant_context(tenant): + call_command('import_template', me['template_name']) diff --git a/tests/test_hobo_deploy.py b/tests/test_hobo_deploy.py index f238760..fa06c93 100644 --- a/tests/test_hobo_deploy.py +++ b/tests/test_hobo_deploy.py @@ -382,9 +382,12 @@ def test_configure_theme(fake_themes, tmpdir): @patch('hobo.agent.common.management.commands.hobo_deploy.get_commands') +@patch('hobo.agent.common.management.commands.hobo_deploy.tenant_context') @patch('hobo.agent.common.management.commands.hobo_deploy.call_command') -def test_configure_template(mocked_call_command, mocked_get_commands): +def test_configure_template(mocked_call_command, mocked_tenant_context, + mocked_get_commands): command = Command() + tenant = Mock() ENVIRONMENT = {'services': [{'service-id': 'combo', 'template_name': 'my_template', 'this': True}]} @@ -394,13 +397,13 @@ def test_configure_template(mocked_call_command, mocked_get_commands): mocked_get_commands.return_value = ['import_template', '...'] # main case - command.configure_template(ENVIRONMENT, 'unused') # TODO: dead tenant parameter + command.configure_template(ENVIRONMENT, tenant) assert mocked_call_command.mock_calls == [call('import_template', 'my_template')] # no template_name entry provided mocked_call_command.reset_mock() del ENVIRONMENT['services'][0]['template_name'] - command.configure_template(ENVIRONMENT, 'unused') + command.configure_template(ENVIRONMENT, tenant) assert mocked_call_command.mock_calls == [] diff --git a/tests_schemas/env.json b/tests_schemas/env.json index e9ad2e7..8e73cdb 100644 --- a/tests_schemas/env.json +++ b/tests_schemas/env.json @@ -6,7 +6,7 @@ "slug": "agendas", "title": "CHRONO", "secret_key": "123", - "template_name": "import_me.txt" + "template_name": "import_me" }, { "service-id": "wcs", @@ -27,7 +27,7 @@ "slug": "portal", "title": "COMBO", "secret_key": "123", - "template_name": "import_me.txt" + "template_name": "import_me" }, { "service-id": "authentic",