-
Notifications
You must be signed in to change notification settings - Fork 313
/
test_plan.py
63 lines (57 loc) · 2.56 KB
/
test_plan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import pytest
from unittest.mock import MagicMock, patch, sentinel
from sceptre.context import SceptreContext
from sceptre.stack import Stack
from sceptre.config.reader import ConfigReader
from sceptre.plan.plan import SceptrePlan
class TestSceptrePlan(object):
def setup_method(self, test_method):
self.patcher_SceptrePlan = patch("sceptre.plan.plan.SceptrePlan")
self.stack = Stack(
name="dev/app/stack",
project_code=sentinel.project_code,
template_handler_config={"path": "/path/to/thing"},
region=sentinel.region,
profile=sentinel.profile,
parameters={"key1": "val1"},
sceptre_user_data=sentinel.sceptre_user_data,
hooks={},
s3_details=None,
dependencies=sentinel.dependencies,
cloudformation_service_role=sentinel.cloudformation_service_role,
protected=False,
tags={"tag1": "val1"},
external_name=sentinel.external_name,
notifications=[sentinel.notification],
on_failure=sentinel.on_failure,
stack_timeout=sentinel.stack_timeout,
)
self.mock_context = MagicMock(spec=SceptreContext)
self.mock_config_reader = MagicMock(spec=ConfigReader)
self.mock_context.project_path = sentinel.project_path
self.mock_context.command_path = sentinel.command_path
self.mock_context.config_file = sentinel.config_file
self.mock_context.full_config_path.return_value = sentinel.full_config_path
self.mock_context.user_variables = {}
self.mock_context.options = {}
self.mock_context.no_colour = True
self.mock_config_reader.context = self.mock_context
def test_planner_executes_without_params(self):
plan = MagicMock(spec=SceptrePlan)
plan.context = self.mock_context
plan.launch.return_value = sentinel.success
result = plan.launch()
plan.launch.assert_called_once_with()
assert result == sentinel.success
def test_planner_executes_with_params(self):
plan = MagicMock(spec=SceptrePlan)
plan.context = self.mock_context
plan.launch.return_value = sentinel.success
result = plan.launch("test-attribute")
plan.launch.assert_called_once_with("test-attribute")
assert result == sentinel.success
def test_command_not_found_error_raised(self):
with pytest.raises(AttributeError):
plan = MagicMock(spec=SceptrePlan)
plan.context = self.mock_context
plan.invalid_command()