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
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 @@
5-# Copyright 2014-2015 Canonical
6+# Copyright 2014-2016 Canonical
7 # All Rights Reserved
8
9 """The eBay scope."""
10@@ -19,6 +19,9 @@
11
12 logger = logging.getLogger("restscopes.ebay")
13
14+# don't send limits more than this or ebay will complain
15+MAX_LIMIT = 100
16+
17 SEARCH_URI = ('https://svcs.ebay.com/services/search/FindingService/v1'
18 '?SECURITY-APPNAME=%(key)s&OPERATION-NAME=findItemsByKeywords'
19 '&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON'
20@@ -77,7 +80,7 @@
21 'PL': {'pl_PL': (212, 'EBAY-PL')},
22 'SG': {'en_SG': (216, 'EBAY-SG')},
23 'US': {'en_US': (0, 'EBAY-US')},
24- }
25+}
26
27 FILTERS = {'Condition', 'MaxPrice', 'MinPrice', 'SellerBusinessType',
28 'EndTimeTo', 'TopRatedSellerOnly'}
29@@ -598,6 +601,8 @@
30 def search(self, **kwargs):
31 """Do the search."""
32 limit = kwargs['limit']
33+ if limit > MAX_LIMIT:
34+ limit = MAX_LIMIT
35 locale = kwargs['locale']
36 country = kwargs.get('country')
37 query = urllib.quote(kwargs['query'].encode('utf-8'))
38
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 # -*- coding: utf8 -*-
44
45-# Copyright 2014 Canonical
46+# Copyright 2014-2016 Canonical
47 # All Rights Reserved
48
49 """Tests for the Simple App base stuff."""
50@@ -22,7 +22,7 @@
51 '?SECURITY-APPNAME=hush&OPERATION-NAME=findItemsByKeywords'
52 '&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON'
53 '&GLOBAL-ID=EBAY-US&REST-PAYLOAD'
54- '&keywords=paris&paginationInput.entriesPerPage=10'
55+ '&keywords=paris&paginationInput.entriesPerPage={limit}'
56 '&outputSelector(0)=PictureURLSuperSize'
57 '&outputSelector(1)=PictureURLLarge'
58 '&affiliate.networkId=9&affiliate.trackingId=campid')
59@@ -30,14 +30,14 @@
60 TEST_SURFACING_URI = (
61 'http://open.api.ebay.com/shopping?callname=FindPopularItems'
62 '&responseencoding=JSON&appid=hush&siteid=0&version=531&'
63- 'CategoryID=550&MaxEntries=10&trackingpartnercode=9&trackingid=campid')
64+ 'CategoryID=550&MaxEntries={limit}&trackingpartnercode=9&trackingid=campid')
65
66 TEST_SORTING_URI = (
67 'https://svcs.ebay.com/services/search/FindingService/v1'
68 '?SECURITY-APPNAME=hush&OPERATION-NAME=findItemsByCategory'
69 '&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON'
70 '&GLOBAL-ID=EBAY-US&REST-PAYLOAD'
71- '&categoryId=550&sortOrder=SomeSorting&paginationInput.entriesPerPage=10'
72+ '&categoryId=550&sortOrder=SomeSorting&paginationInput.entriesPerPage={limit}'
73 '&outputSelector(0)=PictureURLSuperSize&outputSelector(1)=PictureURLLarge'
74 '&itemFilter.name=ListingType&itemFilter.value=Auction'
75 '&affiliate.networkId=9&affiliate.trackingId=campid')
76@@ -61,7 +61,7 @@
77 response = list(app.search(**STD_KWARGS))
78
79 # got the info as it should
80- mock.assert_called_with(TEST_SEARCH_URI)
81+ mock.assert_called_with(TEST_SEARCH_URI.format(limit=STD_KWARGS['limit']))
82
83 # category
84 category_mock = ebay.PRODUCTS_CATEGORY.copy()
85@@ -96,12 +96,25 @@
86 }}
87 self.assertEqual(response[1], should_res)
88
89+ def test_product_limit_limit(self):
90+ std_kwargs = STD_KWARGS.copy()
91+ std_kwargs['limit'] = 300 # too big!
92+ app = ebay.App(CONFIG)
93+ with patch.object(app, '_get_products') as mock:
94+ with patch.object(app, '_get_available_departments') as mdep:
95+ mdep.return_value = {}, ()
96+ mock.return_value = get_fixture('ebay-results.json')
97+ list(app.search(**std_kwargs))
98+
99+ # got the info as it should
100+ mock.assert_called_with(TEST_SEARCH_URI.format(limit=ebay.MAX_LIMIT)) # limit limited!
101+
102 def test_surfacing(self):
103 app = ebay.App(CONFIG)
104 with nested(
105- patch.object(app, '_get_products'),
106- patch.object(app, '_get_available_departments'),
107- ) as (mock, mdep):
108+ patch.object(app, '_get_products'),
109+ patch.object(app, '_get_available_departments'),
110+ ) as (mock, mdep):
111 mdep.return_value = {}, ('550', 'Foo')
112 mock.return_value = get_fixture('ebay-surfacing.json')
113 kwargs = STD_KWARGS.copy()
114@@ -109,7 +122,7 @@
115 response = list(app.search(**kwargs))
116
117 # got the info as it should
118- mock.assert_called_with(TEST_SURFACING_URI)
119+ mock.assert_called_with(TEST_SURFACING_URI.format(limit=STD_KWARGS['limit']))
120
121 # department and filter
122 self.assertEqual(response[0].keys()[0], 'departments')
123@@ -146,12 +159,28 @@
124
125 }))
126
127+ def test_surfacing_limit_limited(self):
128+ app = ebay.App(CONFIG)
129+ with nested(
130+ patch.object(app, '_get_products'),
131+ patch.object(app, '_get_available_departments'),
132+ ) as (mock, mdep):
133+ mdep.return_value = {}, ('550', 'Foo')
134+ mock.return_value = get_fixture('ebay-surfacing.json')
135+ kwargs = STD_KWARGS.copy()
136+ kwargs['query'] = ''
137+ kwargs['limit'] = 300
138+ list(app.search(**kwargs))
139+
140+ # got the info as it should
141+ mock.assert_called_with(TEST_SURFACING_URI.format(limit=ebay.MAX_LIMIT))
142+
143 def test_surfacing_no_img(self):
144 app = ebay.App(CONFIG)
145 with nested(
146- patch.object(app, '_get_products'),
147- patch.object(app, '_get_available_departments'),
148- ) as (mock, mdep):
149+ patch.object(app, '_get_products'),
150+ patch.object(app, '_get_available_departments'),
151+ ) as (mock, mdep):
152 mdep.return_value = {}, ('550', 'Bar')
153 mock.return_value = get_fixture('ebay-surfacing-no-img.json')
154 kwargs = STD_KWARGS.copy()
155@@ -159,7 +188,7 @@
156 response = list(app.search(**kwargs))
157
158 # got the info as it should
159- mock.assert_called_with(TEST_SURFACING_URI)
160+ mock.assert_called_with(TEST_SURFACING_URI.format(limit=STD_KWARGS['limit']))
161
162 # department and filter
163 self.assertEqual(response[0].keys()[0], 'departments')
164@@ -207,9 +236,9 @@
165 app = ebay.App(CONFIG)
166 filters = {ebay.SORTING_ID: ['SomeSorting']}
167 with nested(
168- patch.object(app, '_get_products'),
169- patch.object(app, '_get_available_departments'),
170- ) as (mock, mdep):
171+ patch.object(app, '_get_products'),
172+ patch.object(app, '_get_available_departments'),
173+ ) as (mock, mdep):
174 mdep.return_value = {}, ('550', 'Bar')
175 mock.return_value = get_fixture('ebay-results-sorting.json')
176 kwargs = STD_KWARGS.copy()
177@@ -217,7 +246,7 @@
178 response = list(app.search(**kwargs))
179
180 # got the info as it should
181- mock.assert_called_with(TEST_SORTING_URI)
182+ mock.assert_called_with(TEST_SORTING_URI.format(limit=STD_KWARGS['limit']))
183
184 # department and filter
185 self.assertEqual(response[0].keys()[0], 'departments')
186@@ -226,6 +255,22 @@
187 self.assertEqual(response[1]['category']['title'], "Bar")
188 self.assertEqual(len(response), 7)
189
190+ def test_surfacing_filters_limit_limited(self):
191+ app = ebay.App(CONFIG)
192+ filters = {ebay.SORTING_ID: ['SomeSorting']}
193+ with nested(
194+ patch.object(app, '_get_products'),
195+ patch.object(app, '_get_available_departments'),
196+ ) as (mock, mdep):
197+ mdep.return_value = {}, ('550', 'Bar')
198+ mock.return_value = get_fixture('ebay-results-sorting.json')
199+ kwargs = STD_KWARGS.copy()
200+ kwargs.update(query='', filters=filters, limit=300)
201+ list(app.search(**kwargs))
202+
203+ # got the info as it should
204+ mock.assert_called_with(TEST_SORTING_URI.format(limit=ebay.MAX_LIMIT))
205+
206 def test_filters(self):
207 filters = {"MaxPrice": 5000,
208 "MinPrice": [10, 30],
209@@ -654,9 +699,9 @@
210 def test_attributes_grid(self):
211 app = ebay.App(CONFIG)
212 with nested(
213- patch.object(app, '_get_products'),
214- patch.object(app, '_get_available_departments'),
215- ) as (mock, mdep):
216+ patch.object(app, '_get_products'),
217+ patch.object(app, '_get_available_departments'),
218+ ) as (mock, mdep):
219 mdep.return_value = {}, ('550', 'Foo')
220 mock.return_value = get_fixture('ebay-surfacing.json')
221 kwargs = STD_KWARGS.copy()

Subscribers

People subscribed via source and target branches