[ckan-changes] commit/ckan: kindly: [tests] ticket 1148 speed up and clean up tests

Bitbucket commits-noreply at bitbucket.org
Sat May 21 09:19:15 UTC 2011


1 new changeset in ckan:

http://bitbucket.org/okfn/ckan/changeset/96a43c9d8bd7/
changeset:   r3102:96a43c9d8bd7
user:        kindly
date:        2011-05-21 11:19:01
summary:     [tests] ticket 1148 speed up and clean up tests
affected #:  19 files (1.2 KB)

--- a/ckan/model/__init__.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/model/__init__.py	Sat May 21 10:19:01 2011 +0100
@@ -56,6 +56,7 @@
         that may have been setup with either upgrade_db or a previous run of
         init_db.
         '''
+        warnings.filterwarnings('ignore', 'SAWarning')
         self.session.rollback()
         self.session.remove()
         # sqlite database needs to be recreated each time as the
@@ -72,8 +73,10 @@
 
     def clean_db(self):
         metadata = MetaData(self.metadata.bind)
-        metadata.reflect()
-        
+        with warnings.catch_warnings():
+            warnings.filterwarnings('ignore', '.*(reflection|tsvector).*')
+            metadata.reflect()
+
         metadata.drop_all()
         self.tables_created_and_initialised = False
 
@@ -133,14 +136,12 @@
     def delete_all(self):
         '''Delete all data from all tables.'''
         self.session.remove()
-        metadata = MetaData(self.metadata.bind)
-        metadata.reflect()
         ## use raw connection for performance
         connection = self.session.connection()
         if sqav.startswith("0.4"):
-            tables = metadata.table_iterator()
+            tables = self.metadata.table_iterator()
         else:
-            tables = reversed(metadata.sorted_tables)
+            tables = reversed(self.metadata.sorted_tables)
         for table in tables:
             connection.execute('delete from "%s"' % table.name)
         self.session.commit()


--- a/ckan/tests/functional/api/test_ajax.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/functional/api/test_ajax.py	Sat May 21 10:19:01 2011 +0100
@@ -12,7 +12,7 @@
                 
     @classmethod
     def teardown(cls):
-        CreateTestData.delete()
+        model.repo.rebuild_db()
         
     def test_package_create_slug(self):
         response = self.app.get(


--- a/ckan/tests/functional/api/test_misc.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/functional/api/test_misc.py	Sat May 21 10:19:01 2011 +0100
@@ -7,18 +7,11 @@
 
     @classmethod
     def setup_class(self):
-        try:
-            CreateTestData.delete()
-        except:
-            pass
-        model.repo.init_db()
-        model.Session.remove()
         CreateTestData.create()
 
     @classmethod
     def teardown_class(self):
-        model.Session.remove()
-        CreateTestData.delete()
+        model.repo.rebuild_db()
 
     # Todo: Move this method to the Model API?
     def test_0_tag_counts(self):


--- a/ckan/tests/functional/api/test_package_search.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/functional/api/test_package_search.py	Sat May 21 10:19:01 2011 +0100
@@ -30,8 +30,8 @@
         self.base_url = self.offset('/search/package')
 
     @classmethod
-    def teardown_class(self):
-        CreateTestData.delete()
+    def teardown_class(cls):
+        model.repo.rebuild_db()
 
     def assert_results(self, res_dict, expected_package_names):
         expected_pkgs = [self.package_ref_from_name(expected_package_name) \


--- a/ckan/tests/functional/api/test_resource_search.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/functional/api/test_resource_search.py	Sat May 21 10:19:01 2011 +0100
@@ -36,7 +36,7 @@
 
     @classmethod
     def teardown_class(self):
-        CreateTestData.delete()
+        model.repo.rebuild_db()
 
     def assert_urls_in_search_results(self, offset, expected_urls):
         result = self.app.get(offset, status=200)


--- a/ckan/tests/functional/api/test_revision_search.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/functional/api/test_revision_search.py	Sat May 21 10:19:01 2011 +0100
@@ -9,7 +9,7 @@
 
     @classmethod
     def teardown_class(self):
-        CreateTestData.delete()
+        model.repo.rebuild_db()
 
     def test_12_search_revision_basic(self):
         offset = self.offset('/search/revision')


--- a/ckan/tests/functional/api/test_user.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/functional/api/test_user.py	Sat May 21 10:19:01 2011 +0100
@@ -7,12 +7,12 @@
 
 class TestUserApi(ControllerTestCase):
     @classmethod
-    def setup(cls):
+    def setup_class(cls):
         CreateTestData.create()
                 
     @classmethod
-    def teardown(cls):
-        CreateTestData.delete()
+    def teardown_class(cls):
+        model.repo.rebuild_db()
         
     def test_autocomplete(self):
         response = self.app.get(


--- a/ckan/tests/functional/test_autoneg.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/functional/test_autoneg.py	Sat May 21 10:19:01 2011 +0100
@@ -22,7 +22,6 @@
 
     @classmethod
     def teardown_class(cls):
-        CreateTestData.delete()
         model.repo.rebuild_db()
 
     def test_default(self):


--- a/ckan/tests/functional/test_package.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/functional/test_package.py	Sat May 21 10:19:01 2011 +0100
@@ -464,7 +464,6 @@
 
     @classmethod
     def teardown_class(self):
-        CreateTestData.delete()
         model.repo.rebuild_db()
 
     def test_edit_basic(self):
@@ -1248,8 +1247,6 @@
 
     @classmethod
     def teardown_class(self):
-        CreateTestData.delete()
-        self.purge_packages([self.non_active_name])
         model.repo.rebuild_db()
 
     def test_read(self):
@@ -1300,7 +1297,6 @@
 
     @classmethod
     def teardown_class(self):
-        self.purge_packages([self.name])
         model.repo.rebuild_db()
     
     def test_0_read_history(self):
@@ -1380,7 +1376,6 @@
         self.res = self.app.get(offset)
 
     def teardown(self):
-        CreateTestData.delete()
         model.repo.rebuild_db()
 
     def test_markdown_html_whitelist(self):
@@ -1406,7 +1401,6 @@
 
     @classmethod
     def teardown_class(cls):
-        CreateTestData.delete()
         model.repo.rebuild_db()
 
     def test_calculate_etag_hash(self):


--- a/ckan/tests/functional/test_tag.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/functional/test_tag.py	Sat May 21 10:19:01 2011 +0100
@@ -12,7 +12,7 @@
 
     @classmethod
     def teardown_class(self):
-        CreateTestData.delete()
+        model.repo.rebuild_db()
 
     def test_index(self):
         offset = url_for(controller='tag')


--- a/ckan/tests/lib/test_package_search.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/lib/test_package_search.py	Sat May 21 10:19:01 2011 +0100
@@ -40,7 +40,7 @@
 
     @classmethod
     def teardown_class(self):
-        CreateTestData.delete()
+        model.repo.rebuild_db()
 
     def _pkg_names(self, result):
         return ' '.join(result['results'])
@@ -282,7 +282,7 @@
 
     @classmethod
     def teardown_class(self):
-        CreateTestData.delete()
+        model.repo.rebuild_db()
 
     def _check_search_results(self, terms, expected_count, expected_packages=[], only_open=False, only_downloadable=False):
         options = QueryOptions()
@@ -334,7 +334,7 @@
 
     @classmethod
     def teardown_class(self):
-        CreateTestData.delete()
+        model.repo.rebuild_db()
     
     def _do_search(self, q, expected_pkgs, count=None):
         options = QueryOptions()
@@ -389,7 +389,7 @@
 
     @classmethod
     def teardown_class(self):
-        CreateTestData.delete()
+        model.repo.rebuild_db()
     
     def _do_search(self, department, expected_pkgs, count=None):
         result = self.backend.query_for(model.Package).run(fields={'department':department})
@@ -424,8 +424,7 @@
 
     @classmethod
     def teardown_class(self):
-        self.purge_all_packages()
-        CreateTestData.delete()
+        model.repo.rebuild_db()
     
     def _do_search(self, q, wanted_results):
         options = QueryOptions()


--- a/ckan/tests/lib/test_resource_search.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/lib/test_resource_search.py	Sat May 21 10:19:01 2011 +0100
@@ -55,7 +55,7 @@
 
     @classmethod
     def teardown_class(self):
-        CreateTestData.delete()
+        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)


--- a/ckan/tests/lib/test_search_index.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/lib/test_search_index.py	Sat May 21 10:19:01 2011 +0100
@@ -20,7 +20,7 @@
 
     @classmethod
     def teardown_class(cls):
-        CreateTestData.delete()        
+        model.repo.rebuild_db()
 
     def test_index(self):
         search.dispatch_by_operation('Package', {'title': 'penguin'}, 'new', 
@@ -72,7 +72,7 @@
 
     @classmethod
     def teardown_class(self):
-        CreateTestData.delete()
+        model.repo.rebuild_db()
 
     def test_0_indexing(self):
         searches = model.metadata.bind.execute('SELECT package_id, search_vector FROM package_search').fetchall()


--- a/ckan/tests/models/test_extras.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/models/test_extras.py	Sat May 21 10:19:01 2011 +0100
@@ -9,7 +9,7 @@
 
     @classmethod 
     def teardown_class(self):
-        CreateTestData.delete()
+        model.repo.rebuild_db()
 
     def test_1(self):
         startrev = model.repo.youngest_revision().id


--- a/ckan/tests/models/test_misc.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/models/test_misc.py	Sat May 21 10:19:01 2011 +0100
@@ -9,7 +9,6 @@
 
     @classmethod
     def teardown_class(self):
-        CreateTestData.delete()
         model.repo.rebuild_db()
 
     def test_revision_packages(self):


--- a/ckan/tests/models/test_package.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/models/test_package.py	Sat May 21 10:19:01 2011 +0100
@@ -117,20 +117,6 @@
 
     @classmethod
     def teardown_class(self):
-        # should only be one but maybe things have gone wrong
-        # p = model.Package.by_name(self.pkgname)
-        pkgs = model.Session.query(model.Package).filter_by(name=self.pkgname)
-        for p in pkgs:
-            for pt in p.package_tags:
-                pt.purge()
-            p.purge()
-        t1 = model.Tag.by_name(self.tagname)
-        t1.purge()
-        t2 = model.Tag.by_name(self.tagname2)
-        t2.purge()
-        t3 = model.Tag.by_name(self.tagname3)
-        t3.purge()
-        model.Session.commit()
         model.repo.rebuild_db()
 
     def test_1(self):


--- a/ckan/tests/models/test_purge_revision.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/models/test_purge_revision.py	Sat May 21 10:19:01 2011 +0100
@@ -11,7 +11,7 @@
 
     @classmethod
     def teardown_class(self):
-        CreateTestData.delete()
+        model.repo.rebuild_db()
 
     def setup(self):
         self.pkgname = u'revision-purge-test'


--- a/ckan/tests/models/test_resource.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/models/test_resource.py	Sat May 21 10:19:01 2011 +0100
@@ -32,14 +32,12 @@
                                 extras={u'size':self.size},
                                 )
             rg.resources.append(pr)
-            pkg.resource_groups.append(rg)
         pr = model.Resource(url="no_extra",
                             format=self.format,
                             description=self.description,
                             hash=self.hash,
                             )
         rg.resources.append(pr)
-        pkg.resource_groups.append(rg)
         model.repo.commit_and_remove()
 
     def teardown(self):


--- a/ckan/tests/test_dumper.py	Thu May 19 18:48:11 2011 +0100
+++ b/ckan/tests/test_dumper.py	Sat May 21 10:19:01 2011 +0100
@@ -71,7 +71,7 @@
 
     @classmethod
     def teardown_class(self):
-        CreateTestData.delete()
+        model.repo.rebuild_db()
 
     def test_dump(self):
         assert os.path.exists(self.outpath)

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