FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
aws-cli/tests/unit/test_errorhandler.py at develop · apideveloper/aws-cli · GitHub
apideveloper
/
aws-cli
Public
forked from
aws/aws-cli
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
aws-cli
/
tests
/
unit
/
test_errorhandler.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
110 lines (101 loc) · 4.61 KB
Breadcrumbs
aws-cli
/
tests
/
unit
/
test_errorhandler.py
Copy path
File metadata and controls
110 lines (101 loc) · 4.61 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from
awscli
.
testutils
import
unittest
import
mock
from
awscli
import
errorhandler
class
TestErrorHandler
(
unittest
.
TestCase
):
def
create_http_response
(
self
,
**
kwargs
):
response
=
mock
.
Mock
()
for
key
,
value
in
kwargs
.
items
():
setattr
(
response
,
key
,
value
)
return
response
def
test_error_handler_client_side
(
self
):
response
=
{
'Error'
: {
'Code'
:
'AccessDenied'
,
'HostId'
:
'foohost'
,
'Message'
:
'Access Denied'
,
'RequestId'
:
'requestid'
},
'ResponseMetadata'
: {}}
handler
=
errorhandler
.
ErrorHandler
()
http_response
=
self
.
create_http_response
(
status_code
=
403
)
# We're manually using the try/except form because
# we want to catch the exception and assert that it has specific
# attributes on it.
operation
=
mock
.
Mock
()
operation
.
name
=
'OperationName'
try
:
handler
(
http_response
,
response
,
operation
)
except
errorhandler
.
ClientError
as
e
:
# First, the operation name should be in the error message.
self
.
assertIn
(
'OperationName'
,
str
(
e
))
# We should state that this is a ClientError.
self
.
assertIn
(
'client error'
,
str
(
e
))
# And these values should be available on the exception
# so clients can access this information programmatically.
self
.
assertEqual
(
e
.
error_code
,
'AccessDenied'
)
self
.
assertEqual
(
e
.
error_message
,
'Access Denied'
)
self
.
assertEqual
(
e
.
operation_name
,
'OperationName'
)
except
Exception
as
e
:
self
.
fail
(
"Unexpected error raised: %s"
%
e
)
else
:
self
.
fail
(
"Expected errorhandler.ClientError to be raised "
"but no exception was raised."
)
def
test_error_handler_server_side
(
self
):
response
=
{
'Error'
: {
'Code'
:
'InternalError'
,
'HostId'
:
'foohost'
,
'Message'
:
'An internal error has occurred'
,
'RequestId'
:
'requestid'
},
'ResponseMetadata'
: {}}
handler
=
errorhandler
.
ErrorHandler
()
http_response
=
self
.
create_http_response
(
status_code
=
500
)
# We're manually using the try/except form because
# we want to catch the exception and assert that it has specific
# attributes on it.
operation
=
mock
.
Mock
()
operation
.
name
=
'OperationName'
try
:
handler
(
http_response
,
response
,
operation
)
except
errorhandler
.
ServerError
as
e
:
# First, the operation name should be in the error message.
self
.
assertIn
(
'OperationName'
,
str
(
e
))
# We should state that this is a ServerError.
self
.
assertIn
(
'server error'
,
str
(
e
))
# And these values should be available on the exception
# so clients can access this information programmatically.
self
.
assertEqual
(
e
.
error_code
,
'InternalError'
)
self
.
assertEqual
(
e
.
error_message
,
'An internal error has occurred'
)
self
.
assertEqual
(
e
.
operation_name
,
'OperationName'
)
except
Exception
as
e
:
self
.
fail
(
"Unexpected error raised: %s"
%
e
)
else
:
self
.
fail
(
"Expected errorhandler.ServerError to be raised "
"but no exception was raised."
)
def
test_no_exception_raised_on_200
(
self
):
response
=
{
'CommonPrefixes'
: [],
'Contents'
: [],
}
handler
=
errorhandler
.
ErrorHandler
()
http_response
=
self
.
create_http_response
(
status_code
=
200
)
# We're manually using the try/except form because
# we want to catch the exception and assert that it has specific
# attributes on it.
operation
=
mock
.
Mock
()
operation
.
name
=
'OperationName'
try
:
self
.
assertIsNone
(
handler
(
http_response
,
response
,
operation
))
except
errorhandler
.
BaseOperationError
as
e
:
self
.
fail
(
"Unexpected error raised: %s"
%
e
)
if
__name__
==
'__main__'
:
unittest
.
main
()
Back
|
FazBrowse Home
|
New Git URL