[PATCH 1 of 2 saem] [schema] Drop 'draft' state for Agent and OrganizationUnit

Sylvain Thenault sylvain.thenault at logilab.fr
Tue Oct 31 17:56:10 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1509459492 -3600
#      Tue Oct 31 15:18:12 2017 +0100
# Node ID 24b65167e016aef51eb65c47d8c2c93772e18b0b
# Parent  dfd42c0fe159fcba5df4152907cfb54f31028998
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 24b65167e016
[schema] Drop 'draft' state for Agent and OrganizationUnit

so their default state is 'published'. This deprecates some OAI tests and
several others have to be updated.

Related to extranet #37370184

diff --git a/cubicweb_saem_ref/workflows.py b/cubicweb_saem_ref/workflows.py
--- a/cubicweb_saem_ref/workflows.py
+++ b/cubicweb_saem_ref/workflows.py
@@ -19,18 +19,22 @@ from cubicweb import _
 
 
 def define_publication_workflow(add_workflow, etype):
     """Define a publication workflow for `etype`."""
     wf = add_workflow('publication workflow', etype)
-    draft = wf.add_state(_('draft'), initial=True)
-    published = wf.add_state(_('published'))
+    if etype in ('Agent', 'OrganizationUnit'):
+        published = wf.add_state(_('published'), initial=True)
+    else:
+        draft = wf.add_state(_('draft'), initial=True)
+        published = wf.add_state(_('published'))
+
+        if etype == 'SEDAArchiveTransfer':
+            wf.add_transition(_('publish'), (draft, ), published,
+                              conditions=('U in_group G, G name IN ("users", "managers"),'
+                                          'X compat_list ~= "%SEDA 0.2%"',))
+        else:
+            wf.add_transition(_('publish'), (draft, ), published,
+                              requiredgroups=('managers', 'users'))
     deprecated = wf.add_state(_('deprecated'))
-    if etype == 'SEDAArchiveTransfer':
-        wf.add_transition(_('publish'), (draft, ), published,
-                          conditions=('U in_group G, G name IN ("users", "managers"),'
-                                      'X compat_list ~= "%SEDA 0.2%"',))
-    else:
-        wf.add_transition(_('publish'), (draft, ), published,
-                          requiredgroups=('managers', 'users'))
     wf.add_transition(_('deprecate'), (published, ), deprecated,
                       requiredgroups=('managers', 'users'))
     return wf
