Skip to content

Commit a5e4e8f

Browse files
committed
Improve WizardLoader interface
1 parent c624460 commit a5e4e8f

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

awsshell/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,12 @@ def run(self, command, application):
149149

150150

151151
class WizardHandler(object):
152-
def __init__(self, output=sys.stdout, err=sys.stderr,
153-
loader=WizardLoader()):
152+
def __init__(self, output=sys.stdout, err=sys.stderr, loader=None):
154153
self._output = output
155154
self._err = err
156155
self._wizard_loader = loader
156+
if self._wizard_loader is None:
157+
self._wizard_loader = WizardLoader()
157158

158159
def run(self, command, application):
159160
"""Run the specified wizard.

awsshell/wizard.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class WizardLoader(object):
5151
"""
5252

5353
def __init__(self, session=None, interaction_loader=None,
54-
error_handler=None, delegation_loader=None):
54+
error_handler=None):
5555
"""Initialize a wizard factory.
5656
5757
:type session: :class:`botocore.session.Session`
@@ -71,10 +71,6 @@ def __init__(self, session=None, interaction_loader=None,
7171
self._interaction_loader = interaction_loader
7272
if interaction_loader is None:
7373
self._interaction_loader = InteractionLoader()
74-
if delegation_loader is None:
75-
self._delegation_loader = self
76-
else:
77-
self._delegation_loader = delegation_loader
7874
self._error_handler = error_handler
7975
if error_handler is None:
8076
self._error_handler = stage_error_handler
@@ -126,8 +122,7 @@ def _load_stage(self, stage, env):
126122
}
127123
creator = self._cached_creator
128124
interaction = self._interaction_loader
129-
delegation = self._delegation_loader
130-
return Stage(env, creator, interaction, delegation, **stage_attrs)
125+
return Stage(env, creator, interaction, self, **stage_attrs)
131126

132127
def _load_stages(self, stages, env):
133128
return [self._load_stage(stage, env) for stage in stages]

tests/unit/test_wizard.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import mock
22
import pytest
3+
import botocore.session
4+
5+
from botocore.loaders import Loader
36
from botocore.session import Session
47
from awsshell.utils import FileReadError
58
from awsshell.wizard import stage_error_handler
@@ -289,9 +292,6 @@ def test_wizard_basic_interaction(wizard_spec):
289292

290293

291294
def test_wizard_basic_delegation(wizard_spec):
292-
mock_session = mock.Mock(spec=Session)
293-
mock_loader = mock.Mock(spec=WizardLoader)
294-
loader = WizardLoader(mock_session, delegation_loader=mock_loader)
295295
main_spec = {
296296
"StartStage": "One",
297297
"Stages": [
@@ -306,7 +306,6 @@ def test_wizard_basic_delegation(wizard_spec):
306306
}
307307
]
308308
}
309-
wizard = loader.create_wizard(main_spec)
310309
sub_spec = {
311310
"StartStage": "SubOne",
312311
"Stages": [
@@ -320,9 +319,19 @@ def test_wizard_basic_delegation(wizard_spec):
320319
}
321320
]
322321
}
323-
mock_loader.load_wizard.return_value = loader.create_wizard(sub_spec)
322+
323+
mock_loader = mock.Mock(spec=Loader)
324+
mock_loader.list_available_services.return_value = ['wizards']
325+
mock_load_model = mock_loader.load_service_model
326+
mock_load_model.return_value = sub_spec
327+
328+
session = botocore.session.get_session()
329+
session.register_component('data_loader', mock_loader)
330+
loader = WizardLoader(session)
331+
wizard = loader.create_wizard(main_spec)
332+
324333
result = wizard.execute()
325-
mock_loader.load_wizard.assert_called_once_with('SubWizard')
334+
mock_load_model.assert_called_once_with('wizards', 'SubWizard')
326335
assert result == 'Result from sub'
327336

328337

0 commit comments

Comments
 (0)