combo: add custom import_template to ignore errors with some names (#32495)
This commit is contained in:
parent
6eb6a6c525
commit
362af52cdd
|
@ -0,0 +1,28 @@
|
|||
# hobo - portal to configure and deploy applications
|
||||
# Copyright (C) 2015-2019 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from hobo.agent.common.management.commands import import_template
|
||||
|
||||
class Command(import_template.Command):
|
||||
def handle(self, *args, **kwargs):
|
||||
try:
|
||||
return super(Command, self).handle(*args, **kwargs)
|
||||
except import_template.UnknownTemplateError:
|
||||
# ignore errors if template name is portal-user or portal-agent as
|
||||
# those names do not actually require an existing file to work.
|
||||
if kwargs.get('template_name') not in ('portal-user', 'portal-agent'):
|
||||
raise
|
|
@ -21,6 +21,10 @@ from django.core.management.base import BaseCommand, CommandError
|
|||
from django.core.management import call_command, get_commands
|
||||
|
||||
|
||||
class UnknownTemplateError(CommandError):
|
||||
pass
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
def add_arguments(self, parser):
|
||||
|
@ -34,7 +38,6 @@ class Command(BaseCommand):
|
|||
|
||||
if 'import_site' in get_commands():
|
||||
if not os.path.exists(template):
|
||||
self.stderr.write(self.style.WARNING(
|
||||
'Unknown template (%r)' % template))
|
||||
raise UnknownTemplateError('unknown template (%r)' % template)
|
||||
else:
|
||||
call_command('import_site', template)
|
||||
|
|
|
@ -5,7 +5,7 @@ from django.conf import settings
|
|||
from django.core.management.base import CommandError
|
||||
from django.test import override_settings
|
||||
|
||||
from hobo.agent.common.management.commands.import_template import Command
|
||||
from hobo.agent.common.management.commands.import_template import Command, UnknownTemplateError
|
||||
|
||||
|
||||
@mock.patch('hobo.agent.common.management.commands.import_template.os.path.exists')
|
||||
|
@ -63,7 +63,8 @@ def test_import_template_warning(get_commands, call_command, os_path_exists):
|
|||
# $ XXX-manage import-template import_me
|
||||
command = Command()
|
||||
with override_settings(PROJECT_NAME='bobo'):
|
||||
command.handle(template_name='import_me')
|
||||
with pytest.raises(UnknownTemplateError):
|
||||
command.handle(template_name='import_me')
|
||||
|
||||
# assert 'import_site' command is not run
|
||||
assert call_command.mock_calls == []
|
||||
|
|
Loading…
Reference in New Issue