0001-hobo_deploy-internally-call-import_template-using-te.patch
hobo/agent/common/management/commands/hobo_deploy.py | ||
---|---|---|
10 | 10 |
from django.core.management.base import BaseCommand, CommandError |
11 | 11 |
from django.core.management import call_command, get_commands |
12 | 12 | |
13 |
from tenant_schemas.utils import tenant_context |
|
13 | 14 |
from hobo.multitenant.middleware import TenantMiddleware, TenantNotFound |
14 | 15 |
from hobo.theme.utils import get_theme |
15 | 16 | |
... | ... | |
192 | 193 |
me = [x for x in hobo_environment.get('services') if x.get('this') is True][0] |
193 | 194 | |
194 | 195 |
if 'import_template' in get_commands() and me.get('template_name'): |
195 |
call_command('import_template', me['template_name']) |
|
196 |
with tenant_context(tenant): |
|
197 |
call_command('import_template', me['template_name']) |
tests/test_hobo_deploy.py | ||
---|---|---|
382 | 382 | |
383 | 383 | |
384 | 384 |
@patch('hobo.agent.common.management.commands.hobo_deploy.get_commands') |
385 |
@patch('hobo.agent.common.management.commands.hobo_deploy.tenant_context') |
|
385 | 386 |
@patch('hobo.agent.common.management.commands.hobo_deploy.call_command') |
386 |
def test_configure_template(mocked_call_command, mocked_get_commands): |
|
387 |
def test_configure_template(mocked_call_command, mocked_tenant_context, |
|
388 |
mocked_get_commands): |
|
387 | 389 |
command = Command() |
390 |
tenant = Mock() |
|
388 | 391 |
ENVIRONMENT = {'services': [{'service-id': 'combo', |
389 | 392 |
'template_name': 'my_template', |
390 | 393 |
'this': True}]} |
... | ... | |
394 | 397 |
mocked_get_commands.return_value = ['import_template', '...'] |
395 | 398 | |
396 | 399 |
# main case |
397 |
command.configure_template(ENVIRONMENT, 'unused') # TODO: dead tenant parameter
|
|
400 |
command.configure_template(ENVIRONMENT, tenant)
|
|
398 | 401 |
assert mocked_call_command.mock_calls == [call('import_template', 'my_template')] |
399 | 402 | |
400 | 403 |
# no template_name entry provided |
401 | 404 |
mocked_call_command.reset_mock() |
402 | 405 |
del ENVIRONMENT['services'][0]['template_name'] |
403 |
command.configure_template(ENVIRONMENT, 'unused')
|
|
406 |
command.configure_template(ENVIRONMENT, tenant)
|
|
404 | 407 |
assert mocked_call_command.mock_calls == [] |
405 | 408 | |
406 | 409 |
tests_schemas/env.json | ||
---|---|---|
6 | 6 |
"slug": "agendas", |
7 | 7 |
"title": "CHRONO", |
8 | 8 |
"secret_key": "123", |
9 |
"template_name": "import_me.txt"
|
|
9 |
"template_name": "import_me" |
|
10 | 10 |
}, |
11 | 11 |
{ |
12 | 12 |
"service-id": "wcs", |
... | ... | |
27 | 27 |
"slug": "portal", |
28 | 28 |
"title": "COMBO", |
29 | 29 |
"secret_key": "123", |
30 |
"template_name": "import_me.txt"
|
|
30 |
"template_name": "import_me" |
|
31 | 31 |
}, |
32 | 32 |
{ |
33 | 33 |
"service-id": "authentic", |
34 |
- |