Commits

Anonymous committed 1475795

Applied same changes to AsyncCouch as those for BlockingCouch (in last commit): replaced method list_docs() with view_all_docs(), which accepts the same parameters as view().

Also, updated tests (only BlockingCouch) to changes in function names and return values.

Comments (0)

Files changed (2)

 
     # Document operations
     
-    def list_docs(self, callback=None):
-        '''Get dict with id and rev of all documents in the database'''
-        def list_docs_cb(resp):
-            if isinstance(resp, Exception):
-                callback(resp)
-            else:
-                callback(dict((row['id'], row['value']['rev']) for row in resp['rows']))
-        self._http_get(''.join(['/', self.db_name, '/_all_docs']), callback=callback)
-
     def get_doc(self, doc_id, callback=None):
         '''Open a document with the given id'''
         url = ''.join(['/', self.db_name, '/', url_escape(doc_id)])
           inclusive_end=true
           inclusive_end=false
         '''
+        url = ''.join(['/', self.db_name, '/_design/', design_doc_name, '/_view/', view_name])
+        self._view(url, callback=callback, **kwargs)
+
+    def view_all_docs(self, callback=None, **kwargs):
+        '''Query the _all_docs view.
+        Accepts same keyword parameters as view()
+        '''
+        url = ''.join(['/', self.db_name, '/_all_docs'])
+        self._view(url, callback=callback, **kwargs)
+
+    def _view(self, url, callback=None, **kwargs):
         body = None
         options = []
         if kwargs:
                     value = url_escape(json_encode(value))
                     options.append('='.join([key, value]))
         if options:
-            q = '?' + '&'.join(options)
-        else:
-            q = ''
-        url = ''.join(['/', self.db_name, '/_design/', design_doc_name, '/_view/', view_name, q])
+            url = ''.join([url, '?', '&'.join(options)])
         if body:
             self._http_post(url, body, callback=callback)
         else:
     assert 'error' in resp[0], 'No error on request for unexisting doc'
    
     # list docs
-    resp = db.list_docs()
-    assert {doc1['_id']:doc1['_rev'], doc2['_id']:doc2['_rev']} == resp, 'Failed listing all docs'
+    resp = db.view_all_docs(include_docs=True)
+    assert {doc1['_id']:doc1['_rev'], doc2['_id']:doc2['_rev']} == \
+        dict((row['doc']['_id'], row['doc']['_rev']) for row in resp['rows']), \
+        'Failed listing all docs'
 
     # pull database
     resp = db2.pull_db('testdb', create_target=True)
     # delete docs
     resp = db2.delete_docs([doc1, doc2])
     assert resp[0]['id']==doc1['_id'] and resp[1]['id']==doc2['_id'], 'Failed to delete docs'
-    assert not db2.list_docs(), 'Failed to delete docs, database not empty'
+    assert not db2.view_all_docs()['rows'], 'Failed to delete docs, database not empty'
 
     # delete database
     resp = db2.delete_db()