70 lines
2.7 KiB
Python
70 lines
2.7 KiB
Python
import pytest
|
|
import mock
|
|
|
|
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
|
|
|
|
|
|
@mock.patch('hobo.agent.common.management.commands.import_template.os.path.exists')
|
|
@mock.patch('hobo.agent.common.management.commands.import_template.call_command')
|
|
@mock.patch('hobo.agent.common.management.commands.import_template.get_commands')
|
|
def test_import_template_default(get_commands, call_command, os_path_exists):
|
|
"""do import a template from default path"""
|
|
expected = [mock.call('import_site', '/var/lib/bobo/skeletons/import_me.json')]
|
|
|
|
get_commands.return_value = 'import_site'
|
|
call_command.return_value = mock.MagicMock()
|
|
os_path_exists.return_value = True
|
|
|
|
# simulate:
|
|
# $ XXX-manage import-template import_me
|
|
command = Command()
|
|
with override_settings(PROJECT_NAME='bobo'):
|
|
command.handle(template_name='import_me')
|
|
|
|
# assert 'import_site' command is run
|
|
assert call_command.mock_calls == expected
|
|
|
|
@mock.patch('hobo.agent.common.management.commands.import_template.os.path.exists')
|
|
@mock.patch('hobo.agent.common.management.commands.import_template.call_command')
|
|
@mock.patch('hobo.agent.common.management.commands.import_template.get_commands')
|
|
def test_import_template_basepath(get_commands, call_command, os_path_exists):
|
|
"""do import a template having basepath parameter provided"""
|
|
expected = [mock.call('import_site', '/tmp/import_me.json')]
|
|
|
|
get_commands.return_value = 'import_site'
|
|
call_command.return_value = mock.MagicMock()
|
|
os_path_exists.return_value = True
|
|
|
|
# simulate:
|
|
# $ XXX-manage import-template import_me --basepath /tmp
|
|
command = Command()
|
|
with override_settings(PROJECT_NAME='bobo'):
|
|
command.handle(template_name='import_me', basepath='/tmp')
|
|
|
|
# assert 'import_site' command is run
|
|
assert call_command.mock_calls == expected
|
|
|
|
|
|
@mock.patch('hobo.agent.common.management.commands.import_template.os.path.exists')
|
|
@mock.patch('hobo.agent.common.management.commands.import_template.call_command')
|
|
@mock.patch('hobo.agent.common.management.commands.import_template.get_commands')
|
|
def test_import_template_warning(get_commands, call_command, os_path_exists):
|
|
"""returns if template is not found"""
|
|
|
|
get_commands.return_value = 'import_site'
|
|
call_command.return_value = mock.MagicMock()
|
|
os_path_exists.return_value = False
|
|
|
|
# simulate:
|
|
# $ XXX-manage import-template import_me
|
|
command = Command()
|
|
with override_settings(PROJECT_NAME='bobo'):
|
|
command.handle(template_name='import_me')
|
|
|
|
# assert 'import_site' command is not run
|
|
assert call_command.mock_calls == []
|