Merge lp:~ceronman/txsolr/print-solrresponse-707518 into lp:txsolr

Proposed by Manuel Cerón
Status: Merged
Merged at revision: 54
Proposed branch: lp:~ceronman/txsolr/print-solrresponse-707518
Merge into: lp:txsolr
Diff against target: 63 lines (+18/-2)
3 files modified
txsolr/__init__.py (+1/-0)
txsolr/response.py (+2/-1)
txsolr/test/test_response.py (+15/-1)
To merge this branch: bzr merge lp:~ceronman/txsolr/print-solrresponse-707518
Reviewer Review Type Date Requested Status
Jamu Kakar (community) Approve
txsolr-dev Pending
Review via email: mp+62052@code.launchpad.net

Description of the change

This branch introduces the following changes:

 - Solr responses now can be printed without AttributeError raising.
 - txSolr logger doesn't propagate messages to higher level loggers.

To post a comment you must log in.
57. By Manuel Cerón

Added missing doscring

Revision history for this message
Jamu Kakar (jkakar) wrote :

[1]

+ def testSolrResponseRepr(self):
+ """A L{SolrResponse} representation shows the raw response."""
+ raw = '''{
+ "responseHeader":{
+ "status":0,
+ "QTime":2,
+ "params":{
+ "indent":"on",
+ "wt":"json",
+ "q":"manuel"}},
+ "response":{"numFound":0,"start":0,"docs":[]}
+ }'''
+ response = JSONSolrResponse(raw)
+ self.assertEqual('SolrResponse: %r' % raw, repr(response))

I think you should dump JSON here instead of constructing it by hand:

    def testSolrResponseRepr(self):
        """A L{SolrResponse} representation shows the raw response."""
        rawResponse = dumps({'responseHeader': {'status': 0,
                                                'QTime': 2,
                                                'params': {'indent': 'on',
                                                           'wt': 'json',
                                                           'q': 'manuel'}},
                             'response': {'numFound': 0,
                                          'start': 0,
                                          'docs': []}})
        response = JSONSolrResponse(rawResponse)
        self.assertEqual('SolrResponse: %r' % rawResponse, repr(response))

Nice work, +1!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'txsolr/__init__.py'
2--- txsolr/__init__.py 2010-10-14 10:58:34 +0000
3+++ txsolr/__init__.py 2011-05-23 23:11:37 +0000
4@@ -40,6 +40,7 @@
5 pass
6
7 _logger = logging.getLogger('txsolr')
8+_logger.propagate = False
9 _logger.addHandler(_NullHandler())
10
11 def logToStderr(level=logging.DEBUG):
12
13=== modified file 'txsolr/response.py'
14--- txsolr/response.py 2010-10-15 16:01:42 +0000
15+++ txsolr/response.py 2011-05-23 23:11:37 +0000
16@@ -127,6 +127,7 @@
17 self.header = None
18 self.results = None
19
20+ self.rawResponse = response
21 self.responseDict = self._decodeResponse(response)
22 self._update()
23
24@@ -169,7 +170,7 @@
25 raise SolrResponseError(msg)
26
27 def __repr__(self):
28- return 'SolrResponse: %s' % repr(self.rawResponse)
29+ return 'SolrResponse: %r' % self.rawResponse
30
31
32 class JSONSolrResponse(SolrResponse):
33
34=== modified file 'txsolr/test/test_response.py'
35--- txsolr/test/test_response.py 2010-10-14 10:58:34 +0000
36+++ txsolr/test/test_response.py 2011-05-23 23:11:37 +0000
37@@ -6,7 +6,6 @@
38 class ResponseTest(unittest.TestCase):
39
40 def test_jsonSolrResponse(self):
41-
42 raw = '''{
43 "responseHeader":{
44 "status":0,
45@@ -52,3 +51,18 @@
46 </response> '''
47
48 self.assertRaises(SolrResponseError, JSONSolrResponse, raw)
49+
50+ def testSolrResponseRepr(self):
51+ """A L{SolrResponse} representation shows the raw response."""
52+ raw = '''{
53+ "responseHeader":{
54+ "status":0,
55+ "QTime":2,
56+ "params":{
57+ "indent":"on",
58+ "wt":"json",
59+ "q":"manuel"}},
60+ "response":{"numFound":0,"start":0,"docs":[]}
61+ }'''
62+ response = JSONSolrResponse(raw)
63+ self.assertEqual('SolrResponse: %r' % raw, repr(response))

Subscribers

People subscribed via source and target branches

to all changes: