Merge lp:~facundo/ubuntu-rest-scopes/limit-ebay-limits into lp:ubuntu-rest-scopes

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
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 :

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/scopes/ebay.py'
--- src/scopes/ebay.py 2015-03-30 17:34:32 +0000
+++ src/scopes/ebay.py 2016-05-30 12:24:27 +0000
@@ -1,4 +1,4 @@
1# Copyright 2014-2015 Canonical1# Copyright 2014-2016 Canonical
2# All Rights Reserved2# All Rights Reserved
33
4"""The eBay scope."""4"""The eBay scope."""
@@ -19,6 +19,9 @@
1919
20logger = logging.getLogger("restscopes.ebay")20logger = logging.getLogger("restscopes.ebay")
2121
22# don't send limits more than this or ebay will complain
23MAX_LIMIT = 100
24
22SEARCH_URI = ('https://svcs.ebay.com/services/search/FindingService/v1'25SEARCH_URI = ('https://svcs.ebay.com/services/search/FindingService/v1'
23 '?SECURITY-APPNAME=%(key)s&OPERATION-NAME=findItemsByKeywords'26 '?SECURITY-APPNAME=%(key)s&OPERATION-NAME=findItemsByKeywords'
24 '&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON'27 '&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON'
@@ -77,7 +80,7 @@
77 'PL': {'pl_PL': (212, 'EBAY-PL')},80 'PL': {'pl_PL': (212, 'EBAY-PL')},
78 'SG': {'en_SG': (216, 'EBAY-SG')},81 'SG': {'en_SG': (216, 'EBAY-SG')},
79 'US': {'en_US': (0, 'EBAY-US')},82 'US': {'en_US': (0, 'EBAY-US')},
80 }83}
8184
82FILTERS = {'Condition', 'MaxPrice', 'MinPrice', 'SellerBusinessType',85FILTERS = {'Condition', 'MaxPrice', 'MinPrice', 'SellerBusinessType',
83 'EndTimeTo', 'TopRatedSellerOnly'}86 'EndTimeTo', 'TopRatedSellerOnly'}
@@ -598,6 +601,8 @@
598 def search(self, **kwargs):601 def search(self, **kwargs):
599 """Do the search."""602 """Do the search."""
600 limit = kwargs['limit']603 limit = kwargs['limit']
604 if limit > MAX_LIMIT:
605 limit = MAX_LIMIT
601 locale = kwargs['locale']606 locale = kwargs['locale']
602 country = kwargs.get('country')607 country = kwargs.get('country')
603 query = urllib.quote(kwargs['query'].encode('utf-8'))608 query = urllib.quote(kwargs['query'].encode('utf-8'))
604609
=== modified file 'src/scopes/tests/test_ebay.py'
--- src/scopes/tests/test_ebay.py 2015-02-26 19:13:53 +0000
+++ src/scopes/tests/test_ebay.py 2016-05-30 12:24:27 +0000
@@ -1,6 +1,6 @@
1# -*- coding: utf8 -*-1# -*- coding: utf8 -*-
22
3# Copyright 2014 Canonical3# Copyright 2014-2016 Canonical
4# All Rights Reserved4# All Rights Reserved
55
6"""Tests for the Simple App base stuff."""6"""Tests for the Simple App base stuff."""
@@ -22,7 +22,7 @@
22 '?SECURITY-APPNAME=hush&OPERATION-NAME=findItemsByKeywords'22 '?SECURITY-APPNAME=hush&OPERATION-NAME=findItemsByKeywords'
23 '&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON'23 '&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON'
24 '&GLOBAL-ID=EBAY-US&REST-PAYLOAD'24 '&GLOBAL-ID=EBAY-US&REST-PAYLOAD'
25 '&keywords=paris&paginationInput.entriesPerPage=10'25 '&keywords=paris&paginationInput.entriesPerPage={limit}'
26 '&outputSelector(0)=PictureURLSuperSize'26 '&outputSelector(0)=PictureURLSuperSize'
27 '&outputSelector(1)=PictureURLLarge'27 '&outputSelector(1)=PictureURLLarge'
28 '&affiliate.networkId=9&affiliate.trackingId=campid')28 '&affiliate.networkId=9&affiliate.trackingId=campid')
@@ -30,14 +30,14 @@
30TEST_SURFACING_URI = (30TEST_SURFACING_URI = (
31 'http://open.api.ebay.com/shopping?callname=FindPopularItems'31 'http://open.api.ebay.com/shopping?callname=FindPopularItems'
32 '&responseencoding=JSON&appid=hush&siteid=0&version=531&'32 '&responseencoding=JSON&appid=hush&siteid=0&version=531&'
33 'CategoryID=550&MaxEntries=10&trackingpartnercode=9&trackingid=campid')33 'CategoryID=550&MaxEntries={limit}&trackingpartnercode=9&trackingid=campid')
3434
35TEST_SORTING_URI = (35TEST_SORTING_URI = (
36 'https://svcs.ebay.com/services/search/FindingService/v1'36 'https://svcs.ebay.com/services/search/FindingService/v1'
37 '?SECURITY-APPNAME=hush&OPERATION-NAME=findItemsByCategory'37 '?SECURITY-APPNAME=hush&OPERATION-NAME=findItemsByCategory'
38 '&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON'38 '&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON'
39 '&GLOBAL-ID=EBAY-US&REST-PAYLOAD'39 '&GLOBAL-ID=EBAY-US&REST-PAYLOAD'
40 '&categoryId=550&sortOrder=SomeSorting&paginationInput.entriesPerPage=10'40 '&categoryId=550&sortOrder=SomeSorting&paginationInput.entriesPerPage={limit}'
41 '&outputSelector(0)=PictureURLSuperSize&outputSelector(1)=PictureURLLarge'41 '&outputSelector(0)=PictureURLSuperSize&outputSelector(1)=PictureURLLarge'
42 '&itemFilter.name=ListingType&itemFilter.value=Auction'42 '&itemFilter.name=ListingType&itemFilter.value=Auction'
43 '&affiliate.networkId=9&affiliate.trackingId=campid')43 '&affiliate.networkId=9&affiliate.trackingId=campid')
@@ -61,7 +61,7 @@
61 response = list(app.search(**STD_KWARGS))61 response = list(app.search(**STD_KWARGS))
6262
63 # got the info as it should63 # got the info as it should
64 mock.assert_called_with(TEST_SEARCH_URI)64 mock.assert_called_with(TEST_SEARCH_URI.format(limit=STD_KWARGS['limit']))
6565
66 # category66 # category
67 category_mock = ebay.PRODUCTS_CATEGORY.copy()67 category_mock = ebay.PRODUCTS_CATEGORY.copy()
@@ -96,12 +96,25 @@
96 }}96 }}
97 self.assertEqual(response[1], should_res)97 self.assertEqual(response[1], should_res)
9898
99 def test_product_limit_limit(self):
100 std_kwargs = STD_KWARGS.copy()
101 std_kwargs['limit'] = 300 # too big!
102 app = ebay.App(CONFIG)
103 with patch.object(app, '_get_products') as mock:
104 with patch.object(app, '_get_available_departments') as mdep:
105 mdep.return_value = {}, ()
106 mock.return_value = get_fixture('ebay-results.json')
107 list(app.search(**std_kwargs))
108
109 # got the info as it should
110 mock.assert_called_with(TEST_SEARCH_URI.format(limit=ebay.MAX_LIMIT)) # limit limited!
111
99 def test_surfacing(self):112 def test_surfacing(self):
100 app = ebay.App(CONFIG)113 app = ebay.App(CONFIG)
101 with nested(114 with nested(
102 patch.object(app, '_get_products'),115 patch.object(app, '_get_products'),
103 patch.object(app, '_get_available_departments'),116 patch.object(app, '_get_available_departments'),
104 ) as (mock, mdep):117 ) as (mock, mdep):
105 mdep.return_value = {}, ('550', 'Foo')118 mdep.return_value = {}, ('550', 'Foo')
106 mock.return_value = get_fixture('ebay-surfacing.json')119 mock.return_value = get_fixture('ebay-surfacing.json')
107 kwargs = STD_KWARGS.copy()120 kwargs = STD_KWARGS.copy()
@@ -109,7 +122,7 @@
109 response = list(app.search(**kwargs))122 response = list(app.search(**kwargs))
110123
111 # got the info as it should124 # got the info as it should
112 mock.assert_called_with(TEST_SURFACING_URI)125 mock.assert_called_with(TEST_SURFACING_URI.format(limit=STD_KWARGS['limit']))
113126
114 # department and filter127 # department and filter
115 self.assertEqual(response[0].keys()[0], 'departments')128 self.assertEqual(response[0].keys()[0], 'departments')
@@ -146,12 +159,28 @@
146159
147 }))160 }))
148161
162 def test_surfacing_limit_limited(self):
163 app = ebay.App(CONFIG)
164 with nested(
165 patch.object(app, '_get_products'),
166 patch.object(app, '_get_available_departments'),
167 ) as (mock, mdep):
168 mdep.return_value = {}, ('550', 'Foo')
169 mock.return_value = get_fixture('ebay-surfacing.json')
170 kwargs = STD_KWARGS.copy()
171 kwargs['query'] = ''
172 kwargs['limit'] = 300
173 list(app.search(**kwargs))
174
175 # got the info as it should
176 mock.assert_called_with(TEST_SURFACING_URI.format(limit=ebay.MAX_LIMIT))
177
149 def test_surfacing_no_img(self):178 def test_surfacing_no_img(self):
150 app = ebay.App(CONFIG)179 app = ebay.App(CONFIG)
151 with nested(180 with nested(
152 patch.object(app, '_get_products'),181 patch.object(app, '_get_products'),
153 patch.object(app, '_get_available_departments'),182 patch.object(app, '_get_available_departments'),
154 ) as (mock, mdep):183 ) as (mock, mdep):
155 mdep.return_value = {}, ('550', 'Bar')184 mdep.return_value = {}, ('550', 'Bar')
156 mock.return_value = get_fixture('ebay-surfacing-no-img.json')185 mock.return_value = get_fixture('ebay-surfacing-no-img.json')
157 kwargs = STD_KWARGS.copy()186 kwargs = STD_KWARGS.copy()
@@ -159,7 +188,7 @@
159 response = list(app.search(**kwargs))188 response = list(app.search(**kwargs))
160189
161 # got the info as it should190 # got the info as it should
162 mock.assert_called_with(TEST_SURFACING_URI)191 mock.assert_called_with(TEST_SURFACING_URI.format(limit=STD_KWARGS['limit']))
163192
164 # department and filter193 # department and filter
165 self.assertEqual(response[0].keys()[0], 'departments')194 self.assertEqual(response[0].keys()[0], 'departments')
@@ -207,9 +236,9 @@
207 app = ebay.App(CONFIG)236 app = ebay.App(CONFIG)
208 filters = {ebay.SORTING_ID: ['SomeSorting']}237 filters = {ebay.SORTING_ID: ['SomeSorting']}
209 with nested(238 with nested(
210 patch.object(app, '_get_products'),239 patch.object(app, '_get_products'),
211 patch.object(app, '_get_available_departments'),240 patch.object(app, '_get_available_departments'),
212 ) as (mock, mdep):241 ) as (mock, mdep):
213 mdep.return_value = {}, ('550', 'Bar')242 mdep.return_value = {}, ('550', 'Bar')
214 mock.return_value = get_fixture('ebay-results-sorting.json')243 mock.return_value = get_fixture('ebay-results-sorting.json')
215 kwargs = STD_KWARGS.copy()244 kwargs = STD_KWARGS.copy()
@@ -217,7 +246,7 @@
217 response = list(app.search(**kwargs))246 response = list(app.search(**kwargs))
218247
219 # got the info as it should248 # got the info as it should
220 mock.assert_called_with(TEST_SORTING_URI)249 mock.assert_called_with(TEST_SORTING_URI.format(limit=STD_KWARGS['limit']))
221250
222 # department and filter251 # department and filter
223 self.assertEqual(response[0].keys()[0], 'departments')252 self.assertEqual(response[0].keys()[0], 'departments')
@@ -226,6 +255,22 @@
226 self.assertEqual(response[1]['category']['title'], "Bar")255 self.assertEqual(response[1]['category']['title'], "Bar")
227 self.assertEqual(len(response), 7)256 self.assertEqual(len(response), 7)
228257
258 def test_surfacing_filters_limit_limited(self):
259 app = ebay.App(CONFIG)
260 filters = {ebay.SORTING_ID: ['SomeSorting']}
261 with nested(
262 patch.object(app, '_get_products'),
263 patch.object(app, '_get_available_departments'),
264 ) as (mock, mdep):
265 mdep.return_value = {}, ('550', 'Bar')
266 mock.return_value = get_fixture('ebay-results-sorting.json')
267 kwargs = STD_KWARGS.copy()
268 kwargs.update(query='', filters=filters, limit=300)
269 list(app.search(**kwargs))
270
271 # got the info as it should
272 mock.assert_called_with(TEST_SORTING_URI.format(limit=ebay.MAX_LIMIT))
273
229 def test_filters(self):274 def test_filters(self):
230 filters = {"MaxPrice": 5000,275 filters = {"MaxPrice": 5000,
231 "MinPrice": [10, 30],276 "MinPrice": [10, 30],
@@ -654,9 +699,9 @@
654 def test_attributes_grid(self):699 def test_attributes_grid(self):
655 app = ebay.App(CONFIG)700 app = ebay.App(CONFIG)
656 with nested(701 with nested(
657 patch.object(app, '_get_products'),702 patch.object(app, '_get_products'),
658 patch.object(app, '_get_available_departments'),703 patch.object(app, '_get_available_departments'),
659 ) as (mock, mdep):704 ) as (mock, mdep):
660 mdep.return_value = {}, ('550', 'Foo')705 mdep.return_value = {}, ('550', 'Foo')
661 mock.return_value = get_fixture('ebay-surfacing.json')706 mock.return_value = get_fixture('ebay-surfacing.json')
662 kwargs = STD_KWARGS.copy()707 kwargs = STD_KWARGS.copy()

Subscribers

People subscribed via source and target branches