FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
aws-cli/tests/unit/test_paramfile.py at develop · lovejavaee/aws-cli · GitHub
lovejavaee
/
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
1
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_paramfile.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
157 lines (125 loc) · 5.9 KB
Breadcrumbs
aws-cli
/
tests
/
unit
/
test_paramfile.py
Copy path
File metadata and controls
157 lines (125 loc) · 5.9 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# 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
.
compat
import
six
from
awscli
.
testutils
import
mock
,
unittest
,
FileCreator
from
awscli
.
testutils
import
skip_if_windows
from
awscli
.
paramfile
import
get_paramfile
,
ResourceLoadingError
from
awscli
.
paramfile
import
LOCAL_PREFIX_MAP
,
REMOTE_PREFIX_MAP
from
awscli
.
paramfile
import
register_uri_param_handler
from
botocore
.
session
import
Session
from
botocore
.
exceptions
import
ProfileNotFound
class
TestParamFile
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
files
=
FileCreator
()
def
tearDown
(
self
):
self
.
files
.
remove_all
()
def
get_paramfile
(
self
,
path
):
return
get_paramfile
(
path
,
LOCAL_PREFIX_MAP
.
copy
())
def
test_text_file
(
self
):
contents
=
'This is a test'
filename
=
self
.
files
.
create_file
(
'foo'
,
contents
)
prefixed_filename
=
'file://'
+
filename
data
=
self
.
get_paramfile
(
prefixed_filename
)
self
.
assertEqual
(
data
,
contents
)
self
.
assertIsInstance
(
data
,
six
.
string_types
)
def
test_binary_file
(
self
):
contents
=
'This is a test'
filename
=
self
.
files
.
create_file
(
'foo'
,
contents
)
prefixed_filename
=
'fileb://'
+
filename
data
=
self
.
get_paramfile
(
prefixed_filename
)
self
.
assertEqual
(
data
,
b'This is a test'
)
self
.
assertIsInstance
(
data
,
six
.
binary_type
)
@
skip_if_windows
(
'Binary content error only occurs '
'on non-Windows platforms.'
)
def
test_cannot_load_text_file
(
self
):
contents
=
b'
\xbf
X
\xac
\xbe
'
filename
=
self
.
files
.
create_file
(
'foo'
,
contents
,
mode
=
'wb'
)
prefixed_filename
=
'file://'
+
filename
with
self
.
assertRaises
(
ResourceLoadingError
):
self
.
get_paramfile
(
prefixed_filename
)
def
test_file_does_not_exist_raises_error
(
self
):
with
self
.
assertRaises
(
ResourceLoadingError
):
self
.
get_paramfile
(
'file://file/does/not/existsasdf.txt'
)
def
test_no_match_uris_returns_none
(
self
):
self
.
assertIsNone
(
self
.
get_paramfile
(
'foobar://somewhere.bar'
))
def
test_non_string_type_returns_none
(
self
):
self
.
assertIsNone
(
self
.
get_paramfile
(
100
))
class
TestHTTPBasedResourceLoading
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
session_patch
=
mock
.
patch
(
'awscli.paramfile.URLLib3Session.send'
)
self
.
session_mock
=
self
.
session_patch
.
start
()
self
.
response
=
mock
.
Mock
(
status_code
=
200
)
self
.
session_mock
.
return_value
=
self
.
response
def
tearDown
(
self
):
self
.
session_patch
.
stop
()
def
get_paramfile
(
self
,
path
):
return
get_paramfile
(
path
,
REMOTE_PREFIX_MAP
.
copy
())
def
test_resource_from_http
(
self
):
self
.
response
.
text
=
'http contents'
loaded
=
self
.
get_paramfile
(
'http://foo.bar.baz'
)
self
.
assertEqual
(
loaded
,
'http contents'
)
def
test_resource_from_https
(
self
):
self
.
response
.
text
=
'http contents'
loaded
=
self
.
get_paramfile
(
'https://foo.bar.baz'
)
self
.
assertEqual
(
loaded
,
'http contents'
)
def
test_non_200_raises_error
(
self
):
self
.
response
.
status_code
=
500
with
self
.
assertRaisesRegex
(
ResourceLoadingError
,
'foo\.bar\.baz'
):
self
.
get_paramfile
(
'https://foo.bar.baz'
)
def
test_connection_error_raises_error
(
self
):
self
.
session_mock
.
side_effect
=
Exception
(
"Connection error."
)
with
self
.
assertRaisesRegex
(
ResourceLoadingError
,
'foo\.bar\.baz'
):
self
.
get_paramfile
(
'https://foo.bar.baz'
)
class
TestConfigureURIArgumentHandler
(
unittest
.
TestCase
):
@
mock
.
patch
(
'awscli.paramfile.URIArgumentHandler'
)
def
test_profile_not_found
(
self
,
mock_handler_cls
):
session
=
mock
.
Mock
(
spec
=
Session
)
session
.
get_scoped_config
.
side_effect
=
ProfileNotFound
(
profile
=
'foo'
)
register_uri_param_handler
(
session
)
cases
=
mock_handler_cls
.
call_args
[
0
][
0
]
self
.
assertIn
(
'file://'
,
cases
)
self
.
assertIn
(
'fileb://'
,
cases
)
self
.
assertIn
(
'http://'
,
cases
)
self
.
assertIn
(
'http://'
,
cases
)
@
mock
.
patch
(
'awscli.paramfile.URIArgumentHandler'
)
def
test_missing_config_value
(
self
,
mock_handler_cls
):
session
=
mock
.
Mock
(
spec
=
Session
)
session
.
get_scoped_config
.
return_value
=
{}
register_uri_param_handler
(
session
)
cases
=
mock_handler_cls
.
call_args
[
0
][
0
]
self
.
assertIn
(
'file://'
,
cases
)
self
.
assertIn
(
'fileb://'
,
cases
)
self
.
assertIn
(
'http://'
,
cases
)
self
.
assertIn
(
'http://'
,
cases
)
@
mock
.
patch
(
'awscli.paramfile.URIArgumentHandler'
)
def
test_config_value_true
(
self
,
mock_handler_cls
):
session
=
mock
.
Mock
(
spec
=
Session
)
session
.
get_scoped_config
.
return_value
=
{
'cli_follow_urlparam'
:
'true'
}
register_uri_param_handler
(
session
)
cases
=
mock_handler_cls
.
call_args
[
0
][
0
]
self
.
assertIn
(
'file://'
,
cases
)
self
.
assertIn
(
'fileb://'
,
cases
)
self
.
assertIn
(
'http://'
,
cases
)
self
.
assertIn
(
'http://'
,
cases
)
@
mock
.
patch
(
'awscli.paramfile.URIArgumentHandler'
)
def
test_config_value_false
(
self
,
mock_handler_cls
):
session
=
mock
.
Mock
(
spec
=
Session
)
session
.
get_scoped_config
.
return_value
=
{
'cli_follow_urlparam'
:
'false'
}
register_uri_param_handler
(
session
)
cases
=
mock_handler_cls
.
call_args
[
0
][
0
]
self
.
assertIn
(
'file://'
,
cases
)
self
.
assertIn
(
'fileb://'
,
cases
)
self
.
assertNotIn
(
'http://'
,
cases
)
self
.
assertNotIn
(
'http://'
,
cases
)
Back
|
FazBrowse Home
|
New Git URL