[ckan-changes] commit/ckan: dread: [tests][s]: Reorganise dataset search tests, collecting them all in test_search.py.

Bitbucket commits-noreply at bitbucket.org
Fri Oct 28 09:30:38 UTC 2011


1 new commit in ckan:


https://bitbucket.org/okfn/ckan/changeset/a7ecdbed3bbe/
changeset:   a7ecdbed3bbe
user:        dread
date:        2011-10-28 11:27:04
summary:     [tests][s]: Reorganise dataset search tests, collecting them all in test_search.py.
affected #:  3 files

diff -r c9bfdcb5c4e70011b3d60f0212b727c6e50dfe13 -r a7ecdbed3bbe45e40d4c8d65a3a96d9524da948c ckan/tests/__init__.py
--- a/ckan/tests/__init__.py
+++ b/ckan/tests/__init__.py
@@ -60,7 +60,7 @@
 # Check config is correct for sqlite
 if config['sqlalchemy.url'].startswith('sqlite:'):
     assert ckan_nose_plugin.CkanNose.settings.is_ckan, \
-           'You forgot the "--ckan" nosetest setting - see README.txt'
+           'You forgot the "--ckan" nosetest setting - see doc/test.rst'
 
 class BaseCase(object):
 


diff -r c9bfdcb5c4e70011b3d60f0212b727c6e50dfe13 -r a7ecdbed3bbe45e40d4c8d65a3a96d9524da948c ckan/tests/functional/test_package.py
--- a/ckan/tests/functional/test_package.py
+++ b/ckan/tests/functional/test_package.py
@@ -10,7 +10,6 @@
 from nose.tools import assert_equal
 
 from ckan.tests import *
-from ckan.tests import search_related, setup_test_search_index
 from ckan.tests.html_check import HtmlCheckMethods
 from ckan.tests.pylons_controller import PylonsTestCase
 from base import FunctionalTestCase
@@ -234,20 +233,11 @@
     @classmethod
     def setup_class(cls):
         PylonsTestCase.setup_class()
-        setup_test_search_index()
         CreateTestData.create()
 
     @classmethod
     def teardown_class(cls):
         model.repo.rebuild_db()
-        search.clear()
-
-    @search_related
-    def test_minornavigation_2(self):
-        offset = url_for(controller='package', action='search')
-        res = self.app.get(offset)
-        res = res.click('Register it now')
-        assert 'Add - Datasets' in res
 
     def test_read(self):
         name = u'annakarenina'
@@ -296,6 +286,14 @@
         assert 'romantic novel' in res, res
         assert 'original media' in res, res
         assert 'book' in res, res
+        assert 'This Dataset is Open' in res, res
+
+    def test_read_war(self):
+        name = u'warandpeace'
+        c.hide_welcome_message = True
+        offset = url_for(controller='package', action='read', id=name)
+        res = self.app.get(offset)
+        assert 'This dataset is Not Open' in res, res
 
     def test_read_nonexistentpackage(self):
         name = 'anonexistentpackage'
@@ -330,49 +328,6 @@
         #assert '%s - Datasets' % title in res, res
         #main_div = self.main_div(res)
         #assert title in main_div, main_div.encode('utf8')
