[PATCH 07 of 11 saem_ref] Use postgres in all tests

Denis Laxalde denis.laxalde at logilab.fr
Mon Feb 12 15:20:43 CET 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1518427521 -3600
#      Mon Feb 12 10:25:21 2018 +0100
# Node ID 43cf7062f7aa13401eb6e7dc839a621d72e8b7c8
# Parent  3c72046c3ed6ef2ed369a7a8a5fba28a830d8add
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 43cf7062f7aa
# EXP-Topic ark/postgres-generated
Use postgres in all tests

This will be required when ARK identifiers will be generated through
postgresql.

diff --git a/test/test_ccplugin.py b/test/test_ccplugin.py
--- a/test/test_ccplugin.py
+++ b/test/test_ccplugin.py
@@ -36,6 +36,8 @@ def setUpModule():
 
 class CCPluginTC(testlib.CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def setup_database(self):
         super(CCPluginTC, self).setup_database()
         self.orig_config_for = CubicWebConfiguration.config_for
@@ -47,7 +49,6 @@ class CCPluginTC(testlib.CubicWebTC):
 
 
 class ImportEacDataCommandTC(CCPluginTC):
-    configcls = PostgresApptestConfiguration
 
     def setup_database(self):
         super(ImportEacDataCommandTC, self).setup_database()
diff --git a/test/test_eac.py b/test/test_eac.py
--- a/test/test_eac.py
+++ b/test/test_eac.py
@@ -18,13 +18,20 @@ from datetime import datetime
 
 from lxml import etree
 
+from cubicweb.devtools import PostgresApptestConfiguration
 from cubicweb.devtools.testlib import CubicWebTC
 
 import testutils
 
 
+def setUpModule():
+    testutils.startpgcluster(__file__)
+
+
 class EACExportTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def test_associated_with(self):
         with self.admin_access.client_cnx() as cnx:
             record = testutils.authority_record(cnx, u'My record')
diff --git a/test/test_entities_rdf.py b/test/test_entities_rdf.py
--- a/test/test_entities_rdf.py
+++ b/test/test_entities_rdf.py
@@ -21,6 +21,7 @@ from six import text_type
 
 import mock
 
+from cubicweb.devtools import PostgresApptestConfiguration
 from cubicweb.devtools.testlib import CubicWebTC
 
 from cubes.skos.rdfio import RDFLibRDFGraph, RDFRegistry
@@ -31,9 +32,15 @@ from cubicweb_saem_ref.entities import r
 import testutils
 
 
+def setUpModule():
+    testutils.startpgcluster(__file__)
+
+
 class RDFExportTC(testutils.XmlTestMixin, CubicWebTC):
     """Test case for RDF export"""
 
+    configcls = PostgresApptestConfiguration
+
     def setUp(self):
         super(RDFExportTC, self).setUp()
         self.reg = RDFRegistry()
diff --git a/test/test_oai.py b/test/test_oai.py
--- a/test/test_oai.py
+++ b/test/test_oai.py
@@ -23,6 +23,7 @@ from dateutil.parser import parse as par
 from lxml import etree
 import pytz
 
+from cubicweb.devtools import PostgresApptestConfiguration
 from cubicweb.devtools.testlib import CubicWebTC
 from cubicweb.pyramid.test import PyramidCWTest
 
@@ -32,6 +33,11 @@ from cubicweb_saem_ref import permanent_
 
 import testutils
 
+
+def setUpModule():
+    testutils.startpgcluster(__file__)
+
+
 EntityInfo = namedtuple('EntityInfo', ['ark', 'url', 'eid'])
 
 
@@ -56,6 +62,8 @@ class OAITestMixin(object):
 
 class OAIComponentTC(CubicWebTC, OAITestMixin):
 
+    configcls = PostgresApptestConfiguration
+
     def test_registered(self):
         with self.admin_access.repo_cnx() as cnx:
             oai = self.oai_component(cnx)
@@ -120,6 +128,8 @@ def setup_organization_units(cnx):
 
 class OAIRequestTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def test_rset(self):
         """Test `rset` function for exceptions."""
         with self.admin_access.repo_cnx() as cnx:
@@ -154,6 +164,8 @@ def no_validate_xml(method):
 
 
 class OAIPMHViewsTC(PyramidCWTest, OAITestMixin, testutils.XmlTestMixin):
+
+    configcls = PostgresApptestConfiguration
     settings = {
         # to get clean traceback in tests (instead of in an html error page)
         'cubicweb.bwcompat': False,
diff --git a/test/test_pviews.py b/test/test_pviews.py
--- a/test/test_pviews.py
+++ b/test/test_pviews.py
@@ -18,12 +18,18 @@
 
 import lxml.etree
 
+from cubicweb.devtools import PostgresApptestConfiguration
 from cubicweb.pyramid.test import PyramidCWTest
 
 import testutils
 
 
+def setUpModule():
+    testutils.startpgcluster(__file__)
+
+
 class EACWSTC(PyramidCWTest):
+    configcls = PostgresApptestConfiguration
     settings = {'cubicweb.bwcompat': True}
 
     def test_xml_post(self):
diff --git a/test/test_saem_ref.py b/test/test_saem_ref.py
--- a/test/test_saem_ref.py
+++ b/test/test_saem_ref.py
@@ -19,7 +19,10 @@ from functools import partial
 from unittest import TestCase
 from logilab.common import attrdict
 
-from cubicweb.devtools import testlib
+from cubicweb.devtools import (
+    PostgresApptestConfiguration,
+    testlib,
+)
 from cubicweb.schema import SCHEMA_TYPES
 
 from cubicweb_saem_ref import cwuri_url
@@ -27,6 +30,10 @@ from cubicweb_saem_ref import cwuri_url
 import testutils
 
 
+def setUpModule():
+    testutils.startpgcluster(__file__)
+
+
 class CWURI_URLTC(TestCase):
 
     def test(self):
@@ -48,6 +55,8 @@ class CWURI_URLTC(TestCase):
 
 class ArkURLTC(testlib.CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def setup_database(self):
         with self.admin_access.cnx() as cnx:
             testutils.authority_with_naa(cnx)
@@ -82,6 +91,7 @@ class ArkURLTC(testlib.CubicWebTC):
 
 
 class AutomaticWebTest(testlib.AutomaticWebTest):
+    configcls = PostgresApptestConfiguration
     test_ten_each_config = None  # deactivate attempt to auto populate
     skip_views = set([
         'calendar',
diff --git a/test/test_security.py b/test/test_security.py
--- a/test/test_security.py
+++ b/test/test_security.py
@@ -16,17 +16,25 @@
 """Functional security tests."""
 
 from datetime import date
+
+from cubicweb.devtools import PostgresApptestConfiguration
 from cubicweb.devtools.testlib import CubicWebTC
 
 import testutils
 
 
+def setUpModule():
+    testutils.startpgcluster(__file__)
+
+
 class NonManagerUserTC(CubicWebTC):
     """Tests checking that a user in "users" group only can do things.
 
     Most of the times, we do not call any assertion method and only rely on no
     error being raised.
     """
+    configcls = PostgresApptestConfiguration
+
     assertUnauthorized = testutils.assertUnauthorized
 
     login = u'bob'
@@ -279,6 +287,8 @@ class ManagerUserTC(CubicWebTC):
     Most of the times, we do not call any assertion method and only rely on no
     error being raised.
     """
+    configcls = PostgresApptestConfiguration
+
     assertUnauthorized = testutils.assertUnauthorized
 
     def test_create_update_organization(self):
diff --git a/test/test_seda.py b/test/test_seda.py
--- a/test/test_seda.py
+++ b/test/test_seda.py
@@ -20,6 +20,7 @@ import unittest
 
 from six import text_type
 
+from cubicweb.devtools import PostgresApptestConfiguration
 from cubicweb.devtools.testlib import CubicWebTC
 
 from cubicweb_seda.entities.profile_generation import SEDA1XSDExport, SEDA2RelaxNGExport
@@ -29,6 +30,10 @@ from cubicweb_saem_ref.entities import s
 import testutils
 
 
+def setUpModule():
+    testutils.startpgcluster(__file__)
+
+
 class CWURIURLTC(unittest.TestCase):
 
     def test(self):
@@ -62,6 +67,8 @@ class CWURIURLTC(unittest.TestCase):
 
 class SEDAExportTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def iter_seda_xsd(self, transfer):
         """Yield XSD representations of the transfer for SEDA 0.2 then 1.0,
         within a subTest.
@@ -105,6 +112,8 @@ class CloneImportTC(CubicWebTC):
     Copied and adapted eponymous class in cubicweb-seda/test/test_views.py.
     """
 
+    configcls = PostgresApptestConfiguration
+
     def setup_database(self):
         with self.admin_access.cnx() as cnx:
             transfer = testutils.setup_profile(cnx, title=u'test')
diff --git a/test/test_views.py b/test/test_views.py
--- a/test/test_views.py
+++ b/test/test_views.py
@@ -29,6 +29,7 @@ from six import text_type
 
 from yams.schema import role_name
 
+from cubicweb.devtools import PostgresApptestConfiguration
 from cubicweb.devtools.testlib import CubicWebTC
 
 from cubes.skos.rdfio import default_graph
@@ -38,6 +39,10 @@ from cubicweb_saem_ref.views.widgets imp
 import testutils
 
 
+def setUpModule():
+    testutils.startpgcluster(__file__)
+
+
 def eid_from_ark(ark):
     name = ark.rsplit('/', 1)[-1]
     num = ''.join(c for c in name if c.isdigit())
@@ -79,6 +84,8 @@ class SetDateTC(unittest.TestCase):
 
 class FuncViewsTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def test_citation_view(self):
         with self.admin_access.cnx() as cnx:
             bob = testutils.authority_record(cnx, u'bob')
@@ -243,6 +250,8 @@ class FuncViewsTC(CubicWebTC):
 
 class SEDAViewsTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def test_seda_get_related_version(self):
         """Check that we get correct results when asking for `draft`, `published`, `replaced`
         version of a profile."""
@@ -304,6 +313,8 @@ class SEDAViewsTC(CubicWebTC):
 
 class ArkViewsTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def test_ark_authority_record_creation(self):
         with self.admin_access.cnx() as cnx:
             org = testutils.authority_with_naa(cnx)
@@ -404,6 +415,8 @@ class ArkViewsTC(CubicWebTC):
 
 class AssignArkWebServiceTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def test_not_authenticated(self):
         with self.new_access('anon').web_request(headers={'Accept': 'application/json'},
                                                  method='POST') as req:
@@ -484,6 +497,8 @@ class AssignArkWebServiceTC(CubicWebTC):
 
 
 class ListArchivalUnitsServiceTC(CubicWebTC):
+
+    configcls = PostgresApptestConfiguration
     maxDiff = None
 
     def test_ok(self):
@@ -568,6 +583,8 @@ class ListArchivalUnitsServiceTC(CubicWe
 
 class TimelineViewsTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def test_timeline_json(self):
         with self.admin_access.cnx() as cnx:
             ar1 = testutils.authority_record(
diff --git a/test/unittest_dataimport.py b/test/unittest_dataimport.py
--- a/test/unittest_dataimport.py
+++ b/test/unittest_dataimport.py
@@ -19,13 +19,20 @@
 from os.path import basename
 
 from cubicweb.dataimport.importer import SimpleImportLog
+from cubicweb.devtools import PostgresApptestConfiguration
 from cubicweb.devtools.testlib import CubicWebTC
 
 import testutils
 
 
+def setUpModule():
+    testutils.startpgcluster(__file__)
+
+
 class EACDataImportTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def setup_database(self):
         with self.admin_access.repo_cnx() as cnx:
             self.create_user(cnx, u'bob', ('users', ),
diff --git a/test/unittest_entities.py b/test/unittest_entities.py
--- a/test/unittest_entities.py
+++ b/test/unittest_entities.py
@@ -14,11 +14,20 @@
 # You should have received a copy of the GNU Lesser General Public License along
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 
+from cubicweb.devtools import PostgresApptestConfiguration
 from cubicweb.devtools.testlib import CubicWebTC
 
+import testutils
+
+
+def setUpModule():
+    testutils.startpgcluster(__file__)
+
 
 class ArkGeneratorTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def test_eid(self):
         with self.admin_access.repo_cnx() as cnx:
             generator = self.vreg['adapters'].select(
diff --git a/test/unittest_entities_container.py b/test/unittest_entities_container.py
--- a/test/unittest_entities_container.py
+++ b/test/unittest_entities_container.py
@@ -15,6 +15,7 @@
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-saem_ref unit tests for entities.container"""
 
+from cubicweb.devtools import PostgresApptestConfiguration
 from cubicweb.devtools.testlib import CubicWebTC
 
 from cubicweb_saem_ref.entities import container
@@ -22,6 +23,10 @@ from cubicweb_saem_ref.entities import c
 import testutils
 
 
+def setUpModule():
+    testutils.startpgcluster(__file__)
+
+
 def sort_container(container_def):
     for k, v in container_def:
         yield k, sorted(v)
@@ -29,6 +34,8 @@ def sort_container(container_def):
 
 class ContainerTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def test_authorityrecord_container(self):
         # line below should be copied from entities.container.registration_callback
         container_def = container.authority_record_container_def(self.schema)
@@ -76,6 +83,8 @@ class ContainerTC(CubicWebTC):
 
 class TreeTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def test_seda_profile_clone(self):
         """Functional test for SEDA profile cloning."""
         with self.admin_access.repo_cnx() as cnx:
diff --git a/test/unittest_entities_skos.py b/test/unittest_entities_skos.py
--- a/test/unittest_entities_skos.py
+++ b/test/unittest_entities_skos.py
@@ -15,13 +15,20 @@
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-saem_ref unit tests for entities.skos"""
 
+from cubicweb.devtools import PostgresApptestConfiguration
 from cubicweb.devtools.testlib import CubicWebTC
 
 import testutils
 
 
+def setUpModule():
+    testutils.startpgcluster(__file__)
+
+
 class ConceptSchemeTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def test_optimized_top_concepts(self):
         with self.admin_access.cnx() as cnx:
             scheme = cnx.create_entity('ConceptScheme', ark_naa=testutils.naa(cnx))
diff --git a/test/unittest_hooks.py b/test/unittest_hooks.py
--- a/test/unittest_hooks.py
+++ b/test/unittest_hooks.py
@@ -21,17 +21,25 @@ import unittest
 
 import pytz
 
+from cubicweb.devtools import PostgresApptestConfiguration
 from cubicweb.devtools.testlib import CubicWebTC
 
 from cubicweb_saem_ref.hooks import extract_ark
 
 import testutils
 
+
+def setUpModule():
+    testutils.startpgcluster(__file__)
+
+
 YESTERDAY = datetime.now(tz=pytz.utc) - timedelta(days=1)
 
 
 class SAEMRefHooksTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def assertMDNow(self, entity):
         entity.cw_clear_all_caches()
         self.assertAlmostEqual(mktime(entity.modification_date.timetuple()),
@@ -275,6 +283,8 @@ class SAEMRefHooksTC(CubicWebTC):
 
 class AuthorityRecordHookTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def setup_database(self):
         with self.admin_access.cnx() as cnx:
             self.org_eid = testutils.authority_with_naa(cnx).eid
@@ -305,6 +315,8 @@ class AuthorityRecordHookTC(CubicWebTC):
 
 class ExtractArkTC(unittest.TestCase):
 
+    configcls = PostgresApptestConfiguration
+
     def test_ok(self):
         self.assertEqual(extract_ark('http://dcf/res/ark:/67717/1234'), '67717/1234')
         self.assertEqual(extract_ark('http://dcf/res/ark:/67717/1234#something'), '67717/1234')
@@ -319,6 +331,8 @@ class ExtractArkTC(unittest.TestCase):
 
 class EntityLifeCycleTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def setup_database(self):
         with self.admin_access.repo_cnx() as cnx:
             bob = self.create_user(cnx, u'bob',
@@ -553,6 +567,8 @@ class EntityLifeCycleTC(CubicWebTC):
 
 class SEDAArchiveTransferHooksTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def test_profile_deprecated(self):
         """Test hook deprecating a SEDA Profile upon successor publication."""
         with self.admin_access.repo_cnx() as cnx:
diff --git a/test/unittest_schema.py b/test/unittest_schema.py
--- a/test/unittest_schema.py
+++ b/test/unittest_schema.py
@@ -18,6 +18,7 @@
 import unittest
 from datetime import date
 
+from cubicweb.devtools import PostgresApptestConfiguration
 from cubicweb.devtools.testlib import CubicWebTC
 
 from cubicweb_compound.utils import optional_relations, graph_relations
@@ -26,6 +27,10 @@ from cubicweb_saem_ref import ConceptSch
 import testutils
 
 
+def setUpModule():
+    testutils.startpgcluster(__file__)
+
+
 def create_published_records_panel(cnx):
     for name, kind in (
         (u"Mr Pink", u"person"),
@@ -39,6 +44,8 @@ def create_published_records_panel(cnx):
 
 
 class SchemaConstraintsTC(CubicWebTC):
+
+    configcls = PostgresApptestConfiguration
     assertValidationError = testutils.assertValidationError
 
     def test_published_constraint_on_contact_point(self):
@@ -227,6 +234,8 @@ class SchemaConstraintsTC(CubicWebTC):
 
 class AuthorityRecordTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def test_fti(self):
         with self.admin_access.repo_cnx() as cnx:
             agent = testutils.authority_record(cnx, u'Guenievre', kind=u'person',
@@ -245,6 +254,8 @@ class AuthorityRecordTC(CubicWebTC):
 
 class ConceptSchemeTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def test_graph_structure(self):
         graph = ConceptSchemeGraph(self.schema)
         expected = {
diff --git a/test/unittest_sobjects_skos.py b/test/unittest_sobjects_skos.py
--- a/test/unittest_sobjects_skos.py
+++ b/test/unittest_sobjects_skos.py
@@ -82,6 +82,8 @@ class SKOSImportTC(CubicWebTC):
 
 class LCSVImportTC(CubicWebTC):
 
+    configcls = PostgresApptestConfiguration
+
     def test_cwuri_with_ark(self):
         with self.admin_access.repo_cnx() as cnx:
             scheme = cnx.create_entity('ConceptScheme', ark_naa=testutils.naa(cnx))



More information about the saem-devel mailing list