13
13
_handle_missing_parameters ,
14
14
UsePreviousParameterValue ,
15
15
)
16
+ from stacker .blueprints .base import Blueprint
16
17
from stacker .blueprints .variables .types import CFNString
17
18
from stacker .context import Context , Config
18
19
from stacker .exceptions import StackDidNotChange , StackDoesNotExist
19
20
from stacker .providers .base import BaseProvider
20
21
from stacker .providers .aws .default import Provider
21
22
from stacker .session_cache import get_session
23
+ from stacker .stack import Stack
22
24
from stacker .status import (
23
25
NotSubmittedStatus ,
24
26
COMPLETE ,
28
30
FAILED
29
31
)
30
32
31
- from ..factories import MockThreadingEvent , MockProviderBuilder
33
+ from ..factories import (
34
+ MockThreadingEvent ,
35
+ MockProviderBuilder ,
36
+ generate_definition
37
+ )
32
38
33
39
34
40
def mock_stack_parameters (parameters ):
@@ -155,22 +161,6 @@ def test_execute_plan_when_outline_not_specified(self):
155
161
build_action .run (outline = False )
156
162
self .assertEqual (mock_generate_plan ().execute .call_count , 1 )
157
163
158
- def test_should_update (self ):
159
- test_scenarios = (
160
- dict (blueprint = None , locked = False , force = False , result = False ),
161
- dict (blueprint = "BLUEPRINT" , locked = False , force = False ,
162
- result = True ),
163
- dict (blueprint = "BLUEPRINT" , locked = False , force = True , result = True ),
164
- dict (blueprint = "BLUEPRINT" , locked = True , force = False ,
165
- result = False ),
166
- dict (blueprint = "BLUEPRINT" , locked = True , force = True , result = True )
167
- )
168
- for t in test_scenarios :
169
- mock_stack = mock .MagicMock (
170
- ["blueprint" , "locked" , "force" , "name" ],
171
- name = 'test-stack' , ** t )
172
- self .assertEqual (build .should_update (mock_stack ), t ['result' ])
173
-
174
164
def test_should_ensure_cfn_bucket (self ):
175
165
test_scenarios = [
176
166
dict (outline = False , dump = False , result = True ),
@@ -191,21 +181,18 @@ def test_should_ensure_cfn_bucket(self):
191
181
e .args += ("scenario" , str (scenario ))
192
182
raise
193
183
194
- def test_should_submit (self ):
195
- test_scenarios = (
196
- dict (blueprint = None , enabled = False , result = True ),
197
- dict (blueprint = "BLUEPRINT" , enabled = False , result = False ),
198
- dict (blueprint = "BLUEPRINT" , enabled = True , result = True ),
199
- )
200
184
201
- for t in test_scenarios :
202
- mock_stack = mock .MagicMock (
203
- ["blueprint" , "enabled" , "name" ],
204
- name = 'test-stack' , ** t )
205
- self .assertEqual (build .should_submit (mock_stack ), t ['result' ])
185
+ class TestLaunchStack (TestBuildAction ):
186
+ def _get_stack (self ):
187
+ stack = Stack (definition = generate_definition ("vpc" , 1 ),
188
+ context = self .context ,)
206
189
190
+ blueprint_mock = mock .patch .object (type (stack ), 'blueprint' ,
191
+ spec = Blueprint , rendered = '{}' )
192
+ self .addCleanup (blueprint_mock .stop )
193
+ blueprint_mock .start ()
194
+ return stack
207
195
208
- class TestLaunchStack (TestBuildAction ):
209
196
def setUp (self ):
210
197
self .context = self ._get_context ()
211
198
self .session = get_session (region = None )
@@ -215,13 +202,7 @@ def setUp(self):
215
202
self .build_action = build .Action (self .context ,
216
203
provider_builder = provider_builder ,
217
204
cancel = MockThreadingEvent ())
218
-
219
- self .stack = mock .MagicMock ()
220
- self .stack .region = None
221
- self .stack .name = 'vpc'
222
- self .stack .fqn = 'vpc'
223
- self .stack .blueprint .rendered = '{}'
224
- self .stack .locked = False
205
+ self .stack = self ._get_stack ()
225
206
self .stack_status = None
226
207
227
208
plan = self .build_action ._generate_plan ()
@@ -233,14 +214,16 @@ def patch_object(*args, **kwargs):
233
214
self .addCleanup (m .stop )
234
215
m .start ()
235
216
236
- def get_stack (name , * args , ** kwargs ):
237
- if name != self .stack .name or not self .stack_status :
238
- raise StackDoesNotExist (name )
217
+ def get_stack (fqn , * args , ** kwargs ):
218
+ if fqn != self .stack .fqn or not self .stack_status :
219
+ raise StackDoesNotExist (fqn )
239
220
221
+ tags = [{'Key' : key , 'Value' : value }
222
+ for (key , value ) in self .stack .tags .items ()]
240
223
return {'StackName' : self .stack .name ,
241
224
'StackStatus' : self .stack_status ,
242
- 'Outputs' : [] ,
243
- 'Tags' : [] }
225
+ 'Outputs' : {} ,
226
+ 'Tags' : tags }
244
227
245
228
patch_object (self .provider , 'get_stack' , side_effect = get_stack )
246
229
patch_object (self .provider , 'update_stack' )
0 commit comments