Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/output/test_text_output.py
1567 views
1
#!/usr/bin/env python
2
# Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License"). You
5
# may not use this file except in compliance with the License. A copy of
6
# the License is located at
7
#
8
# http://aws.amazon.com/apache2.0/
9
#
10
# or in the "license" file accompanying this file. This file is
11
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
# ANY KIND, either express or implied. See the License for the specific
13
# language governing permissions and limitations under the License.
14
from awscli.testutils import BaseAWSCommandParamsTest
15
from awscli.testutils import mock, unittest
16
from awscli.compat import StringIO
17
import json
18
import os
19
import sys
20
import re
21
import locale
22
23
from awscli.formatter import Formatter
24
25
26
class TestListUsers(BaseAWSCommandParamsTest):
27
28
def setUp(self):
29
super(TestListUsers, self).setUp()
30
self.first_parsed_response = {
31
'Users': [
32
{
33
"UserName": "testuser-50",
34
"Path": "/",
35
"CreateDate": "2013-02-12T19:08:52Z",
36
"UserId": "EXAMPLEUSERID",
37
"Arn": "arn:aws:iam::12345:user/testuser1"
38
},
39
],
40
'Groups': []
41
}
42
self.second_parsed_response = {
43
'Users': [
44
{
45
"UserName": "testuser-51",
46
"Path": "/",
47
"CreateDate": "2012-10-14T23:53:39Z",
48
"UserId": "EXAMPLEUSERID",
49
"Arn": "arn:aws:iam::123456:user/testuser2"
50
},
51
],
52
'Groups': []
53
}
54
55
self.parsed_responses = [
56
self.first_parsed_response,
57
self.second_parsed_response
58
]
59
60
def test_text_response(self):
61
output = self.run_cmd('iam list-users --output text', expected_rc=0)[0]
62
self.assertEqual(
63
output,
64
('USERS\tarn:aws:iam::12345:user/testuser1\t2013-02-12T19:08:52Z\t'
65
'/\tEXAMPLEUSERID\ttestuser-50\n'))
66
67
# Test something with a jmespath expression.
68
output = self.run_cmd(
69
'rds describe-engine-default-parameters ' \
70
'--db-parameter-group-family mysql5.1 --output text',
71
expected_rc=0)[0]
72
self.assertEqual(
73
output,
74
'ENGINEDEFAULTS\tNone\n')
75
76
77
class TestDescribeChangesets(BaseAWSCommandParamsTest):
78
79
def setUp(self):
80
super(TestDescribeChangesets, self).setUp()
81
self.first_parsed_response = {
82
'Capabilities': ['CAPABILITY_IAM'],
83
'ChangeSetId': (
84
'arn:aws:cloudformation:us-west-2:12345:changeSet'
85
'/mychangeset/12345'
86
),
87
'ChangeSetName': 'mychangeset',
88
'Changes': [{"ChangeId": "1"}],
89
'CreationTime': '2019-04-08T14:21:53.765Z',
90
'ExecutionStatus': 'AVAILABLE',
91
'NotificationARNs': [],
92
'RollbackConfiguration': {'RollbackTriggers': []},
93
'StackId': (
94
'arn:aws:cloudformation:us-west-2:12345:stack'
95
'/MyStack/12345'
96
),
97
'StackName': 'MyStack',
98
'Status': 'CREATE_COMPLETE',
99
'NextToken': "more stuff"
100
}
101
self.second_parsed_response = {
102
'Capabilities': ['CAPABILITY_IAM'],
103
'ChangeSetId': (
104
'arn:aws:cloudformation:us-west-2:12345:changeSet'
105
'/mychangeset/12345'
106
),
107
'ChangeSetName': 'mychangeset',
108
'Changes': [{"ChangeId": "2"}],
109
'CreationTime': '2019-04-08T14:21:53.765Z',
110
'ExecutionStatus': 'AVAILABLE',
111
'NotificationARNs': [],
112
'RollbackConfiguration': {'RollbackTriggers': []},
113
'StackId': (
114
'arn:aws:cloudformation:us-west-2:12345:stack'
115
'/MyStack/12345'
116
),
117
'StackName': 'MyStack',
118
'Status': 'CREATE_COMPLETE'
119
}
120
self.parsed_responses = [
121
self.first_parsed_response,
122
self.second_parsed_response,
123
]
124
125
def test_non_aggregate_keys(self):
126
output = self.run_cmd(
127
('cloudformation describe-change-set --change-set-name mychangeset'
128
' --stack-name MyStack --output text'),
129
expected_rc=0
130
)[0]
131
fields = output.split()
132
self.assertIn((
133
"arn:aws:cloudformation:us-west-2:12345:changeSet/mychangeset/"
134
"12345"), fields)
135
self.assert_in("CAPABILITY_IAM", fields, 1)
136
self.assert_in("mychangeset", fields, 1)
137
self.assert_in("2019-04-08T14:21:53.765Z", fields, 1)
138
self.assert_in("AVAILABLE", fields, 1)
139
self.assert_in("MyStack", fields, 1)
140
self.assert_in("CREATE_COMPLETE", fields, 1)
141
142
def assert_in(self, key, fields, count=None):
143
if count is None:
144
self.assertIn(key, fields)
145
else:
146
actual_count = fields.count(key)
147
self.assertEqual(
148
count,
149
actual_count,
150
"%s was found in the output %s times. Expected %s." % (
151
key, actual_count, count
152
)
153
)
154
155