Merge lp:~verterok/unity-scope-songkick/empty-response into lp:unity-scope-songkick

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Guillermo Gonzalez
Approved revision: 16
Merged at revision: 15
Proposed branch: lp:~verterok/unity-scope-songkick/empty-response
Merge into: lp:unity-scope-songkick
Diff against target: 87 lines (+33/-13)
3 files modified
src/unity_songkick_daemon.py (+2/-3)
tests/data/mock_songkick_empty (+2/-0)
tests/test_songkick.py (+29/-10)
To merge this branch: bzr merge lp:~verterok/unity-scope-songkick/empty-response
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Facundo Batista (community) Approve
Review via email: mp+189163@code.launchpad.net

Commit message

Handle empty result

Description of the change

Handle empty result

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
16. By Guillermo Gonzalez

add test data file

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/unity_songkick_daemon.py'
--- src/unity_songkick_daemon.py 2013-09-24 22:21:01 +0000
+++ src/unity_songkick_daemon.py 2013-10-03 19:30:01 +0000
@@ -74,13 +74,12 @@
74 response = urllib.request.urlopen(uri).read()74 response = urllib.request.urlopen(uri).read()
75 response = response.decode('utf8')75 response = response.decode('utf8')
76 json_response = json.loads(response)76 json_response = json.loads(response)
77 result = json_response['resultsPage']['results']['event']77 result = json_response['resultsPage']['results'].get('event', [])
78 except Exception:78 except Exception:
79 logger.exception("Error while fetching: %r", uri)79 logger.exception("Error while fetching: %r", uri)
80 result = {}80 result = []
81 if result:81 if result:
82 for item in result:82 for item in result:
83
84 icon_hint = ""83 icon_hint = ""
85 for artist in item['performance']:84 for artist in item['performance']:
86 #if artist['artist']['displayName'].lower() == search.replace("%20", " "):85 #if artist['artist']['displayName'].lower() == search.replace("%20", " "):
8786
=== added file 'tests/data/mock_songkick_empty'
--- tests/data/mock_songkick_empty 1970-01-01 00:00:00 +0000
+++ tests/data/mock_songkick_empty 2013-10-03 19:30:01 +0000
@@ -0,0 +1,2 @@
1{"resultsPage":{"status":"ok","results":{},"perPage":50,"page":1,"totalEntries":0}}
2
03
=== modified file 'tests/test_songkick.py'
--- tests/test_songkick.py 2013-09-25 02:59:30 +0000
+++ tests/test_songkick.py 2013-10-03 19:30:01 +0000
@@ -1,8 +1,10 @@
1#! /usr/bin/python31#! /usr/bin/python3
2# -*- coding: utf-8 -*-2# -*- coding: utf-8 -*-
3import imp
4import logging
5
3from gi.repository import Unity6from gi.repository import Unity
4from unittest import TestCase7from unittest import TestCase
5import imp
68
79
8class ResultSet(Unity.ResultSet):10class ResultSet(Unity.ResultSet):
@@ -43,18 +45,35 @@
43 expected_results = ["http://www.songkick.com/concerts/15019954-black-rebel-motorcycle-club-at-academy?utm_source=18004&utm_medium=partner",45 expected_results = ["http://www.songkick.com/concerts/15019954-black-rebel-motorcycle-club-at-academy?utm_source=18004&utm_medium=partner",
44 "Black Rebel Motorcycle Club at Academy (March 11, 2013)"]46 "Black Rebel Motorcycle Club at Academy (March 11, 2013)"]
45 results = []47 results = []
46 for s in ['empathy']:48 result_set = self.perform_query("Black")
47 result_set = self.perform_query(s)49 results.append(result_set.results[0]['uri'])
48 results.append(result_set.results[0]['uri'])50 results.append(result_set.results[0]['title'])
49 results.append(result_set.results[0]['title'])
50 self.assertEqual(results, expected_results)51 self.assertEqual(results, expected_results)
5152
5253 def test_failing_search(self):
53 def test_questions_failing_search(self):
54 self.scope_module.SEARCH_URI = 'file:tests/data/mock_songkick_fail#'54 self.scope_module.SEARCH_URI = 'file:tests/data/mock_songkick_fail#'
55 for s in ['empathy']:55 result_set = self.perform_query("empathy")
56 result_set = self.perform_query(s)56 self.assertEqual(len(result_set.results), 0)
57 self.assertEqual(len(result_set.results), 0)57
58 def test_empty_result(self):
59 self.scope_module.SEARCH_URI = 'file:tests/data/mock_songkick_empty#'
60 handler = Handler()
61 handler.setLevel(logging.ERROR)
62 self.scope_module.logger.addHandler(handler)
63 result_set = self.perform_query("foo")
64 self.assertEqual(len(result_set.results), 0)
65 self.assertEqual(len(handler.records), 0)
66
67
68class Handler(logging.Handler):
69 """Log handler to capture messages."""
70
71 def __init__(self):
72 super(Handler, self).__init__()
73 self.records = []
74
75 def emit(self, record):
76 self.records.append(record)
5877
59if __name__ == '__main__':78if __name__ == '__main__':
60 unittest.main()79 unittest.main()

Subscribers

People subscribed via source and target branches