Merge lp:~facundo/ubuntu-rest-scopes/limit-ebay-limits into lp:ubuntu-rest-scopes
- limit-ebay-limits
- Merge into trunk
Proposed by
Facundo Batista
Status: | Merged |
---|---|
Approved by: | Facundo Batista |
Approved revision: | 523 |
Merged at revision: | 523 |
Proposed branch: | lp:~facundo/ubuntu-rest-scopes/limit-ebay-limits |
Merge into: | lp:ubuntu-rest-scopes |
Diff against target: |
221 lines (+72/-22) 2 files modified
src/scopes/ebay.py (+7/-2) src/scopes/tests/test_ebay.py (+65/-20) |
To merge this branch: | bzr merge lp:~facundo/ubuntu-rest-scopes/limit-ebay-limits |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Roberto Alsina (community) | Approve | ||
Review via email: mp+296037@code.launchpad.net |
Commit message
Limit the limits sent to ebay.
Description of the change
Limit the limits sent to ebay.
To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) : | # |
review:
Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/scopes/ebay.py' | |||
2 | --- src/scopes/ebay.py 2015-03-30 17:34:32 +0000 | |||
3 | +++ src/scopes/ebay.py 2016-05-30 12:24:27 +0000 | |||
4 | @@ -1,4 +1,4 @@ | |||
6 | 1 | # Copyright 2014-2015 Canonical | 1 | # Copyright 2014-2016 Canonical |
7 | 2 | # All Rights Reserved | 2 | # All Rights Reserved |
8 | 3 | 3 | ||
9 | 4 | """The eBay scope.""" | 4 | """The eBay scope.""" |
10 | @@ -19,6 +19,9 @@ | |||
11 | 19 | 19 | ||
12 | 20 | logger = logging.getLogger("restscopes.ebay") | 20 | logger = logging.getLogger("restscopes.ebay") |
13 | 21 | 21 | ||
14 | 22 | # don't send limits more than this or ebay will complain | ||
15 | 23 | MAX_LIMIT = 100 | ||
16 | 24 | |||
17 | 22 | SEARCH_URI = ('https://svcs.ebay.com/services/search/FindingService/v1' | 25 | SEARCH_URI = ('https://svcs.ebay.com/services/search/FindingService/v1' |
18 | 23 | '?SECURITY-APPNAME=%(key)s&OPERATION-NAME=findItemsByKeywords' | 26 | '?SECURITY-APPNAME=%(key)s&OPERATION-NAME=findItemsByKeywords' |
19 | 24 | '&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON' | 27 | '&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON' |
20 | @@ -77,7 +80,7 @@ | |||
21 | 77 | 'PL': {'pl_PL': (212, 'EBAY-PL')}, | 80 | 'PL': {'pl_PL': (212, 'EBAY-PL')}, |
22 | 78 | 'SG': {'en_SG': (216, 'EBAY-SG')}, | 81 | 'SG': {'en_SG': (216, 'EBAY-SG')}, |
23 | 79 | 'US': {'en_US': (0, 'EBAY-US')}, | 82 | 'US': {'en_US': (0, 'EBAY-US')}, |
25 | 80 | } | 83 | } |
26 | 81 | 84 | ||
27 | 82 | FILTERS = {'Condition', 'MaxPrice', 'MinPrice', 'SellerBusinessType', | 85 | FILTERS = {'Condition', 'MaxPrice', 'MinPrice', 'SellerBusinessType', |
28 | 83 | 'EndTimeTo', 'TopRatedSellerOnly'} | 86 | 'EndTimeTo', 'TopRatedSellerOnly'} |
29 | @@ -598,6 +601,8 @@ | |||
30 | 598 | def search(self, **kwargs): | 601 | def search(self, **kwargs): |
31 | 599 | """Do the search.""" | 602 | """Do the search.""" |
32 | 600 | limit = kwargs['limit'] | 603 | limit = kwargs['limit'] |
33 | 604 | if limit > MAX_LIMIT: | ||
34 | 605 | limit = MAX_LIMIT | ||
35 | 601 | locale = kwargs['locale'] | 606 | locale = kwargs['locale'] |
36 | 602 | country = kwargs.get('country') | 607 | country = kwargs.get('country') |
37 | 603 | query = urllib.quote(kwargs['query'].encode('utf-8')) | 608 | query = urllib.quote(kwargs['query'].encode('utf-8')) |
38 | 604 | 609 | ||
39 | === modified file 'src/scopes/tests/test_ebay.py' | |||
40 | --- src/scopes/tests/test_ebay.py 2015-02-26 19:13:53 +0000 | |||
41 | +++ src/scopes/tests/test_ebay.py 2016-05-30 12:24:27 +0000 | |||
42 | @@ -1,6 +1,6 @@ | |||
43 | 1 | # -*- coding: utf8 -*- | 1 | # -*- coding: utf8 -*- |
44 | 2 | 2 | ||
46 | 3 | # Copyright 2014 Canonical | 3 | # Copyright 2014-2016 Canonical |
47 | 4 | # All Rights Reserved | 4 | # All Rights Reserved |
48 | 5 | 5 | ||
49 | 6 | """Tests for the Simple App base stuff.""" | 6 | """Tests for the Simple App base stuff.""" |
50 | @@ -22,7 +22,7 @@ | |||
51 | 22 | '?SECURITY-APPNAME=hush&OPERATION-NAME=findItemsByKeywords' | 22 | '?SECURITY-APPNAME=hush&OPERATION-NAME=findItemsByKeywords' |
52 | 23 | '&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON' | 23 | '&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON' |
53 | 24 | '&GLOBAL-ID=EBAY-US&REST-PAYLOAD' | 24 | '&GLOBAL-ID=EBAY-US&REST-PAYLOAD' |
55 | 25 | '&keywords=paris&paginationInput.entriesPerPage=10' | 25 | '&keywords=paris&paginationInput.entriesPerPage={limit}' |
56 | 26 | '&outputSelector(0)=PictureURLSuperSize' | 26 | '&outputSelector(0)=PictureURLSuperSize' |
57 | 27 | '&outputSelector(1)=PictureURLLarge' | 27 | '&outputSelector(1)=PictureURLLarge' |
58 | 28 | '&affiliate.networkId=9&affiliate.trackingId=campid') | 28 | '&affiliate.networkId=9&affiliate.trackingId=campid') |
59 | @@ -30,14 +30,14 @@ | |||
60 | 30 | TEST_SURFACING_URI = ( | 30 | TEST_SURFACING_URI = ( |
61 | 31 | 'http://open.api.ebay.com/shopping?callname=FindPopularItems' | 31 | 'http://open.api.ebay.com/shopping?callname=FindPopularItems' |
62 | 32 | '&responseencoding=JSON&appid=hush&siteid=0&version=531&' | 32 | '&responseencoding=JSON&appid=hush&siteid=0&version=531&' |
64 | 33 | 'CategoryID=550&MaxEntries=10&trackingpartnercode=9&trackingid=campid') | 33 | 'CategoryID=550&MaxEntries={limit}&trackingpartnercode=9&trackingid=campid') |
65 | 34 | 34 | ||
66 | 35 | TEST_SORTING_URI = ( | 35 | TEST_SORTING_URI = ( |
67 | 36 | 'https://svcs.ebay.com/services/search/FindingService/v1' | 36 | 'https://svcs.ebay.com/services/search/FindingService/v1' |
68 | 37 | '?SECURITY-APPNAME=hush&OPERATION-NAME=findItemsByCategory' | 37 | '?SECURITY-APPNAME=hush&OPERATION-NAME=findItemsByCategory' |
69 | 38 | '&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON' | 38 | '&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON' |
70 | 39 | '&GLOBAL-ID=EBAY-US&REST-PAYLOAD' | 39 | '&GLOBAL-ID=EBAY-US&REST-PAYLOAD' |
72 | 40 | '&categoryId=550&sortOrder=SomeSorting&paginationInput.entriesPerPage=10' | 40 | '&categoryId=550&sortOrder=SomeSorting&paginationInput.entriesPerPage={limit}' |
73 | 41 | '&outputSelector(0)=PictureURLSuperSize&outputSelector(1)=PictureURLLarge' | 41 | '&outputSelector(0)=PictureURLSuperSize&outputSelector(1)=PictureURLLarge' |
74 | 42 | '&itemFilter.name=ListingType&itemFilter.value=Auction' | 42 | '&itemFilter.name=ListingType&itemFilter.value=Auction' |
75 | 43 | '&affiliate.networkId=9&affiliate.trackingId=campid') | 43 | '&affiliate.networkId=9&affiliate.trackingId=campid') |
76 | @@ -61,7 +61,7 @@ | |||
77 | 61 | response = list(app.search(**STD_KWARGS)) | 61 | response = list(app.search(**STD_KWARGS)) |
78 | 62 | 62 | ||
79 | 63 | # got the info as it should | 63 | # got the info as it should |
81 | 64 | mock.assert_called_with(TEST_SEARCH_URI) | 64 | mock.assert_called_with(TEST_SEARCH_URI.format(limit=STD_KWARGS['limit'])) |
82 | 65 | 65 | ||
83 | 66 | # category | 66 | # category |
84 | 67 | category_mock = ebay.PRODUCTS_CATEGORY.copy() | 67 | category_mock = ebay.PRODUCTS_CATEGORY.copy() |
85 | @@ -96,12 +96,25 @@ | |||
86 | 96 | }} | 96 | }} |
87 | 97 | self.assertEqual(response[1], should_res) | 97 | self.assertEqual(response[1], should_res) |
88 | 98 | 98 | ||
89 | 99 | def test_product_limit_limit(self): | ||
90 | 100 | std_kwargs = STD_KWARGS.copy() | ||
91 | 101 | std_kwargs['limit'] = 300 # too big! | ||
92 | 102 | app = ebay.App(CONFIG) | ||
93 | 103 | with patch.object(app, '_get_products') as mock: | ||
94 | 104 | with patch.object(app, '_get_available_departments') as mdep: | ||
95 | 105 | mdep.return_value = {}, () | ||
96 | 106 | mock.return_value = get_fixture('ebay-results.json') | ||
97 | 107 | list(app.search(**std_kwargs)) | ||
98 | 108 | |||
99 | 109 | # got the info as it should | ||
100 | 110 | mock.assert_called_with(TEST_SEARCH_URI.format(limit=ebay.MAX_LIMIT)) # limit limited! | ||
101 | 111 | |||
102 | 99 | def test_surfacing(self): | 112 | def test_surfacing(self): |
103 | 100 | app = ebay.App(CONFIG) | 113 | app = ebay.App(CONFIG) |
104 | 101 | with nested( | 114 | with nested( |
108 | 102 | patch.object(app, '_get_products'), | 115 | patch.object(app, '_get_products'), |
109 | 103 | patch.object(app, '_get_available_departments'), | 116 | patch.object(app, '_get_available_departments'), |
110 | 104 | ) as (mock, mdep): | 117 | ) as (mock, mdep): |
111 | 105 | mdep.return_value = {}, ('550', 'Foo') | 118 | mdep.return_value = {}, ('550', 'Foo') |
112 | 106 | mock.return_value = get_fixture('ebay-surfacing.json') | 119 | mock.return_value = get_fixture('ebay-surfacing.json') |
113 | 107 | kwargs = STD_KWARGS.copy() | 120 | kwargs = STD_KWARGS.copy() |
114 | @@ -109,7 +122,7 @@ | |||
115 | 109 | response = list(app.search(**kwargs)) | 122 | response = list(app.search(**kwargs)) |
116 | 110 | 123 | ||
117 | 111 | # got the info as it should | 124 | # got the info as it should |
119 | 112 | mock.assert_called_with(TEST_SURFACING_URI) | 125 | mock.assert_called_with(TEST_SURFACING_URI.format(limit=STD_KWARGS['limit'])) |
120 | 113 | 126 | ||
121 | 114 | # department and filter | 127 | # department and filter |
122 | 115 | self.assertEqual(response[0].keys()[0], 'departments') | 128 | self.assertEqual(response[0].keys()[0], 'departments') |
123 | @@ -146,12 +159,28 @@ | |||
124 | 146 | 159 | ||
125 | 147 | })) | 160 | })) |
126 | 148 | 161 | ||
127 | 162 | def test_surfacing_limit_limited(self): | ||
128 | 163 | app = ebay.App(CONFIG) | ||
129 | 164 | with nested( | ||
130 | 165 | patch.object(app, '_get_products'), | ||
131 | 166 | patch.object(app, '_get_available_departments'), | ||
132 | 167 | ) as (mock, mdep): | ||
133 | 168 | mdep.return_value = {}, ('550', 'Foo') | ||
134 | 169 | mock.return_value = get_fixture('ebay-surfacing.json') | ||
135 | 170 | kwargs = STD_KWARGS.copy() | ||
136 | 171 | kwargs['query'] = '' | ||
137 | 172 | kwargs['limit'] = 300 | ||
138 | 173 | list(app.search(**kwargs)) | ||
139 | 174 | |||
140 | 175 | # got the info as it should | ||
141 | 176 | mock.assert_called_with(TEST_SURFACING_URI.format(limit=ebay.MAX_LIMIT)) | ||
142 | 177 | |||
143 | 149 | def test_surfacing_no_img(self): | 178 | def test_surfacing_no_img(self): |
144 | 150 | app = ebay.App(CONFIG) | 179 | app = ebay.App(CONFIG) |
145 | 151 | with nested( | 180 | with nested( |
149 | 152 | patch.object(app, '_get_products'), | 181 | patch.object(app, '_get_products'), |
150 | 153 | patch.object(app, '_get_available_departments'), | 182 | patch.object(app, '_get_available_departments'), |
151 | 154 | ) as (mock, mdep): | 183 | ) as (mock, mdep): |
152 | 155 | mdep.return_value = {}, ('550', 'Bar') | 184 | mdep.return_value = {}, ('550', 'Bar') |
153 | 156 | mock.return_value = get_fixture('ebay-surfacing-no-img.json') | 185 | mock.return_value = get_fixture('ebay-surfacing-no-img.json') |
154 | 157 | kwargs = STD_KWARGS.copy() | 186 | kwargs = STD_KWARGS.copy() |
155 | @@ -159,7 +188,7 @@ | |||
156 | 159 | response = list(app.search(**kwargs)) | 188 | response = list(app.search(**kwargs)) |
157 | 160 | 189 | ||
158 | 161 | # got the info as it should | 190 | # got the info as it should |
160 | 162 | mock.assert_called_with(TEST_SURFACING_URI) | 191 | mock.assert_called_with(TEST_SURFACING_URI.format(limit=STD_KWARGS['limit'])) |
161 | 163 | 192 | ||
162 | 164 | # department and filter | 193 | # department and filter |
163 | 165 | self.assertEqual(response[0].keys()[0], 'departments') | 194 | self.assertEqual(response[0].keys()[0], 'departments') |
164 | @@ -207,9 +236,9 @@ | |||
165 | 207 | app = ebay.App(CONFIG) | 236 | app = ebay.App(CONFIG) |
166 | 208 | filters = {ebay.SORTING_ID: ['SomeSorting']} | 237 | filters = {ebay.SORTING_ID: ['SomeSorting']} |
167 | 209 | with nested( | 238 | with nested( |
171 | 210 | patch.object(app, '_get_products'), | 239 | patch.object(app, '_get_products'), |
172 | 211 | patch.object(app, '_get_available_departments'), | 240 | patch.object(app, '_get_available_departments'), |
173 | 212 | ) as (mock, mdep): | 241 | ) as (mock, mdep): |
174 | 213 | mdep.return_value = {}, ('550', 'Bar') | 242 | mdep.return_value = {}, ('550', 'Bar') |
175 | 214 | mock.return_value = get_fixture('ebay-results-sorting.json') | 243 | mock.return_value = get_fixture('ebay-results-sorting.json') |
176 | 215 | kwargs = STD_KWARGS.copy() | 244 | kwargs = STD_KWARGS.copy() |
177 | @@ -217,7 +246,7 @@ | |||
178 | 217 | response = list(app.search(**kwargs)) | 246 | response = list(app.search(**kwargs)) |
179 | 218 | 247 | ||
180 | 219 | # got the info as it should | 248 | # got the info as it should |
182 | 220 | mock.assert_called_with(TEST_SORTING_URI) | 249 | mock.assert_called_with(TEST_SORTING_URI.format(limit=STD_KWARGS['limit'])) |
183 | 221 | 250 | ||
184 | 222 | # department and filter | 251 | # department and filter |
185 | 223 | self.assertEqual(response[0].keys()[0], 'departments') | 252 | self.assertEqual(response[0].keys()[0], 'departments') |
186 | @@ -226,6 +255,22 @@ | |||
187 | 226 | self.assertEqual(response[1]['category']['title'], "Bar") | 255 | self.assertEqual(response[1]['category']['title'], "Bar") |
188 | 227 | self.assertEqual(len(response), 7) | 256 | self.assertEqual(len(response), 7) |
189 | 228 | 257 | ||
190 | 258 | def test_surfacing_filters_limit_limited(self): | ||
191 | 259 | app = ebay.App(CONFIG) | ||
192 | 260 | filters = {ebay.SORTING_ID: ['SomeSorting']} | ||
193 | 261 | with nested( | ||
194 | 262 | patch.object(app, '_get_products'), | ||
195 | 263 | patch.object(app, '_get_available_departments'), | ||
196 | 264 | ) as (mock, mdep): | ||
197 | 265 | mdep.return_value = {}, ('550', 'Bar') | ||
198 | 266 | mock.return_value = get_fixture('ebay-results-sorting.json') | ||
199 | 267 | kwargs = STD_KWARGS.copy() | ||
200 | 268 | kwargs.update(query='', filters=filters, limit=300) | ||
201 | 269 | list(app.search(**kwargs)) | ||
202 | 270 | |||
203 | 271 | # got the info as it should | ||
204 | 272 | mock.assert_called_with(TEST_SORTING_URI.format(limit=ebay.MAX_LIMIT)) | ||
205 | 273 | |||
206 | 229 | def test_filters(self): | 274 | def test_filters(self): |
207 | 230 | filters = {"MaxPrice": 5000, | 275 | filters = {"MaxPrice": 5000, |
208 | 231 | "MinPrice": [10, 30], | 276 | "MinPrice": [10, 30], |
209 | @@ -654,9 +699,9 @@ | |||
210 | 654 | def test_attributes_grid(self): | 699 | def test_attributes_grid(self): |
211 | 655 | app = ebay.App(CONFIG) | 700 | app = ebay.App(CONFIG) |
212 | 656 | with nested( | 701 | with nested( |
216 | 657 | patch.object(app, '_get_products'), | 702 | patch.object(app, '_get_products'), |
217 | 658 | patch.object(app, '_get_available_departments'), | 703 | patch.object(app, '_get_available_departments'), |
218 | 659 | ) as (mock, mdep): | 704 | ) as (mock, mdep): |
219 | 660 | mdep.return_value = {}, ('550', 'Foo') | 705 | mdep.return_value = {}, ('550', 'Foo') |
220 | 661 | mock.return_value = get_fixture('ebay-surfacing.json') | 706 | mock.return_value = get_fixture('ebay-surfacing.json') |
221 | 662 | kwargs = STD_KWARGS.copy() | 707 | kwargs = STD_KWARGS.copy() |
The attempt to merge lp:~facundo/ubuntu-rest-scopes/limit-ebay-limits into lp:ubuntu-rest-scopes failed. Below is the output from the failed tests.
....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ....... ------- ------- ------- ------- ------- ------- ------- ------- -------
-------
Ran 364 tests in 17.543s
OK