[ckan-changes] commit/ckan: John Glover: [search][xs] Fix tests for resource search

Bitbucket commits-noreply at bitbucket.org
Tue Sep 20 11:08:43 UTC 2011


1 new changeset in ckan:

http://bitbucket.org/okfn/ckan/changeset/a89848e1a5d4/
changeset:   a89848e1a5d4
user:        John Glover
date:        2011-09-20 13:07:57
summary:     [search][xs] Fix tests for resource search
affected #:  1 file (-1 bytes)

--- a/ckan/tests/lib/test_resource_search.py	Tue Sep 20 10:43:26 2011 +0100
+++ b/ckan/tests/lib/test_resource_search.py	Tue Sep 20 12:07:57 2011 +0100
@@ -3,16 +3,13 @@
 
 from ckan.tests import *
 from ckan.tests import is_search_supported
-from ckan.lib.search import QueryOptions
+import ckan.lib.search as search
 from ckan import model
 from ckan.lib.create_test_data import CreateTestData
-from ckan.lib.search.common import SearchError
 
 class TestSearch(object):
     @classmethod
     def setup_class(self):
-        raise SkipTest("Resource search not yet implemented with solr")
-
         if not is_search_supported():
             raise SkipTest("Search not supported")
 
@@ -53,21 +50,20 @@
              },
             ]
         CreateTestData.create_arbitrary(self.pkgs)
-        self.backend = get_backend(backend='sql')
 
     @classmethod
     def teardown_class(self):
         model.repo.rebuild_db()
 
-    def res_search(self, query='', fields={}, terms=[], options=QueryOptions()):
-        result = self.backend.query_for(model.Resource).run(query=query, fields=fields, terms=terms, options=options)
+    def res_search(self, query='', fields={}, terms=[], options=search.QueryOptions()):
+        result = search.query_for(model.Resource).run(query=query, fields=fields, terms=terms, options=options)
         resources = [model.Session.query(model.Resource).get(resource_id) for resource_id in result['results']]
         urls = set([resource.url for resource in resources])
         return urls
 
     def test_01_search_url(self):
         fields = {'url':'site.com'}
-        result = self.backend.query_for(model.Resource).run(fields=fields)
+        result = search.query_for(model.Resource).run(fields=fields)
         assert result['count'] == 6, result
         resources = [model.Session.query(model.Resource).get(resource_id) for resource_id in result['results']]
         urls = set([resource.url for resource in resources])
@@ -117,8 +113,8 @@
 
     def test_12_search_all_fields(self):
         fields = {'url':'a/b'}
-        options = QueryOptions(all_fields=True)
-        result = self.backend.query_for(model.Resource).run(fields=fields, options=options)
+        options = search.QueryOptions(all_fields=True)
+        result = search.query_for(model.Resource).run(fields=fields, options=options)
         assert result['count'] == 1, result
         res_dict = result['results'][0]
         assert isinstance(res_dict, dict)
@@ -138,17 +134,17 @@
 
     def test_13_pagination(self):
         # large search
-        options = QueryOptions(order_by='hash')
+        options = search.QueryOptions(order_by='hash')
         fields = {'url':'site'}
-        all_results = self.backend.query_for(model.Resource).run(fields=fields, options=options)
+        all_results = search.query_for(model.Resource).run(fields=fields, options=options)
         all_resources = all_results['results']
         all_resource_count = all_results['count']
         assert all_resource_count >= 6, all_results
 
         # limit
-        options = QueryOptions(order_by='hash')
+        options = search.QueryOptions(order_by='hash')
         options.limit = 2
-        result = self.backend.query_for(model.Resource).run(fields=fields, options=options)
+        result = search.query_for(model.Resource).run(fields=fields, options=options)
         resources = result['results']
         count = result['count']
         assert len(resources) == 2, resources
@@ -156,36 +152,35 @@
         assert resources == all_resources[:2], '%r, %r' % (resources, all_resources)
 
         # offset
-        options = QueryOptions(order_by='hash')
+        options = search.QueryOptions(order_by='hash')
         options.limit = 2
         options.offset = 2
-        result = self.backend.query_for(model.Resource).run(fields=fields, options=options)
+        result = search.query_for(model.Resource).run(fields=fields, options=options)
         resources = result['results']
         assert len(resources) == 2, resources
         assert resources == all_resources[2:4]
 
         # larger offset
-        options = QueryOptions(order_by='hash')
+        options = search.QueryOptions(order_by='hash')
         options.limit = 2
         options.offset = 4
-        result = self.backend.query_for(model.Resource).run(fields=fields, options=options)
+        result = search.query_for(model.Resource).run(fields=fields, options=options)
         resources = result['results']
         assert len(resources) == 2, resources
         assert resources == all_resources[4:6]
 
     def test_14_extra_info(self):
-
         fields = {'alt_url':'alt1'}
-        result = self.backend.query_for(model.Resource).run(fields=fields)
+        result = search.query_for(model.Resource).run(fields=fields)
         assert result['count'] == 2, result
 
         fields = {'alt_url':'alt2'}
-        result = self.backend.query_for(model.Resource).run(fields=fields)
+        result = search.query_for(model.Resource).run(fields=fields)
         assert result['count'] == 1, result
 
         # Document that resource extras not in ckan.extra_resource_fields
         # can't be searched
         fields = {'size_extra':'100'}
-        assert_raises(SearchError, self.backend.query_for(model.Resource).run, fields=fields)
+        assert_raises(search.SearchError, search.query_for(model.Resource).run, fields=fields)

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list