Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/functional/history/test_show.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 tests.functional.history import BaseHistoryCommandParamsTest
14
15
from awscli.testutils import create_clidriver, mock
16
17
18
class TestShowCommand(BaseHistoryCommandParamsTest):
19
def test_show_latest(self):
20
self.parsed_responses = [
21
{
22
"Regions": [
23
{
24
"Endpoint": "ec2.ap-south-1.amazonaws.com",
25
"RegionName": "ap-south-1"
26
},
27
]
28
}
29
]
30
self.run_cmd('ec2 describe-regions', expected_rc=0)
31
self.run_cmd('history show', expected_rc=0)
32
# Test that the CLI specific events are present such as arguments
33
# entered and version
34
#
35
# The show command writes the history out as binary to the attached
36
# stream so we want to determine if the values are in the binary
37
# stdout stream
38
self.assertIn(b'describe-regions', self.binary_stdout.getvalue())
39
self.assertIn(b'version', self.binary_stdout.getvalue())
40
41
def test_show_nothing_when_no_history(self):
42
self.environ['AWS_CONFIG_FILE'] = ''
43
self.driver = create_clidriver()
44
self.parsed_responses = [
45
{
46
"Regions": [
47
{
48
"Endpoint": "ec2.ap-south-1.amazonaws.com",
49
"RegionName": "ap-south-1"
50
},
51
]
52
}
53
]
54
self.run_cmd('ec2 describe-regions', expected_rc=0)
55
self.run_cmd('history show', expected_rc=0)
56
# The history show should not display anything as no history should
57
# have been collected
58
self.assertEqual(b'', self.binary_stdout.getvalue())
59
60
def test_show_with_include(self):
61
self.parsed_responses = [
62
{
63
"Regions": [
64
{
65
"Endpoint": "ec2.ap-south-1.amazonaws.com",
66
"RegionName": "ap-south-1"
67
},
68
]
69
}
70
]
71
self.run_cmd('ec2 describe-regions', expected_rc=0)
72
self.run_cmd('history show --include CLI_ARGUMENTS', expected_rc=0)
73
# Make sure the CLI version was not included because of the filter.
74
#
75
# The show command writes the history out as binary to the attached
76
# stream so we want to determine if the values are in the binary
77
# stdout stream
78
self.assertIn(b'describe-regions', self.binary_stdout.getvalue())
79
self.assertNotIn(b'version', self.binary_stdout.getvalue())
80
81
def test_show_with_exclude(self):
82
self.parsed_responses = [
83
{
84
"Regions": [
85
{
86
"Endpoint": "ec2.ap-south-1.amazonaws.com",
87
"RegionName": "ap-south-1"
88
},
89
]
90
}
91
]
92
self.run_cmd('ec2 describe-regions', expected_rc=0)
93
self.run_cmd('history show --exclude CLI_ARGUMENTS', expected_rc=0)
94
# Make sure the API call was not included because of the filter,
95
# but all other events such as the version are included.
96
#
97
# The show command writes the history out as binary to the attached
98
# stream so we want to determine if the values are in the binary
99
# stdout stream
100
self.assertNotIn(b'describe-regions', self.binary_stdout.getvalue())
101
self.assertIn(b'version', self.binary_stdout.getvalue())
102
103