0001-combo-add-custom-import_template-to-ignore-errors-wi.patch
hobo/agent/combo/management/commands/import_template.py | ||
---|---|---|
1 |
# hobo - portal to configure and deploy applications |
|
2 |
# Copyright (C) 2015-2019 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software: you can redistribute it and/or modify it |
|
5 |
# under the terms of the GNU Affero General Public License as published |
|
6 |
# by the Free Software Foundation, either version 3 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU Affero General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU Affero General Public License |
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 | ||
18 |
from hobo.agent.common.management.commands import import_template |
|
19 | ||
20 |
class Command(import_template.Command): |
|
21 |
def handle(self, *args, **kwargs): |
|
22 |
try: |
|
23 |
return super(Command, self).handle(*args, **kwargs) |
|
24 |
except import_template.UnknownTemplateError: |
|
25 |
# ignore errors if template name is portal-user or portal-agent as |
|
26 |
# those names do not actually require an existing file to work. |
|
27 |
if kwargs.get('template_name') not in ('portal-user', 'portal-agent'): |
|
28 |
raise |
hobo/agent/common/management/commands/import_template.py | ||
---|---|---|
21 | 21 |
from django.core.management import call_command, get_commands |
22 | 22 | |
23 | 23 | |
24 |
class UnknownTemplateError(CommandError): |
|
25 |
pass |
|
26 | ||
27 | ||
24 | 28 |
class Command(BaseCommand): |
25 | 29 | |
26 | 30 |
def add_arguments(self, parser): |
... | ... | |
34 | 38 | |
35 | 39 |
if 'import_site' in get_commands(): |
36 | 40 |
if not os.path.exists(template): |
37 |
self.stderr.write(self.style.WARNING( |
|
38 |
'Unknown template (%r)' % template)) |
|
41 |
raise UnknownTemplateError('unknown template (%r)' % template) |
|
39 | 42 |
else: |
40 | 43 |
call_command('import_site', template) |
tests/test_import_template.py | ||
---|---|---|
5 | 5 |
from django.core.management.base import CommandError |
6 | 6 |
from django.test import override_settings |
7 | 7 | |
8 |
from hobo.agent.common.management.commands.import_template import Command |
|
8 |
from hobo.agent.common.management.commands.import_template import Command, UnknownTemplateError
|
|
9 | 9 | |
10 | 10 | |
11 | 11 |
@mock.patch('hobo.agent.common.management.commands.import_template.os.path.exists') |
... | ... | |
63 | 63 |
# $ XXX-manage import-template import_me |
64 | 64 |
command = Command() |
65 | 65 |
with override_settings(PROJECT_NAME='bobo'): |
66 |
command.handle(template_name='import_me') |
|
66 |
with pytest.raises(UnknownTemplateError): |
|
67 |
command.handle(template_name='import_me') |
|
67 | 68 | |
68 | 69 |
# assert 'import_site' command is not run |
69 | 70 |
assert call_command.mock_calls == [] |
70 |
- |