Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/functional/history/test_list.py
1567 views
1
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
from awscli.compat import ensure_text_type
14
15
from tests.functional.history import BaseHistoryCommandParamsTest
16
from awscli.testutils import create_clidriver
17
18
19
class TestListCommand(BaseHistoryCommandParamsTest):
20
def test_show_nothing_when_no_history_and_call_made(self):
21
self.environ['AWS_CONFIG_FILE'] = ''
22
self.driver = create_clidriver()
23
self.parsed_responses = [
24
{
25
"Regions": [
26
{
27
"Endpoint": "ec2.ap-south-1.amazonaws.com",
28
"RegionName": "ap-south-1"
29
},
30
]
31
}
32
]
33
self.run_cmd('ec2 describe-regions', expected_rc=0)
34
self.run_cmd('history show', expected_rc=0)
35
# The history show should not display anything as no history should
36
# have been collected
37
self.assertEqual(b'', self.binary_stdout.getvalue())
38
39
def test_show_nothing_when_no_history(self):
40
out, err, rc = self.run_cmd('history list', expected_rc=255)
41
error_message = (
42
'No commands were found in your history. Make sure you have '
43
'enabled history mode by adding "cli_history = enabled" '
44
'to the config file.'
45
)
46
self.assertEqual('', ensure_text_type(out))
47
self.assertEqual('\n%s\n' % error_message, ensure_text_type(err))
48
49
def test_show_one_call_present(self):
50
self.parsed_responses = [
51
{
52
"Regions": [
53
{
54
"Endpoint": "ec2.ap-south-1.amazonaws.com",
55
"RegionName": "ap-south-1"
56
},
57
]
58
}
59
]
60
_, _, rc = self.run_cmd('ec2 describe-regions', expected_rc=0)
61
self.history_recorder.record('CLI_RC', rc, 'CLI')
62
self.run_cmd('history list', expected_rc=0)
63
self.assertIn(b'ec2 describe-regions', self.binary_stdout.getvalue())
64
65
def test_multiple_calls_present(self):
66
self.parsed_responses = [
67
{
68
"Regions": [
69
{
70
"Endpoint": "ec2.ap-south-1.amazonaws.com",
71
"RegionName": "ap-south-1"
72
},
73
]
74
},
75
{
76
"UserId": "foo",
77
"Account": "bar",
78
"Arn": "arn:aws:iam::1234567:user/baz"
79
}
80
]
81
_, _, rc = self.run_cmd('ec2 describe-regions', expected_rc=0)
82
self.history_recorder.record('CLI_RC', rc, 'CLI')
83
_, _, rc = self.run_cmd('sts get-caller-identity', expected_rc=0)
84
self.history_recorder.record('CLI_RC', rc, 'CLI')
85
self.run_cmd('history list', expected_rc=0)
86
self.assertIn(b'ec2 describe-regions',
87
self.binary_stdout.getvalue())
88
self.assertIn(b'sts get-caller-identity',
89
self.binary_stdout.getvalue())
90
91