diff --git a/test/test_oai.py b/test/test_oai.py
--- a/test/test_oai.py
+++ b/test/test_oai.py
@@ -103,23 +103,20 @@ class OAIComponentTC(CubicWebTC, OAITest
             setspecs = [x[0] for x in oai.setspecs()]
             self.assertCountEqual(setspecs, expected)
 
 
 def setup_organization_units(cnx):
-    """Create three agents (alice, bobby and draft), publish alice and bobby but not draft, and return
-    the (ark, url, eid) attributes of alice and bobby.
+    """Create two agents (alice and bobby) in published state and return their
+    (ark, url, eid) attributes.
     """
     alice = testutils.organization_unit(cnx, u'alice',
                                         archival_roles=[u'producer'])
     cnx.commit()
-    publish_entity(alice)
     bobby = testutils.organization_unit(cnx, u'bobby',
                                         archival_roles=[u'enquirer'])
     cnx.commit()
-    publish_entity(bobby)
-    testutils.organization_unit(cnx, u'draft', archival_roles=[u'enquirer'])
-    cnx.commit()
+
     return (
         EntityInfo(alice.ark, permanent_url(alice), alice.eid),
         EntityInfo(bobby.ark, permanent_url(bobby), bobby.eid),
     )
 
@@ -275,12 +272,10 @@ class OAIPMHViewsTC(PyramidCWTest, OAITe
             result = self.oai_request(req, verb='ListIdentifiers',
                                       set='organizationunit',
                                       metadataPrefix='rdf')
             self.assertIn('<identifier>ark:/{0}</identifier>'.format(bobby), result)
             self.assertIn('<identifier>ark:/{0}</identifier>'.format(alice), result)
-            draft = req.execute('Any A WHERE X ark A, X name "draft"')[0][0]
-            self.assertNotIn(draft, result)
             result = self.oai_request(req, verb='ListIdentifiers',
                                       set='organizationunit:role:producer',
                                       metadataPrefix='rdf')
             self.assertIn('<identifier>ark:/{0}</identifier>'.format(alice),
                           result)
@@ -296,24 +291,10 @@ class OAIPMHViewsTC(PyramidCWTest, OAITe
                                       metadataPrefix='rdf')
             result = self.oai_request(req, verb='ListIdentifiers',
                                       set='profile', metadataPrefix='seda02xsd')
             self.assertIn('<identifier>ark:/{0}</identifier>'.format(profile.ark), result)
 
-    def test_listidentifiers_setspec_wfstate(self):
-        """Check workflow state condition is statisfied with a multi-level
-        setspec `organizationunit:role:enquirer`.
-        """
-        alice, bobby = [x.ark for x in self._setup_organization_units()]
-        self._setup_profile()
-        with self.admin_access.web_request() as req:
-            result = self.oai_request(req, verb='ListIdentifiers',
-                                      set='organizationunit:role:enquirer',
-                                      metadataPrefix='rdf')
-            self.assertIn('<identifier>ark:/{0}</identifier>'.format(bobby), result)
-            draft = req.execute('Any A WHERE X ark A, X name "draft"')[0][0]
-            self.assertNotIn(draft, result)
-
     def test_listidentifiers_deleted(self):
         """Check <header> element (status attribute, datestamp) for deleted
         records in ListIdentifiers response.
         """
         alice, bobby = self._setup_organization_units()
@@ -347,12 +328,10 @@ class OAIPMHViewsTC(PyramidCWTest, OAITe
                                       metadataPrefix='rdf')
             self.assertIn(
                 '<rdf:Description rdf:about="{0}">'.format(bobby.url), result)
             self.assertIn(
                 '<rdf:Description rdf:about="{0}">'.format(alice.url), result)
-            draft = req.execute('Any A WHERE X ark A, X name "draft"')[0][0]
-            self.assertNotIn(draft, result)
             result = self.oai_request(
                 req, verb='ListRecords', set='organizationunit:role:producer',
                 metadataPrefix='rdf')
             self.assertIn(
                 '<rdf:Description rdf:about="{0}">'.format(alice.url), result)
@@ -417,11 +396,10 @@ class OAIPMHViewsTC(PyramidCWTest, OAITe
     def test_getrecord_agent(self):
         self._debug_xml = True
         with self.admin_access.repo_cnx() as cnx:
             agent = testutils.agent(cnx, u'toto')
             cnx.commit()
-            publish_entity(agent)
             ark = agent.ark
         with self.admin_access.web_request() as req:
             result = self.oai_request(req, verb='GetRecord',
                                       identifier='ark:/' + ark,
                                       metadataPrefix='rdf')
@@ -447,11 +425,10 @@ class OAIPMHViewsTC(PyramidCWTest, OAITe
     def test_getrecord_organizationunit(self):
         self._debug_xml = True
         with self.admin_access.repo_cnx() as cnx:
             orgu = testutils.organization_unit(cnx, u'toto')
             cnx.commit()
-            publish_entity(orgu)
             ark = orgu.ark
         with self.admin_access.web_request() as req:
             result = self.oai_request(req, verb='GetRecord',
                                       identifier='ark:/' + ark,
                                       metadataPrefix='rdf')
@@ -495,18 +472,9 @@ class OAIPMHViewsTC(PyramidCWTest, OAITe
                 req, verb='ListIdentifiers',
                 set='authorityrecord:used_by:{}'.format(ou_ark),
                 metadataPrefix='eac')
             self.assertIn('<identifier>ark:/' + ark, result)
 
-    def test_getrecord_draft(self):
-        self._setup_organization_units()
-        with self.admin_access.web_request() as req:
-            draft = req.execute('Any A WHERE X ark A, X name "draft"')[0][0]
-            result = self.oai_request(req, verb='GetRecord',
-                                      identifier='ark:/' + draft,
-                                      metadataPrefix='rdf')
-            self.assertIn('idDoesNotExist', result)
-
 
 if __name__ == '__main__':
     import unittest
     unittest.main()
diff --git a/test/unittest_schema.py b/test/unittest_schema.py
--- a/test/unittest_schema.py
+++ b/test/unittest_schema.py
@@ -46,13 +46,14 @@ class SchemaConstraintsTC(CubicWebTC):
             create one OU and check that interface will only show P that can become its
             contact point
         """
         with self.admin_access.repo_cnx() as cnx:
             peter = testutils.agent(cnx, u'Peter')
-            testutils.agent(cnx, u'Norton')
+            norton = testutils.agent(cnx, u'Norton')
             cnx.commit()
-            peter.cw_adapt_to('IWorkflowable').fire_transition('publish')
+            norton.cw_adapt_to('IWorkflowable').fire_transition('deprecate')
+            cnx.commit()
             ou = testutils.organization_unit(cnx, u'Alice')
             cnx.commit()
             rset = ou.unrelated('contact_point', 'Agent')
             self.assertEqual(rset.one().eid, peter.eid)
 
@@ -61,13 +62,13 @@ class SchemaConstraintsTC(CubicWebTC):
             create one Organization and check that interface will only show P that can become its
             archival agent
         """
         with self.admin_access.repo_cnx() as cnx:
             pou = testutils.organization_unit(cnx, u'P OU', archival_roles=['archival'])
-            testutils.organization_unit(cnx, u'N OU', archival_roles=['archival'])
+            nou = testutils.organization_unit(cnx, u'N OU', archival_roles=['archival'])
             cnx.commit()
-            pou.cw_adapt_to('IWorkflowable').fire_transition('publish')
+            nou.cw_adapt_to('IWorkflowable').fire_transition('deprecate')
             cnx.commit()
             # should be created by testutils.organization_unit() above.
             authority = cnx.find('Organization', name=u'Default authority').one()
             rset = authority.unrelated('archival_unit', 'OrganizationUnit')
             self.assertEqual(rset.one().eid, pou.eid)
@@ -148,18 +149,14 @@ class SchemaConstraintsTC(CubicWebTC):
         interface will only show consistent proposal for contact point
         """
         with self.admin_access.repo_cnx() as cnx:
             # Create an archival agent in a custom authority
             authority = testutils.authority_with_naa(cnx, name=u'boss club')
-            jdoe = testutils.agent(cnx, u'jdoe', authority=authority)
+            testutils.agent(cnx, u'jdoe', authority=authority)
             # Create another archival agent in the default authority
             norton = testutils.agent(cnx, u'Norton')
             cnx.commit()
-            # Publish both agents (because of the published constraint)
-            jdoe.cw_adapt_to('IWorkflowable').fire_transition('publish')
-            norton.cw_adapt_to('IWorkflowable').fire_transition('publish')
-            cnx.commit()
             # Now create an organisation unit and check the unrelated list
             ou = testutils.organization_unit(cnx, u'Alice')
             cnx.commit()
             rset = ou.unrelated('contact_point', 'Agent')
             self.assertEqual(rset.one().eid, norton.eid)
@@ -169,17 +166,13 @@ class SchemaConstraintsTC(CubicWebTC):
         of them as proposal for archival_agent of the default organization
         """
         with self.admin_access.repo_cnx() as cnx:
             # Create an organization unit in a custom authority
             authority = testutils.authority_with_naa(cnx, name=u'boss club')
-            jdoe = testutils.organization_unit(cnx, u'jdoe', archival_roles=['archival'])
+            testutils.organization_unit(cnx, u'jdoe', archival_roles=['archival'])
             # Create another archival organization unit in the default authority
-            norton = testutils.organization_unit(cnx, u'Norton', archival_roles=[u'archival'])
-            cnx.commit()
-            # Publish both organization units (because of the published constraint)
-            jdoe.cw_adapt_to('IWorkflowable').fire_transition('publish')
-            norton.cw_adapt_to('IWorkflowable').fire_transition('publish')
+            testutils.organization_unit(cnx, u'Norton', archival_roles=[u'archival'])
             cnx.commit()
             # Now check the unrelated list for authority's archival_unit
             authority = cnx.find('Organization', name=u'Default authority').one()
             rset = authority.unrelated('archival_unit', 'OrganizationUnit')
             self.assertEqual(len(rset), 2)


More information about the saem-devel mailing list