-
-    @search_related
-    def test_search(self):
-        offset = url_for(controller='package', action='search', id=None)
-        print offset
-        res = self.app.get(offset)
-        assert 'Search - ' in res
-        self._check_search_results(res, 'annakarenina', ['<strong>1</strong>', 'A Novel By Tolstoy'] )
-        self._check_search_results(res, 'warandpeace', ['<strong>1</strong>'])
-        self._check_search_results(res, 'warandpeace', ['<strong>1</strong>'])
-        self._check_search_results(res, 'annakarenina', ['<strong>1</strong>'])
-        # check for something that also finds tags ...
-        self._check_search_results(res, 'russian', ['<strong>2</strong>'])
-
-    @search_related
-    def test_search_foreign_chars(self):
-        offset = url_for(controller='package', action='search')
-        res = self.app.get(offset)
-        assert 'Search - ' in res
-        self._check_search_results(res, u'th\xfcmb', ['<strong>1</strong>'])
-        self._check_search_results(res, 'thumb', ['<strong>0</strong>'])
-
-    @search_related
-    def test_search_escape_chars(self):
-        payload = '?q=fjdkf%2B%C2%B4gfhgfkgf%7Bg%C2%B4pk&search=Search+Packages+%C2%BB'
-        offset = url_for(controller='package', action='search') + payload
-        results_page = self.app.get(offset)
-        assert 'Search - ' in results_page, results_page
-        results_page = self.main_div(results_page)
-        # solr's edismax parser won't throw an error, so this should return 0 results
-        assert '>0<' in results_page, results_page
-
-    def _check_search_results(self, page, terms, requireds):
-        form = page.forms['dataset-search']
-        form['q'] = terms.encode('utf8') # paste doesn't handle this!
-        results_page = form.submit()
-        assert 'Search - ' in results_page, results_page
-        results_page = self.main_div(results_page)
-        for required in requireds:
-            if required not in results_page:
-                print results_page
-                print 'Could not find %r' % required
-                raise AssertionError
     
     def test_history(self):
         name = 'annakarenina'
@@ -1269,10 +1224,8 @@
 
 class TestNonActivePackages(TestPackageBase):
 
-
     @classmethod
     def setup_class(self):
-        setup_test_search_index()
         CreateTestData.create()
         self.non_active_name = u'test_nonactive'
         pkg = model.Package(name=self.non_active_name)
@@ -1294,7 +1247,6 @@
     @classmethod
     def teardown_class(self):
         model.repo.rebuild_db()
-        search.clear()
 
     def test_read(self):
         offset = url_for(controller='package', action='read', id=self.non_active_name)
@@ -1305,17 +1257,6 @@
         offset = url_for(controller='package', action='read', id=self.non_active_name)
         res = self.app.get(offset, status=200, extra_environ={'REMOTE_USER':'joeadmin'})
 
-    @search_related
-    def test_search(self):
-        offset = url_for(controller='package', action='search')
-        res = self.app.get(offset)
-        assert 'Search - ' in res
-        form = res.forms['dataset-search']
-        form['q'] =  str(self.non_active_name)
-        results_page = form.submit()
-        assert 'Search - ' in results_page, results_page
-        assert '<strong>0</strong> datasets found' in results_page, (self.non_active_name, results_page)
-
 
 class TestRevisions(TestPackageBase):
     @classmethod


diff -r c9bfdcb5c4e70011b3d60f0212b727c6e50dfe13 -r a7ecdbed3bbe45e40d4c8d65a3a96d9524da948c ckan/tests/functional/test_search.py
--- a/ckan/tests/functional/test_search.py
+++ b/ckan/tests/functional/test_search.py
@@ -5,12 +5,14 @@
 import re
 from nose.tools import assert_equal
 
-from ckan.tests import (TestController, CreateTestData,
-                        setup_test_search_index, html_check)
+from ckan.tests import CreateTestData, setup_test_search_index, search_related
+from ckan.tests.pylons_controller import PylonsTestCase
+from base import FunctionalTestCase
 from ckan import model
 import ckan.lib.search as search
+from ckan.lib.helpers import url_for
 
-class TestSearch(TestController, html_check.HtmlCheckMethods):
+class TestSearch(FunctionalTestCase):
     # 'penguin' is in all test search packages
     q_all = u'penguin'
 
@@ -66,3 +68,104 @@
         # multiple words
         res = self.app.get('/dataset?q=Government%20Expenditure')
         result = self._check_results(res, 1, 'uk-government-expenditure')
