Merge lp:~facundo/ubuntu-rest-scopes/ebay-curated-categories into lp:ubuntu-rest-scopes

Proposed by Facundo Batista
Status: Rejected
Rejected by: Facundo Batista
Proposed branch: lp:~facundo/ubuntu-rest-scopes/ebay-curated-categories
Merge into: lp:ubuntu-rest-scopes
Diff against target: 400 lines (+316/-11)
3 files modified
configs/scopes/ebay_top_departments.yaml (+238/-0)
src/scopes/ebay.py (+36/-8)
src/scopes/tests/test_ebay.py (+42/-3)
To merge this branch: bzr merge lp:~facundo/ubuntu-rest-scopes/ebay-curated-categories
Reviewer Review Type Date Requested Status
Ubuntu One hackers Pending
Review via email: mp+226517@code.launchpad.net

Commit message

Incorporate curated top categories for eBay.

Description of the change

Incorporate curated top categories for eBay.

Test included.

To post a comment you must log in.

Unmerged revisions

169. By Facundo Batista

Incorporate curated top categories.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'configs/scopes/ebay_top_departments.yaml'
2--- configs/scopes/ebay_top_departments.yaml 1970-01-01 00:00:00 +0000
3+++ configs/scopes/ebay_top_departments.yaml 2014-07-11 19:01:44 +0000
4@@ -0,0 +1,238 @@
5+fr_BE:
6+ - [Art & Antiquités, 353]
7+ - [Cinéma & DVD, 11232]
8+ - [Informatique & PDA, 160]
9+ - [Jeux Vidéos & PC, 14616]
10+ - [Livres & BD, 267]
11+ - [Musique & Instruments, 11233]
12+ - [Photo & Cameras, 625]
13+ - [Sports & Vélos, 11796]
14+ - [Tickets & Voyages, 11730]
15+ - ["TV, Audio & Vidéo", 293]
16+
17+nl_BE:
18+ - [Boeken & Strips, 267]
19+ - [Computer & PDA, 160]
20+ - ["Dvd's, Video's & Films", 11232]
21+ - [Foto & Camera's, 625]
22+ - [Games & Consoles, 14616]
23+ - [Muziek & Instrumenten, 11233]
24+ - [Sport & Fietsen, 11796]
25+ - ["Tv, Audio & Video", 293]
26+
27+fr_FR:
28+ - ["Art, antiquités", 353]
29+ - ["DVD, cinéma", 11232]
30+ - ["Image, son", 293]
31+ - ["Informatique, Réseaux", 58058]
32+ - ["Jeux vidéo, consoles", 1249]
33+ - ["Livres, BD, revues", 267]
34+ - ["Musique, CD, vinyles", 11233]
35+ - ["Photo, caméscopes", 625]
36+ - ["Sports, vacances", 888]
37+ - ["Téléphonie, mobilité", 15032]
38+
39+de_CH:
40+ - [Antiquitäten & Kunst, 353]
41+ - ["Computer, Tablets & Netzwerk", 58058]
42+ - [Filme & DVDs, 11232]
43+ - [Foto & Camcorder, 625]
44+ - [Handys & Kommunikation, 15032]
45+ - [Musik, 11233]
46+ - [PC- & Videospiele, 1249]
47+ - [Sport, 888]
48+ - [Tickets, 1305]
49+ - ["TV, Video & Audio", 293]
50+
51+nl_NL:
52+ - [Boeken en strips, 267]
53+ - [Computers, 160]
54+ - [Consumentenelektronica, 293]
55+ - [Film en DVD, 11232]
56+ - [Games en consoles, 14616]
57+ - [GSM en telecom, 14675]
58+ - ["Kunst, antiek en design", 353]
59+ - ["Sport, fietsen en vakantie", 888]
60+
61+en_MY:
62+ - [Art, 550]
63+ - [Books, 267]
64+ - [Cameras & Photo, 625]
65+ - [Computers & Tablets, 58058]
66+ - [Consumer Electronics, 293]
67+ - [DVD & Movies, 11232]
68+ - [Mobile Phones & Accessories, 15032]
69+ - [Music, 11233]
70+ - [Sporting Goods, 382]
71+
72+en_CA:
73+ - [Art, 550]
74+ - [Books, 267]
75+ - [Cameras & Photo, 625]
76+ - [Cell Phones & Accessories, 15032]
77+ - [Computers/Tablets & Networking, 58058]
78+ - [Consumer Electronics, 293]
79+ - [DVDs & Movies, 11232]
80+ - [Music, 11233]
81+ - [Sporting Goods, 888]
82+ - [Tickets & Experiences, 1305]
83+
84+fr_CA:
85+ - [Art, 550]
86+ - [Articles de sports, 888]
87+ - [Billets & expériences, 1305]
88+ - [Caméras & appareils photo, 625]
89+ - [Cellulaires & accessoires, 15032]
90+ - [DVD & films, 11232]
91+ - [Électronique grand public, 293]
92+ - [Livres, 267]
93+ - [Musique, 11233]
94+ - ["Ordinateur, tablette & réseau", 58058]
95+
96+de_DE:
97+ - [Antiquitäten & Kunst, 353]
98+ - ["Computer, Tablets & Netzwerk", 58058]
99+ - [Filme & DVDs, 11232]
100+ - [Foto & Camcorder, 625]
101+ - [Handys & Kommunikation, 15032]
102+ - [Musik, 11233]
103+ - [PC- & Videospiele, 1249]
104+ - [Sport, 888]
105+ - [Tickets, 1305]
106+ - ["TV, Video & Audio", 293]
107+
108+it_IT:
109+ - [Arte e Antiquariato, 353]
110+ - [Film e DVD, 11232]
111+ - [Fotografia e Video, 625]
112+ - [Informatica, 58058]
113+ - [Libri e Riviste, 267]
114+ - ["Musica, CD e Vinili", 11233]
115+ - [Sport e Viaggi, 888]
116+ - ["TV, Audio e Video", 293]
117+
118+en_US:
119+ - [Art, 550]
120+ - [Books, 267]
121+ - [Cameras & Photo, 625]
122+ - [Cell Phones & Accessories, 15032]
123+ - [Computers/Tablets & Networking, 58058]
124+ - [Consumer Electronics, 293]
125+ - [DVDs & Movies, 11232]
126+ - [Music, 11233]
127+ - [Tickets & Experiences, 1305]
128+
129+pl_PL:
130+ - [Antyki i Sztuka, 353]
131+ - [Filmy i DVD, 11232]
132+ - [Fotografia i Aparaty, 625]
133+ - [Komputery i Laptopy, 58058]
134+ - [Muzyka i CD, 11233]
135+ - [RTV i AGD, 293]
136+ - [Sport i Turystyka, 382]
137+ - [Telefony i Akcesoria, 14675]
138+
139+zh_HK:
140+ - [手機、通訊產品, 14675]
141+ - [電子產品及電器, 293]
142+ - [電腦及網絡, 58058]
143+ - [數碼相機、攝影器材, 625]
144+ - [電影音樂, 45099]
145+ - [體育、休閒及旅遊, 888]
146+ - [書籍, 267]
147+
148+en_AU:
149+ - [Art, 550]
150+ - ["Books, Magazines", 267]
151+ - [Computers, 58058]
152+ - [Electronics, 293]
153+ - [Home Entertainment, 172176]
154+ - [Movies, 11232]
155+ - [Music, 11233]
156+ - [Phones, 15032]
157+ - [Sporting Goods, 888]
158+ - ["Tickets, Travel", 11730]
159+
160+de_AT:
161+ - [Antiquitäten & Kunst, 353]
162+ - [Bücher, 267]
163+ - ["Computer, Tablets & Netzwerk", 58058]
164+ - [Filme & DVDs, 11232]
165+ - [Foto & Camcorder, 625]
166+ - [Handys & Kommunikation, 15032]
167+ - [Musik, 11233]
168+ - [PC- & Videospiele, 1249]
169+ - [Sport, 888]
170+ - [Tickets, 1305]
171+ - ["TV, Video & Audio", 293]
172+
173+en_IN:
174+ - [Audio & Home Entertainment, 293]
175+ - [Books & Magazines, 267]
176+ - [Cameras & Optics, 625]
177+ - [Fitness & Sports, 13361]
178+ - [Laptops & Computer Peripherals, 160]
179+ - ["LCD, LED & Televisions", 11071]
180+ - [Mobile Accessories, 14416]
181+ - [Mobile Phones, 15032]
182+ - [Movies & Music, 11232]
183+ - [Tablets & Accessories, 178741]
184+
185+en_SG:
186+ - [Art, 550]
187+ - [Books, 267]
188+ - [Cameras & Photo, 625]
189+ - [Computers & Tablets, 58058]
190+ - [Consumer Electronics, 293]
191+ - [DVD & Movies, 11232]
192+ - [Home & Garden, 11700]
193+ - [Music, 11233]
194+ - [Sporting Goods, 382]
195+
196+en_PH:
197+ - [Art, 550]
198+ - [Books, 267]
199+ - [Cameras & Photo, 625]
200+ - [Computers & Tablets, 58058]
201+ - [Consumer Electronics, 293]
202+ - [DVD & Movies, 11232]
203+ - [Home & Garden, 11700]
204+ - [Mobile Phones & Accessories, 15032]
205+ - [Music, 11233]
206+ - [Sporting Goods, 382]
207+
208+en_IE:
209+ - [Art, 550]
210+ - ["Books, Comics & Magazines", 267]
211+ - [Cameras & Photography, 625]
212+ - [Computers/Tablets & Networking, 58058]
213+ - ["DVDs, Films & TV", 11232]
214+ - [Events Tickets, 1305]
215+ - ["Home, Furniture & DIY", 11700]
216+ - [Mobile Phones & Communication, 15032]
217+ - [Music, 11233]
218+ - [Sporting Goods, 888]
219+
220+es_ES:
221+ - [Arte y Antigüedades, 353]
222+ - [Cámaras y Fotografía, 625]
223+ - ["Cine, DVD y Películas", 11232]
224+ - [Electrodomésticos, 20710]
225+ - [Entradas y eventos, 1305]
226+ - [Informática y tablets, 58058]
227+ - ["Libros, Revistas y Comics", 267]
228+ - [Móviles y telefonía, 15032]
229+ - ["Música, CD y Vinilos", 11233]
230+
231+en_GB:
232+ - [Art, 550]
233+ - ["Books, Comics & Magazines", 267]
234+ - [Cameras & Photography, 625]
235+ - [Computers/Tablets & Networking, 58058]
236+ - ["DVDs, Films & TV", 11232]
237+ - [Events Tickets, 1305]
238+ - [Mobile Phones & Communication, 15032]
239+ - [Music, 11233]
240+ - [Sound & Vision, 293]
241+ - [Video Games & Consoles, 1249]
242+
243
244=== modified file 'src/scopes/ebay.py'
245--- src/scopes/ebay.py 2014-06-25 14:54:41 +0000
246+++ src/scopes/ebay.py 2014-07-11 19:01:44 +0000
247@@ -7,6 +7,8 @@
248 import json
249 import re
250 import logging
251+import os
252+import yaml
253
254 from urllib2 import urlopen
255 from urllib import urlencode
256@@ -537,6 +539,33 @@
257 super(App, self).__init__(*args, **kwargs)
258 self.api_utils = {'key': self.config['secrets'].get('api_key')}
259
260+ _rootdir = os.environ['ROOTDIR']
261+ _configdir = self.config['scopes_config_dir']
262+ _path = os.path.join(_rootdir, _configdir, 'ebay_top_departments.yaml')
263+ with open(_path, 'r') as f:
264+ self.top_departments = yaml.load(f)
265+
266+ def _get_top_departments(self, locale):
267+ """Get the top departments, from a curated config."""
268+ try:
269+ curated_data = self.top_departments[locale]
270+ except KeyError:
271+ curated_data = self.top_departments['en_US']
272+
273+ subdeps = []
274+ for dep_label, dep_id in curated_data:
275+ subdeps.append({
276+ 'canned_query': 'scope://ebay?dep=%s' % (dep_id,),
277+ 'has_subdepartments': True,
278+ 'label': dep_label,
279+ })
280+ tree = {
281+ 'canned_query': 'scope://ebay',
282+ 'label': translator('All departments', locale),
283+ 'subdepartments': subdeps,
284+ }
285+ return tree
286+
287 def search(self, **kwargs):
288 """Do the search."""
289 limit = kwargs['limit']
290@@ -556,19 +585,18 @@
291 site_id, global_id = shop_loc.get(locale, shop_loc.itervalues().next())
292 if not query.strip():
293 # Surfacing API calls
294- available_deps = _get_available_departments(department,
295- site_id,
296- self.api_utils["key"],
297- locale,
298- filters=filters_state)
299- yield dict(departments=available_deps)
300 if not department:
301- department, dep_label = _get_surfacing_department(
302- available_deps)
303+ top_deps = self._get_top_departments(locale)
304+ yield dict(departments=top_deps)
305+ department, dep_label = _get_surfacing_department(top_deps)
306 yield dict(category=_build_surfacing_category(dep_label,
307 locale))
308 grid_rendering = True
309 else:
310+ available_deps = _get_available_departments(
311+ department, site_id, self.api_utils["key"],
312+ locale, filters=filters_state)
313+ yield dict(departments=available_deps)
314 yield dict(filters=_get_localized_filters(locale))
315 yield dict(category=localized_category(PRODUCTS_CATEGORY,
316 locale))
317
318=== modified file 'src/scopes/tests/test_ebay.py'
319--- src/scopes/tests/test_ebay.py 2014-06-25 14:54:41 +0000
320+++ src/scopes/tests/test_ebay.py 2014-07-11 19:01:44 +0000
321@@ -13,7 +13,7 @@
322 from src.scopes import ebay
323 from src.scopes.tests import get_fixture
324
325-CONFIG = {'secrets': {}}
326+CONFIG = {'secrets': {}, 'scopes_config_dir': 'configs/scopes'}
327
328 SEARCH_URI = ('https://svcs.ebay.com/services/search/FindingService/v1'
329 '?SECURITY-APPNAME=None&OPERATION-NAME=findItemsByKeywords'
330@@ -81,7 +81,7 @@
331 app = ebay.App(CONFIG)
332 with patch.object(ebay, '_get_products') as mock:
333 with patch.object(ebay, '_get_surfacing_department') as dep_mock:
334- with patch.object(ebay, '_get_available_departments') as mdep:
335+ with patch.object(app, '_get_top_departments') as mdep:
336 mdep.return_value = {}
337 mock.return_value = get_fixture('ebay-surfacing.json')
338 dep_mock.return_value = ('550', 'Foo')
339@@ -92,6 +92,7 @@
340
341 # got the info as it should
342 mock.assert_called_with(SURFACING_URI)
343+ mdep.assert_called_with('C')
344
345 # category
346 self.assertEqual(response[1]['category']['title'], "Featured in Foo")
347@@ -129,7 +130,7 @@
348 app = ebay.App(CONFIG)
349 with patch.object(ebay, '_get_products') as mock:
350 with patch.object(ebay, '_get_surfacing_department') as dep_mock:
351- with patch.object(ebay, '_get_available_departments') as mdep:
352+ with patch.object(app, '_get_top_departments') as mdep:
353 mdep.return_value = {}
354 mock.return_value = get_fixture(
355 'ebay-surfacing-no-img.json')
356@@ -226,6 +227,44 @@
357 'CategoryID=550&MaxEntries=10')
358 mock.assert_called_with(uri)
359
360+ def test_get_top_departments_knownlocale(self):
361+ app = ebay.App(CONFIG)
362+ app.top_departments = {
363+ 'fr_FR': [('Art', 12), ('Accessoires', 111)],
364+ }
365+ resp = app._get_top_departments('fr_FR')
366+ self.assertEqual(resp, {
367+ 'canned_query': 'scope://ebay',
368+ 'label': u'Tous les départements',
369+ 'subdepartments': [{
370+ 'canned_query': 'scope://ebay?dep=12',
371+ 'has_subdepartments': True,
372+ 'label': 'Art',
373+ }, {
374+ 'canned_query': 'scope://ebay?dep=111',
375+ 'has_subdepartments': True,
376+ 'label': 'Accessoires',
377+ }]})
378+
379+ def test_get_top_departments_localefallback(self):
380+ app = ebay.App(CONFIG)
381+ app.top_departments = {
382+ 'en_US': [('Art', 550), ('Books', 999)],
383+ }
384+ resp = app._get_top_departments('fr_FR')
385+ self.assertEqual(resp, {
386+ 'canned_query': 'scope://ebay',
387+ 'label': u'Tous les départements',
388+ 'subdepartments': [{
389+ 'canned_query': 'scope://ebay?dep=550',
390+ 'has_subdepartments': True,
391+ 'label': 'Art',
392+ }, {
393+ 'canned_query': 'scope://ebay?dep=999',
394+ 'has_subdepartments': True,
395+ 'label': 'Books',
396+ }]})
397+
398
399 class PreviewTestCase(TestCase):
400 """Tests for the preview function."""

Subscribers

People subscribed via source and target branches