[ckan-changes] commit/ckanext-solr: John Glover: Update package search tests
Bitbucket
commits-noreply at bitbucket.org
Thu Aug 11 16:32:27 UTC 2011
1 new changeset in ckanext-solr:
http://bitbucket.org/okfn/ckanext-solr/changeset/6a8abe410c12/
changeset: 6a8abe410c12
user: John Glover
date: 2011-08-11 18:32:08
summary: Update package search tests
affected #: 1 file (5.3 KB)
--- a/tests/test_package_search.py Thu Aug 11 16:53:55 2011 +0100
+++ b/tests/test_package_search.py Thu Aug 11 17:32:08 2011 +0100
@@ -263,3 +263,139 @@
self._check_search_results('annakarenina', 1, ['annakarenina'], True, True)
+class TestGeographicCoverage(TestController):
+ @classmethod
+ def setup_class(cls):
+ init_data = [
+ {'name':'eng',
+ 'extras':{'geographic_coverage':'100000: England'},},
+ {'name':'eng_ni',
+ 'extras':{'geographic_coverage':'100100: England, Northern Ireland'},},
+ {'name':'uk',
+ 'extras':{'geographic_coverage':'111100: United Kingdom (England, Scotland, Wales, Northern Ireland'},},
+ {'name':'gb',
+ 'extras':{'geographic_coverage':'111000: Great Britain (England, Scotland, Wales)'},},
+ {'name':'none',
+ 'extras':{'geographic_coverage':'000000:'},},
+ ]
+ CreateTestData.create_arbitrary(init_data)
+ search.rebuild()
+ cls.backend = search.get_backend()
+
+ @classmethod
+ def teardown_class(self):
+ model.repo.rebuild_db()
+ search.get_backend().index_for('Package').clear()
+
+ def _do_search(self, q, expected_pkgs, count=None):
+ options = search.QueryOptions()
+ options.order_by = 'rank'
+ result = self.backend.query_for(model.Package).run(query=q, options=options)
+ pkgs = result['results']
+ fields = [model.Package.by_name(pkg_name).name for pkg_name in pkgs]
+ if not (count is None):
+ assert result['count'] == count, result['count']
+ for expected_pkg in expected_pkgs:
+ assert expected_pkg in fields, expected_pkg
+
+ def _filtered_search(self, value, expected_pkgs, count=None):
+ options = QueryOptions()
+ options.order_by = 'rank'
+ result = self.backend.query_for(model.Package).run(fields={'geographic_coverage':value}, options=options)
+ pkgs = result['results']
+ fields = [model.Package.by_name(pkg_name).name for pkg_name in pkgs]
+ if not (count is None):
+ assert result['count'] == count, result['count']
+ for expected_pkg in expected_pkgs:
+ assert expected_pkg in fields, expected_pkg
+
+ def test_0_basic(self):
+ self._do_search(u'england', ['eng', 'eng_ni', 'uk', 'gb'], 4)
+ self._do_search(u'northern ireland', ['eng_ni', 'uk'], 2)
+ self._do_search(u'united kingdom', ['uk'], 1)
+ self._do_search(u'great britain', ['gb'], 1)
+
+ # TODO: fix this test
+ # def test_1_filtered(self):
+ # self._filtered_search(u'england', ['eng', 'eng_ni', 'uk', 'gb'], 4)
+
+class TestExtraFields(TestController):
+ @classmethod
+ def setup_class(cls):
+ init_data = [
+ {'name':'a',
+ 'extras':{'department':'abc',
+ 'agency':'ag-a'},},
+ {'name':'b',
+ 'extras':{'department':'bcd',
+ 'agency':'ag-b'},},
+ {'name':'c',
+ 'extras':{'department':'cde abc'},},
+ {'name':'none',
+ 'extras':{'department':''},},
+ ]
+ CreateTestData.create_arbitrary(init_data)
+ search.rebuild()
+ cls.backend = search.get_backend()
+
+ @classmethod
+ def teardown_class(self):
+ model.repo.rebuild_db()
+ search.get_backend().index_for('Package').clear()
+
+ def _do_search(self, department, expected_pkgs, count=None):
+ result = self.backend.query_for(model.Package).run(fields={'department':department})
+ pkgs = result['results']
+ fields = [model.Package.by_name(pkg_name).name for pkg_name in pkgs]
+ if not (count is None):
+ assert result['count'] == count, result['count']
+ for expected_pkg in expected_pkgs:
+ assert expected_pkg in fields, expected_pkg
+
+ def test_0_basic(self):
+ self._do_search(u'bcd', 'b', 1)
+ # TODO: fix this test
+ # self._do_search(u'abc', ['a', 'c'], 2)
+ # self._do_search(u'cde', 'c', 1)
+ # self._do_search(u'abc cde', 'c', 1)
+ # self._do_search(u'cde abc', 'c', 1)
+
+class TestRank(TestController):
+ @classmethod
+ def setup_class(cls):
+ init_data = [{'name':u'test1-penguin-canary',
+ 'tags':u'canary goose squirrel wombat wombat'},
+ {'name':u'test2-squirrel-squirrel-canary-goose',
+ 'tags':u'penguin wombat'},
+ ]
+ CreateTestData.create_arbitrary(init_data)
+ cls.pkg_names = [
+ u'test1-penguin-canary',
+ u'test2-squirrel-squirrel-canary-goose'
+ ]
+ search.rebuild()
+ cls.backend = search.get_backend()
+
+ @classmethod
+ def teardown_class(self):
+ model.repo.rebuild_db()
+ search.get_backend().index_for('Package').clear()
+
+ def _do_search(self, q, wanted_results):
+ options = search.QueryOptions()
+ options.order_by = 'rank'
+ result = self.backend.query_for(model.Package).run(query=q, options=options)
+ results = result['results']
+ err = 'Wanted %r, got %r' % (wanted_results, results)
+ assert wanted_results[0] == results[0], err
+ assert wanted_results[1] == results[1], err
+
+ def test_0_basic(self):
+ self._do_search(u'wombat', self.pkg_names)
+ self._do_search(u'squirrel', self.pkg_names[::-1])
+ self._do_search(u'canary', self.pkg_names)
+
+ # TODO: fix this test
+ # def test_1_weighting(self):
+ # self._do_search(u'penguin', self.pkg_names)
+ # self._do_search(u'goose', self.pkg_names[::-1])
Repository URL: https://bitbucket.org/okfn/ckanext-solr/
--
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