[test] Use testutils module now provided by the seda cube
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 31 Mar 2017 11:41:47 +0200
changeset 255 f6460bb9bd8c
parent 252 a5f9d7f3d312
child 256 8fb9299594e6
[test] Use testutils module now provided by the seda cube
dev-requirements.txt
test/test_management.py
test/test_security.py
test/test_templates.py
test/testutils.py
--- a/dev-requirements.txt	Fri Mar 31 10:22:54 2017 +0200
+++ b/dev-requirements.txt	Fri Mar 31 11:41:47 2017 +0200
@@ -1,1 +1,2 @@
 pytest
+http://hg.logilab.org/master/cubes/seda/archive/tip.tar.bz2#egg=cubicweb-seda
--- a/test/test_management.py	Fri Mar 31 10:22:54 2017 +0200
+++ b/test/test_management.py	Fri Mar 31 11:41:47 2017 +0200
@@ -17,7 +17,7 @@
 from cubicweb.devtools.testlib import CubicWebTC
 from cubicweb.web.views import actions
 
-import testutils
+from cubicweb_seda import testutils
 
 
 class ActionTC(CubicWebTC):
--- a/test/test_security.py	Fri Mar 31 10:22:54 2017 +0200
+++ b/test/test_security.py	Fri Mar 31 11:41:47 2017 +0200
@@ -20,7 +20,7 @@
 from cubicweb import Unauthorized
 from cubicweb.devtools.testlib import CubicWebTC
 
-import testutils
+from cubicweb_seda import testutils
 
 
 class SecurityTC(CubicWebTC):
--- a/test/test_templates.py	Fri Mar 31 10:22:54 2017 +0200
+++ b/test/test_templates.py	Fri Mar 31 11:41:47 2017 +0200
@@ -16,30 +16,16 @@
 
 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):
@@ -49,7 +35,7 @@
 
     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):
--- a/test/testutils.py	Fri Mar 31 10:22:54 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-# copyright 2016-2017 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_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