hobo_deploy: internally call import_template using tenant_command (#33873)

This commit is contained in:
Nicolas Roche 2019-06-12 16:22:45 +02:00
parent 4e379b2f91
commit 43c082bf3b
3 changed files with 11 additions and 6 deletions

View File

@ -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'])

View File

@ -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 == []

View File

@ -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",