Add a regression test for Extranet #43776568
authorDenis Laxalde <denis.laxalde@logilab.fr>
Mon, 22 Jan 2018 17:26:58 +0100
changeset 3419 f0e22d15953e
parent 3418 311c3c0222ce
child 3421 f0a811ee873a
Add a regression test for Extranet #43776568 Before changeset 919faf33df18 in cubicweb-seda, this test pass.
test/test_seda.py
--- a/test/test_seda.py	Mon Jan 08 14:43:52 2018 +0100
+++ b/test/test_seda.py	Mon Jan 22 17:26:58 2018 +0100
@@ -15,8 +15,11 @@
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-saem-ref tests for SEDA cube integration"""
 
+import re
 import unittest
 
+from six import text_type
+
 from cubicweb.devtools.testlib import CubicWebTC
 
 from cubicweb_seda.entities.profile_generation import SEDA1XSDExport, SEDA2RelaxNGExport
@@ -95,5 +98,36 @@
                 self.assertIn('ark:/' + record.ark, xml)
 
 
+class CloneImportTC(CubicWebTC):
+    """Tests for cubicweb-seda's seda.doimport controller, making sure it
+    works in SAEM-Ref as well.
+
+    Copied and adapted eponymous class in cubicweb-seda/test/test_views.py.
+    """
+
+    def setup_database(self):
+        with self.admin_access.cnx() as cnx:
+            transfer = testutils.setup_profile(cnx, title=u'test')
+            unit, unit_alt, unit_alt_seq = testutils.create_archive_unit(None, cnx=cnx,
+                                                                         user_cardinality=u'1',
+                                                                         user_annotation=u'plop')
+            self.transfer_eid = transfer.eid
+            self.unit_eid = unit.eid
+            cnx.commit()
+
+    def test_import_one_entity(self):
+        params = dict(eid=text_type(self.transfer_eid),
+                      cloned=text_type(self.unit_eid))
+        with self.admin_access.web_request(**params) as req:
+            path, _ = self.expect_redirect_handle_request(
+                req, 'seda.doimport')
+            match = re.match(r'^ark:/0/p0*(\d+)$', path)
+            assert match, path
+            eid = int(match.group(1))
+            rset = req.execute('Any X WHERE X seda_archive_unit P, P eid %(p)s',
+                               {'p': eid})
+            self.assertTrue(rset)
+
+
 if __name__ == '__main__':
     unittest.main()