@@ -26,17 +26,35 @@ def run(self, command, context):
26
26
assert call_args == [(['.foo' , 'a' , 'b' , 'c' ], context )]
27
27
28
28
29
+ class PopenLogger (object ):
30
+ def __call__ (self , cmd ):
31
+ self .cmd = cmd
32
+ filename = cmd [1 ]
33
+ with open (filename , 'r' ) as f :
34
+ self .contents = f .read ()
35
+ return mock .Mock ()
36
+
37
+
29
38
def test_edit_handler ():
30
39
env = {'EDITOR' : 'my-editor' }
31
40
popen_cls = mock .Mock ()
32
- context = mock .Mock ()
33
- context .history = []
34
- handler = app .EditHandler (popen_cls , env )
35
- handler .run (['.edit' ], context )
41
+ application = mock .Mock ()
42
+ application .history = [
43
+ '!ls' ,
44
+ '.edit' ,
45
+ 'aws ec2 describe-instances' ,
46
+ 'aws ec2 allocate-hosts' ,
47
+ ]
48
+ popen = PopenLogger ()
49
+ handler = app .EditHandler (popen , env )
50
+ handler .run (['.edit' ], application )
36
51
# Ensure our editor was called with some arbitrary temp filename.
37
- command_run = popen_cls . call_args [ 0 ][ 0 ]
52
+ command_run = popen . cmd
38
53
assert len (command_run ) == 2
39
54
assert command_run [0 ] == 'my-editor'
55
+ # Ensure the contents of the temp file are correct
56
+ expected_contents = 'aws ec2 describe-instances\n aws ec2 allocate-hosts'
57
+ assert popen .contents == expected_contents
40
58
41
59
42
60
def test_error_msg_printed_on_error_handler (errstream ):
@@ -132,6 +150,25 @@ def test_error_displayed_when_chdir_fails(errstream):
132
150
assert 'FAILED' in errstream .getvalue ()
133
151
134
152
153
+ def test_history_stored_correctly ():
154
+ mock_prompter = mock .Mock ()
155
+ mock_prompter .buffers = {'clidocs' : mock .Mock ()}
156
+ # Simulate the user entering various commands
157
+ quit_document = mock .Mock ()
158
+ quit_document .text = '.quit'
159
+ command_document = mock .Mock ()
160
+ command_document .text = 'ec2 describe-instances'
161
+ mock_prompter .run .side_effect = [command_document , quit_document ]
162
+ shell = app .AWSShell (mock .Mock (), mock .Mock (), mock .Mock (),
163
+ popen_cls = mock .Mock ())
164
+ shell .create_cli_interface = mock .Mock (return_value = mock_prompter )
165
+ shell .run ()
166
+
167
+ # two calls should have been made, history should have added aws
168
+ assert mock_prompter .run .call_count == 2
169
+ assert list (shell .history ) == ['aws ec2 describe-instances' ]
170
+
171
+
135
172
def test_exit_dot_command_exits_shell ():
136
173
mock_prompter = mock .Mock ()
137
174
# Simulate the user entering '.quit'
0 commit comments