Merge lp:~submarine/ubuntu-scopes/googlenews-25-limit into lp:~submarine/ubuntu-scopes/googlenews

Proposed by David Callé
Status: Merged
Approved by: James Henstridge
Approved revision: 59
Merged at revision: 58
Proposed branch: lp:~submarine/ubuntu-scopes/googlenews-25-limit
Merge into: lp:~submarine/ubuntu-scopes/googlenews
Diff against target: 52 lines (+14/-5)
2 files modified
src/unity_googlenews_daemon.py (+6/-4)
tests/test_googlenews.py (+8/-1)
To merge this branch: bzr merge lp:~submarine/ubuntu-scopes/googlenews-25-limit
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
James Henstridge Approve
Review via email: mp+155150@code.launchpad.net

Commit message

Limit to 25 results for speed and ease of exploration. Don't search for <3 characters.

Description of the change

Limit to 25 results for speed and ease of exploration. Don't search for <3 characters.

To post a comment you must log in.
Revision history for this message
James Henstridge (jamesh) wrote :

Could you add test coverage to show that searches of two characters or less give no results?

Revision history for this message
James Henstridge (jamesh) :
review: Needs Fixing
59. By David Callé

Add test for search <= 2 characters

Revision history for this message
David Callé (davidc3) wrote :

Added test.

Revision history for this message
James Henstridge (jamesh) wrote :

Looks good. But in future, I wouldn't bother with useless for loops like "for s in ['qu']:" -- if you need to extend a test to cover multiple cases in the future, add it in then. As it is, it just makes the test more difficult to read for little benefit.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity_googlenews_daemon.py'
2--- src/unity_googlenews_daemon.py 2013-03-20 11:01:43 +0000
3+++ src/unity_googlenews_daemon.py 2013-03-25 13:44:20 +0000
4@@ -115,20 +115,22 @@
5 country, city = get_location()
6
7 results = []
8+ if not search or len(search) <= 2:
9+ return results
10 for cat in range(0,2):
11 topic = ''
12 scoring = "r"
13 if search:
14 search = urllib.parse.quote(search)
15 if cat == 0:
16- rss = "%s?output=rss&q=%s&num=50&scoring=%s&ned=%s&geo=%s&topic=%s" % (SEARCH_URI, search, scoring, country, city, topic)
17+ rss = "%s?output=rss&q=%s&num=25&scoring=%s&ned=%s&geo=%s&topic=%s" % (SEARCH_URI, search, scoring, country, city, topic)
18 else:
19- rss = "%s?output=rss&q=%s&num=50&scoring=%s&ned=%s&topic=%s" % (SEARCH_URI, search, scoring, country, topic)
20+ rss = "%s?output=rss&q=%s&num=25&scoring=%s&ned=%s&topic=%s" % (SEARCH_URI, search, scoring, country, topic)
21 else:
22 if cat == 0:
23- rss = "%s?output=rss&num=50&scoring=%s&ned=%s&geo=%s&topic=%s" % (SEARCH_URI, scoring, country, city, topic)
24+ rss = "%s?output=rss&num=25&scoring=%s&ned=%s&geo=%s&topic=%s" % (SEARCH_URI, scoring, country, city, topic)
25 else:
26- rss = "%s?output=rss&num=50&scoring=%s&ned=%s&topic=%s" % (SEARCH_URI, scoring, country, topic)
27+ rss = "%s?output=rss&num=25&scoring=%s&ned=%s&topic=%s" % (SEARCH_URI, scoring, country, topic)
28 print(rss)
29 # try:
30 feed = feedparser.parse(rss)
31
32=== modified file 'tests/test_googlenews.py'
33--- tests/test_googlenews.py 2013-03-19 01:26:33 +0000
34+++ tests/test_googlenews.py 2013-03-25 13:44:20 +0000
35@@ -46,9 +46,16 @@
36 for s in ['query']:
37 result_set = self.perform_query(s)
38 results.append(result_set.results[1]['title'])
39-
40 self.assertEqual(results, expected_results)
41
42+ def test_short_search(self):
43+ self.scope_module.SEARCH_URI = 'file:tests/data/mock_googlenews_pass.rss#'
44+ self.scope_module.GEOIPLOOKUP_URI = 'file:tests/data/mock_geoiplookup.js'
45+ results = []
46+ for s in ['qu']:
47+ result_set = self.perform_query(s)
48+ self.assertEqual(len(result_set.results), 0)
49+
50 def test_failing_search(self):
51 self.scope_module.SEARCH_URI = 'file:tests/data/mock_googlenews_fail'
52 self.scope_module.GEOIPLOOKUP_URI = 'file:tests/data/mock_geoiplookup.js'

Subscribers

People subscribed via source and target branches

to all changes: