|
1 |
import pytest
|
|
2 |
import mock
|
|
3 |
|
|
4 |
from django.conf import settings
|
|
5 |
from django.core.management.base import CommandError
|
|
6 |
from django.test import override_settings
|
|
7 |
|
|
8 |
from hobo.agent.common.management.commands.import_template import Command
|
|
9 |
|
|
10 |
|
|
11 |
@mock.patch('hobo.agent.common.management.commands.import_template.os.path.exists')
|
|
12 |
@mock.patch('hobo.agent.common.management.commands.import_template.call_command')
|
|
13 |
@mock.patch('hobo.agent.common.management.commands.import_template.get_commands')
|
|
14 |
def test_import_template_default(get_commands, call_command, os_path_exists):
|
|
15 |
"""do import a template from default path"""
|
|
16 |
expected = [mock.call('import_site', '/var/lib/bobo/skeletons/import_me.json')]
|
|
17 |
|
|
18 |
get_commands.return_value = 'import_site'
|
|
19 |
call_command.return_value = mock.MagicMock()
|
|
20 |
os_path_exists.return_value = True
|
|
21 |
|
|
22 |
# simulate:
|
|
23 |
# $ XXX-manage import-template import_me
|
|
24 |
command = Command()
|
|
25 |
with override_settings(PROJECT_NAME='bobo'):
|
|
26 |
command.handle(template_name='import_me')
|
|
27 |
|
|
28 |
# assert 'import_site' command is run
|
|
29 |
assert call_command.mock_calls == expected
|
|
30 |
|
|
31 |
@mock.patch('hobo.agent.common.management.commands.import_template.os.path.exists')
|
|
32 |
@mock.patch('hobo.agent.common.management.commands.import_template.call_command')
|
|
33 |
@mock.patch('hobo.agent.common.management.commands.import_template.get_commands')
|
|
34 |
def test_import_template_basepath(get_commands, call_command, os_path_exists):
|
|
35 |
"""do import a template having basepath parameter provided"""
|
|
36 |
expected = [mock.call('import_site', '/tmp/import_me.json')]
|
|
37 |
|
|
38 |
get_commands.return_value = 'import_site'
|
|
39 |
call_command.return_value = mock.MagicMock()
|
|
40 |
os_path_exists.return_value = True
|
|
41 |
|
|
42 |
# simulate:
|
|
43 |
# $ XXX-manage import-template import_me --basepath /tmp
|
|
44 |
command = Command()
|
|
45 |
with override_settings(PROJECT_NAME='bobo'):
|
|
46 |
command.handle(template_name='import_me', basepath='/tmp')
|
|
47 |
|
|
48 |
# assert 'import_site' command is run
|
|
49 |
assert call_command.mock_calls == expected
|
|
50 |
|
|
51 |
|
|
52 |
@mock.patch('hobo.agent.common.management.commands.import_template.os.path.exists')
|
|
53 |
@mock.patch('hobo.agent.common.management.commands.import_template.call_command')
|
|
54 |
@mock.patch('hobo.agent.common.management.commands.import_template.get_commands')
|
|
55 |
def test_import_template_warning(get_commands, call_command, os_path_exists):
|
|
56 |
"""returns if template is not found"""
|
|
57 |
|
|
58 |
get_commands.return_value = 'import_site'
|
|
59 |
call_command.return_value = mock.MagicMock()
|
|
60 |
os_path_exists.return_value = False
|
|
61 |
|
|
62 |
# simulate:
|
|
63 |
# $ XXX-manage import-template import_me
|
|
64 |
command = Command()
|
|
65 |
with override_settings(PROJECT_NAME='bobo'):
|
|
66 |
command.handle(template_name='import_me')
|
|
67 |
|
|
68 |
# assert 'import_site' command is not run
|
|
69 |
assert call_command.mock_calls == []
|
0 |
|
-
|