[PATCH sherpa] [test] Use testutils module now provided by the seda cube

Sylvain Thenault sylvain.thenault at logilab.fr
Tue Apr 11 15:40:53 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1490953307 -7200
#      Fri Mar 31 11:41:47 2017 +0200
# Node ID 43ab707fda2e9a8a1603d670eb54c3ab66ac1c86
# Parent  a5f9d7f3d31260028f9bcebc4f907047fd35629b
[test] Use testutils module now provided by the seda cube

diff --git a/dev-requirements.txt b/dev-requirements.txt
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -1,1 +1,2 @@
 pytest
+http://hg.logilab.org/review/cubes/seda/archive/tip.tar.bz2#egg=cubicweb-seda
diff --git a/test/test_management.py b/test/test_management.py
--- a/test/test_management.py
+++ b/test/test_management.py
@@ -15,11 +15,11 @@
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 from cubicweb.devtools.testlib import CubicWebTC
 from cubicweb.web.views import actions
 
-import testutils
+from cubicweb_seda import testutils
 
 
 class ActionTC(CubicWebTC):
 
     def assertMayManageSecurity(self, req, eid):
diff --git a/test/test_security.py b/test/test_security.py
--- a/test/test_security.py
+++ b/test/test_security.py
@@ -18,11 +18,11 @@
 from contextlib import contextmanager
 
 from cubicweb import Unauthorized
 from cubicweb.devtools.testlib import CubicWebTC
 
-import testutils
+from cubicweb_seda import testutils
 
 
 class SecurityTC(CubicWebTC):
 
     @contextmanager
diff --git a/test/test_templates.py b/test/test_templates.py
--- a/test/test_templates.py
+++ b/test/test_templates.py
@@ -14,44 +14,30 @@
 # You should have received a copy of the GNU General Public License
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 from cubicweb.devtools.testlib import CubicWebTC
 
+from cubicweb_seda import testutils
 from cubicweb_sherpa.views.templates import _compute_active_path
 
 
-def create_archive_unit(parent, title=None, **kwargs):
-    """Create an archive unit and its mandatory children and return them.
-    """
-    cnx = kwargs.pop('cnx', getattr(parent, '_cw', None))
-    kwargs.setdefault('user_annotation', u'archive unit title')
-    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)
-    last = cnx.create_entity(
-        'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement',
-        reverse_seda_seq_alt_archive_unit_archive_unit_ref_id_management=alt)
-    cnx.create_entity('SEDATitle', seda_title=last, title=title)
-    return au, alt, last
-
-
 class ActivePathTC(CubicWebTC):
 
     def test_archive_transfer(self):
         with self.admin_access.cnx() as cnx:
             at = cnx.create_entity('SEDAArchiveTransfer', title=u'hop')
-            au, alt, last = create_archive_unit(at)
+            au, alt, last = testutils.create_archive_unit(at)
             cnx.commit()
 
             for entity in (at, au, alt, last):
                 with self.subTest(entity=entity):
                     self.assertEqual(_compute_active_path(entity.as_rset()),
                                      'sedaarchivetransfer')
 
     def test_archive_unit(self):
         with self.admin_access.cnx() as cnx:
-            au, alt, last = create_archive_unit(None, cnx=cnx)
+            au, alt, last = testutils.create_archive_unit(None, cnx=cnx)
             cnx.commit()
 
             for entity in (au, alt, last):
                 with self.subTest(entity=entity):
                     self.assertEqual(_compute_active_path(entity.as_rset()),
diff --git a/test/testutils.py b/test/testutils.py
deleted file mode 100644
--- a/test/testutils.py
+++ /dev/null
@@ -1,43 +0,0 @@
-# copyright 2016-2017 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr -- mailto:contact at 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_archive_unit(parent, **kwargs):
-    """Create an archive unit and its mandatory children, return a 3-uple
-
-         (archive unit, alternative, sequence)
-    """
-    cnx = kwargs.pop('cnx', getattr(parent, '_cw', None))
-    kwargs.setdefault('user_annotation', u'archive unit title')
-    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)
-    last = cnx.create_entity(
-        'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement',
-        reverse_seda_seq_alt_archive_unit_archive_unit_ref_id_management=alt)
-    cnx.create_entity('SEDATitle', seda_title=last)
-
-    return au, alt, last
-
-
-def create_authority_record(cnx, name, kind=u'person', **kwargs):
-    """Return an AuthorityRecord with specified kind and name."""
-    kind_eid = cnx.find('AgentKind', name=kind)[0][0]
-    record = cnx.create_entity('AuthorityRecord', agent_kind=kind_eid, **kwargs)
-    cnx.create_entity('NameEntry', parts=name, form_variant=u'authorized',
-                      name_entry_for=record)
-    return record


More information about the saem-devel mailing list