Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: third_party/boto/tests/unit/mws/test_connection.py

Issue 698893003: Update checked in version of gsutil to version 4.6 (Closed) Base URL: http://dart.googlecode.com/svn/third_party/gsutil/
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved 2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved
3 # 3 #
4 # Permission is hereby granted, free of charge, to any person obtaining a 4 # Permission is hereby granted, free of charge, to any person obtaining a
5 # copy of this software and associated documentation files (the 5 # copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including 6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish, dis- 7 # without limitation the rights to use, copy, modify, merge, publish, dis-
8 # tribute, sublicense, and/or sell copies of the Software, and to permit 8 # tribute, sublicense, and/or sell copies of the Software, and to permit
9 # persons to whom the Software is furnished to do so, subject to the fol- 9 # persons to whom the Software is furnished to do so, subject to the fol-
10 # lowing conditions: 10 # lowing conditions:
11 # 11 #
12 # The above copyright notice and this permission notice shall be included 12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software. 13 # in all copies or substantial portions of the Software.
14 # 14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- 16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 # IN THE SOFTWARE. 21 # IN THE SOFTWARE.
22 # 22 #
23 from boto.mws.connection import MWSConnection, api_call_map, destructure_object 23 from boto.mws.connection import MWSConnection, api_call_map, destructure_object
24 from boto.mws.response import ResponseElement 24 from boto.mws.response import (ResponseElement, GetFeedSubmissionListResult,
25 ResponseFactory)
25 26
26 from tests.unit import AWSMockServiceTestCase 27 from tests.unit import AWSMockServiceTestCase
27 28
28 29
29 class TestMWSConnection(AWSMockServiceTestCase): 30 class TestMWSConnection(AWSMockServiceTestCase):
30 connection_class = MWSConnection 31 connection_class = MWSConnection
31 mws = True 32 mws = True
32 33
33 def default_body(self): 34 def default_body(self):
34 return """<?xml version="1.0"?> 35 return """<?xml version="1.0"?>
35 <GetFeedSubmissionListResponse xmlns="http://mws.amazonservices.com/ 36 <GetFeedSubmissionListResponse xmlns="http://mws.amazonservices.com/
36 doc/2009-01-01/"> 37 doc/2009-01-01/">
37 <GetFeedSubmissionListResult> 38 <GetFeedSubmissionListResult>
38 <NextToken>2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=</NextToken> 39 <NextToken>2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=</NextToken>
39 <HasNext>true</HasNext> 40 <HasNext>true</HasNext>
40 <FeedSubmissionInfo> 41 <FeedSubmissionInfo>
41 <FeedSubmissionId>2291326430</FeedSubmissionId> 42 <FeedSubmissionId>2291326430</FeedSubmissionId>
42 <FeedType>_POST_PRODUCT_DATA_</FeedType> 43 <FeedType>_POST_PRODUCT_DATA_</FeedType>
43 <SubmittedDate>2009-02-20T02:10:35+00:00</SubmittedDate> 44 <SubmittedDate>2009-02-20T02:10:35+00:00</SubmittedDate>
44 <FeedProcessingStatus>_SUBMITTED_</FeedProcessingStatus> 45 <FeedProcessingStatus>_SUBMITTED_</FeedProcessingStatus>
45 </FeedSubmissionInfo> 46 </FeedSubmissionInfo>
46 </GetFeedSubmissionListResult> 47 </GetFeedSubmissionListResult>
47 <ResponseMetadata> 48 <ResponseMetadata>
48 <RequestId>1105b931-6f1c-4480-8e97-f3b467840a9e</RequestId> 49 <RequestId>1105b931-6f1c-4480-8e97-f3b467840a9e</RequestId>
49 </ResponseMetadata> 50 </ResponseMetadata>
50 </GetFeedSubmissionListResponse>""" 51 </GetFeedSubmissionListResponse>"""
51 52
52 def test_destructure_object(self): 53 def test_destructure_object(self):
53 # Test that parsing of user input to Amazon input works. 54 # Test that parsing of user input to Amazon input works.
54 response = ResponseElement(name='Prefix') 55 response = ResponseElement()
55 response.C = 'four' 56 response.C = 'four'
56 response.D = 'five' 57 response.D = 'five'
57 inputs = [ 58 inputs = [
58 ('A', 'B'), ['B', 'A'], set(['C']), 59 ('A', 'B'), ['B', 'A'], set(['C']),
59 False, 'String', {'A': 'one', 'B': 'two'}, 60 False, 'String', {'A': 'one', 'B': 'two'},
60 response, 61 response,
62 {'A': 'one', 'B': 'two',
63 'C': [{'D': 'four', 'E': 'five'},
64 {'F': 'six', 'G': 'seven'}]},
61 ] 65 ]
62 outputs = [ 66 outputs = [
63 {'Prefix.1': 'A', 'Prefix.2': 'B'}, 67 {'Prefix.1': 'A', 'Prefix.2': 'B'},
64 {'Prefix.1': 'B', 'Prefix.2': 'A'}, 68 {'Prefix.1': 'B', 'Prefix.2': 'A'},
65 {'Prefix.1': 'C'}, 69 {'Prefix.1': 'C'},
66 {'Prefix': 'false'}, {'Prefix': 'String'}, 70 {'Prefix': 'false'}, {'Prefix': 'String'},
67 {'Prefix.A': 'one', 'Prefix.B': 'two'}, 71 {'Prefix.A': 'one', 'Prefix.B': 'two'},
68 {'Prefix.C': 'four', 'Prefix.D': 'five'}, 72 {'Prefix.C': 'four', 'Prefix.D': 'five'},
73 {'Prefix.A': 'one', 'Prefix.B': 'two',
74 'Prefix.C.member.1.D': 'four',
75 'Prefix.C.member.1.E': 'five',
76 'Prefix.C.member.2.F': 'six',
77 'Prefix.C.member.2.G': 'seven'}
69 ] 78 ]
70 for user, amazon in zip(inputs, outputs): 79 for user, amazon in zip(inputs, outputs):
71 result = {} 80 result = {}
72 destructure_object(user, result, prefix='Prefix') 81 members = user is inputs[-1]
82 destructure_object(user, result, prefix='Prefix', members=members)
73 self.assertEqual(result, amazon) 83 self.assertEqual(result, amazon)
74 84
75 def test_built_api_call_map(self): 85 def test_built_api_call_map(self):
76 # Ensure that the map is populated. 86 # Ensure that the map is populated.
77 # It starts empty, but the decorators should add to it as they're 87 # It starts empty, but the decorators should add to it as they're
78 # applied. As of 2013/10/21, there were 52 calls (with more likely 88 # applied. As of 2013/10/21, there were 52 calls (with more likely
79 # to be added), so let's simply ensure there are enough there. 89 # to be added), so let's simply ensure there are enough there.
80 self.assertTrue(len(api_call_map.keys()) > 50) 90 self.assertTrue(len(api_call_map.keys()) > 50)
81 91
82 def test_method_for(self): 92 def test_method_for(self):
83 # First, ensure that the map is in "right enough" state. 93 # First, ensure that the map is in "right enough" state.
84 self.assertTrue('GetFeedSubmissionList' in api_call_map) 94 self.assertTrue('GetFeedSubmissionList' in api_call_map)
85 95
86 # Make sure we can find the correct method. 96 # Make sure we can find the correct method.
87 func = self.service_connection.method_for('GetFeedSubmissionList') 97 func = self.service_connection.method_for('GetFeedSubmissionList')
88 # Ensure the right name was found. 98 # Ensure the right name was found.
89 self.assertTrue(callable(func)) 99 self.assertTrue(callable(func))
90 ideal = self.service_connection.get_feed_submission_list 100 ideal = self.service_connection.get_feed_submission_list
91 self.assertEqual(func, ideal) 101 self.assertEqual(func, ideal)
92 102
93 # Check a non-existent action. 103 # Check a non-existent action.
94 func = self.service_connection.method_for('NotHereNorThere') 104 func = self.service_connection.method_for('NotHereNorThere')
95 self.assertEqual(func, None) 105 self.assertEqual(func, None)
96 106
107 def test_response_factory(self):
108 connection = self.service_connection
109 body = self.default_body()
110 action = 'GetFeedSubmissionList'
111 parser = connection._response_factory(action, connection=connection)
112 response = connection._parse_response(parser, 'text/xml', body)
113 self.assertEqual(response._action, action)
114 self.assertEqual(response.__class__.__name__, action + 'Response')
115 self.assertEqual(response._result.__class__,
116 GetFeedSubmissionListResult)
117
118 class MyResult(GetFeedSubmissionListResult):
119 _hello = '_world'
120
121 scope = {'GetFeedSubmissionListResult': MyResult}
122 connection._setup_factories([scope])
123
124 parser = connection._response_factory(action, connection=connection)
125 response = connection._parse_response(parser, 'text/xml', body)
126 self.assertEqual(response._action, action)
127 self.assertEqual(response.__class__.__name__, action + 'Response')
128 self.assertEqual(response._result.__class__, MyResult)
129 self.assertEqual(response._result._hello, '_world')
130 self.assertEqual(response._result.HasNext, 'true')
131
97 def test_get_service_status(self): 132 def test_get_service_status(self):
98 with self.assertRaises(AttributeError) as err: 133 with self.assertRaises(AttributeError) as err:
99 self.service_connection.get_service_status() 134 self.service_connection.get_service_status()
100 135
101 self.assertTrue('products,' in str(err.exception)) 136 self.assertTrue('products,' in str(err.exception))
102 self.assertTrue('inventory,' in str(err.exception)) 137 self.assertTrue('inventory,' in str(err.exception))
103 self.assertTrue('feeds,' in str(err.exception)) 138 self.assertTrue('feeds,' in str(err.exception))
104 139
105 140
106 if __name__ == '__main__': 141 if __name__ == '__main__':
107 unittest.main() 142 unittest.main()
OLDNEW
« no previous file with comments | « third_party/boto/tests/unit/iam/test_connection.py ('k') | third_party/boto/tests/unit/mws/test_response.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698