[test] Introduce a testutils module with functions collected from test modules
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 25 Aug 2016 16:56:08 +0200
changeset 1554 dce90c3bd6f4
parent 1553 f9f6974d3f6b
child 1555 d1c4f5a8fc8a
[test] Introduce a testutils module with functions collected from test modules
test/test_hooks.py
test/test_profile_generation.py
test/test_schema.py
test/test_views.py
test/testutils.py
--- a/test/test_hooks.py	Thu Aug 25 16:47:23 2016 +0200
+++ b/test/test_hooks.py	Thu Aug 25 16:56:08 2016 +0200
@@ -18,8 +18,7 @@
 from cubicweb import ValidationError
 from cubicweb.devtools.testlib import CubicWebTC
 
-from test_schema import create_transfer_to_bdo
-from test_profile_generation import scheme_for_rtype, create_archive_unit
+from testutils import create_transfer_to_bdo, create_archive_unit, scheme_for_rtype
 
 
 class ValidationHooksTC(CubicWebTC):
--- a/test/test_profile_generation.py	Thu Aug 25 16:47:23 2016 +0200
+++ b/test/test_profile_generation.py	Thu Aug 25 16:56:08 2016 +0200
@@ -26,6 +26,8 @@
 from cubes.seda.xsd2yams import XSDMMapping
 from cubes.seda.entities.profile_generation import _path_target_values
 
+from testutils import create_archive_unit, scheme_for_rtype
+
 
 class XmlTestMixin(object):
     """Mixin class provinding additional assertion methods for checking XML data."""
@@ -187,32 +189,6 @@
                 edef['type'] = 'xsd:' + datatype.attrib['type']
 
 
-def create_archive_unit(parent, **kwargs):
-    cnx = parent._cw
-    kwargs.setdefault('id', u'au1')
-    au = cnx.create_entity('SEDAArchiveUnit', seda_archive_unit=parent, **kwargs)
-    alt = cnx.create_entity('SEDAAltArchiveUnitArchiveUnitRefId',
-                            reverse_seda_alt_archive_unit_archive_unit_ref_id=au)
-    alt_seq = cnx.create_entity(
-        'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement',
-        reverse_seda_seq_alt_archive_unit_archive_unit_ref_id_management=alt)
-    return au, alt, alt_seq
-
-
-def map_cs_to_rtype(scheme, rtype):
-    cnx = scheme._cw
-    cnx.execute('SET CS scheme_relation_type RT WHERE CS eid %(cs)s, RT name %(rt)s',
-                {'cs': scheme.eid, 'rt': rtype})
-
-
-def scheme_for_rtype(cnx, rtype, *concept_labels):
-    scheme = cnx.create_entity('ConceptScheme', title=u'{0} vocabulary'.format(rtype))
-    map_cs_to_rtype(scheme, rtype)
-    for label in concept_labels:
-        scheme.add_concept(label)
-    return scheme
-
-
 class PathTargetValuesTC(CubicWebTC):
 
     def test_path(self):
--- a/test/test_schema.py	Thu Aug 25 16:47:23 2016 +0200
+++ b/test/test_schema.py	Thu Aug 25 16:56:08 2016 +0200
@@ -21,21 +21,7 @@
 from cubicweb.devtools.testlib import CubicWebTC
 from cubicweb.schema import ERQLExpression, RRQLExpression
 
-from test_profile_generation import create_archive_unit
-
-
-def create_transfer_to_bdo(cnx):
-    """Create minimal ArchiveTransfer down to a BinaryDataObject and return the later."""
-    create = cnx.create_entity
-    transfer = create('SEDAArchiveTransfer', title=u'test profile')
-    bdo = create('SEDABinaryDataObject', id=u"bdo1", seda_binary_data_object=transfer)
-    choice = create('SEDAAltBinaryDataObjectAttachment',
-                    reverse_seda_alt_binary_data_object_attachment=bdo)
-    create('SEDAAttachment', seda_attachment=choice)  # Choice cannot be empty
-    # commit and clear cache to allow access to container relation
-    cnx.commit()
-    bdo.cw_clear_all_caches()
-    return bdo
+from testutils import create_archive_unit, create_transfer_to_bdo
 
 
 class SchemaTC(CubicWebTC):
--- a/test/test_views.py	Thu Aug 25 16:47:23 2016 +0200
+++ b/test/test_views.py	Thu Aug 25 16:56:08 2016 +0200
@@ -18,7 +18,7 @@
 from cubicweb.devtools.testlib import CubicWebTC
 from cubicweb.web import INTERNAL_FIELD_VALUE
 
-from test_schema import create_transfer_to_bdo
+from testutils import create_transfer_to_bdo
 
 
 class ManagementRulesTC(CubicWebTC):
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/testutils.py	Thu Aug 25 16:56:08 2016 +0200
@@ -0,0 +1,56 @@
+# copyright 2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr -- mailto:contact@logilab.fr
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# 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/>.
+"""Miscellaneous test utilities."""
+
+
+def create_transfer_to_bdo(cnx):
+    """Create minimal ArchiveTransfer down to a BinaryDataObject and return the later."""
+    create = cnx.create_entity
+    transfer = create('SEDAArchiveTransfer', title=u'test profile')
+    bdo = create('SEDABinaryDataObject', id=u"bdo1", seda_binary_data_object=transfer)
+    choice = create('SEDAAltBinaryDataObjectAttachment',
+                    reverse_seda_alt_binary_data_object_attachment=bdo)
+    create('SEDAAttachment', seda_attachment=choice)  # Choice cannot be empty
+    # commit and clear cache to allow access to container relation
+    cnx.commit()
+    bdo.cw_clear_all_caches()
+    return bdo
+
+
+def create_archive_unit(parent, **kwargs):
+    cnx = parent._cw
+    kwargs.setdefault('id', u'au1')
+    au = cnx.create_entity('SEDAArchiveUnit', seda_archive_unit=parent, **kwargs)
+    alt = cnx.create_entity('SEDAAltArchiveUnitArchiveUnitRefId',
+                            reverse_seda_alt_archive_unit_archive_unit_ref_id=au)
+    alt_seq = cnx.create_entity(
+        'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement',
+        reverse_seda_seq_alt_archive_unit_archive_unit_ref_id_management=alt)
+    return au, alt, alt_seq
+
+
+def map_cs_to_rtype(scheme, rtype):
+    cnx = scheme._cw
+    cnx.execute('SET CS scheme_relation_type RT WHERE CS eid %(cs)s, RT name %(rt)s',
+                {'cs': scheme.eid, 'rt': rtype})
+
+
+def scheme_for_rtype(cnx, rtype, *concept_labels):
+    scheme = cnx.create_entity('ConceptScheme', title=u'{0} vocabulary'.format(rtype))
+    map_cs_to_rtype(scheme, rtype)
+    for label in concept_labels:
+        scheme.add_concept(label)
+    return scheme