+
+class TestSearch2(FunctionalTestCase, PylonsTestCase):#, TestPackageForm):
+
+    @classmethod
+    def setup_class(cls):
+        PylonsTestCase.setup_class()
+        setup_test_search_index()
+        CreateTestData.create()
+
+    @classmethod
+    def teardown_class(cls):
+        model.repo.rebuild_db()
+        search.clear()
+
+    @search_related
+    def test_minornavigation_2(self):
+        offset = url_for(controller='package', action='search')
+        res = self.app.get(offset)
+        res = res.click('Register it now')
+        assert 'Add - Datasets' in res
+
+    @search_related
+    def test_search(self):
+        offset = url_for(controller='package', action='search', id=None)
+        print offset
+        res = self.app.get(offset)
+        assert 'Search - ' in res
+        self._check_search_results(res, 'annakarenina', ['<strong>1</strong>', 'A Novel By Tolstoy'] )
+        self._check_search_results(res, 'warandpeace', ['<strong>1</strong>'])
+        self._check_search_results(res, 'warandpeace', ['<strong>1</strong>'])
+        self._check_search_results(res, 'annakarenina', ['<strong>1</strong>'])
+        # check for something that also finds tags ...
+        self._check_search_results(res, 'russian', ['<strong>2</strong>'])
+
+    @search_related
+    def test_search_foreign_chars(self):
+        offset = url_for(controller='package', action='search')
+        res = self.app.get(offset)
+        assert 'Search - ' in res
+        self._check_search_results(res, u'th\xfcmb', ['<strong>1</strong>'])
+        self._check_search_results(res, 'thumb', ['<strong>0</strong>'])
+
+    @search_related
+    def test_search_escape_chars(self):
+        payload = '?q=fjdkf%2B%C2%B4gfhgfkgf%7Bg%C2%B4pk&search=Search+Packages+%C2%BB'
+        offset = url_for(controller='package', action='search') + payload
+        results_page = self.app.get(offset)
+        assert 'Search - ' in results_page, results_page
+        results_page = self.main_div(results_page)
+        # solr's edismax parser won't throw an error, so this should return 0 results
+        assert '>0<' in results_page, results_page
+
+    def _check_search_results(self, page, terms, requireds):
+        form = page.forms['dataset-search']
+        form['q'] = terms.encode('utf8') # paste doesn't handle this!
+        results_page = form.submit()
+        assert 'Search - ' in results_page, results_page
+        results_page = self.main_div(results_page)
+        for required in requireds:
+            if required not in results_page:
+                print results_page
+                print 'Could not find %r' % required
+                raise AssertionError
+
+class TestNonActivePackages(FunctionalTestCase):
+    @classmethod
+    def setup_class(self):
+        setup_test_search_index()
+        CreateTestData.create()
+        self.non_active_name = u'test_nonactive'
+        pkg = model.Package(name=self.non_active_name)
+        model.repo.new_revision()
+        model.Session.add(pkg)
+        model.repo.commit_and_remove()
+
+        pkg = model.Session.query(model.Package).filter_by(name=self.non_active_name).one()
+        admin = model.User.by_name(u'joeadmin')
+        model.setup_default_user_roles(pkg, [admin])
+        model.repo.commit_and_remove()
+
+        model.repo.new_revision()        
+        pkg = model.Session.query(model.Package).filter_by(name=self.non_active_name).one()
+        pkg.delete() # becomes non active
+        model.repo.commit_and_remove()
+        
+
+    @classmethod
+    def teardown_class(self):
+        model.repo.rebuild_db()
+        search.clear()
+
+    @search_related
+    def test_search(self):
+        offset = url_for(controller='package', action='search')
+        res = self.app.get(offset)
+        assert 'Search - ' in res
+        form = res.forms['dataset-search']
+        form['q'] =  str(self.non_active_name)
+        results_page = form.submit()
+        assert 'Search - ' in results_page, results_page
+        assert '<strong>0</strong> datasets found' in results_page, (self.non_active_name, results_page)

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