[PATCH 1 of 4 saem_ref] [schema] Drop undesired unicity constraint on OrganizationUnit.name

Denis Laxalde denis.laxalde at logilab.fr
Wed Apr 12 09:53:39 CEST 2017


Sylvain Thenault a écrit :
> # HG changeset patch
> # User Sylvain Thénault <sylvain.thenault at logilab.fr>
> # Date 1491978452 -7200
> #      Wed Apr 12 08:27:32 2017 +0200
> # Node ID bda3689076b1a6622c3b940b50b7e314440d39f8
> # Parent  f67d92b022bbd43239efb823363253f0b7fb858c
> [schema] Drop undesired unicity constraint on OrganizationUnit.name
>
> name should be unique within an authority but not globally.
>
> diff --git a/cubicweb_saem_ref/migration/0.15.1_Any.py b/cubicweb_saem_ref/migration/0.15.1_Any.py
> --- a/cubicweb_saem_ref/migration/0.15.1_Any.py
> +++ b/cubicweb_saem_ref/migration/0.15.1_Any.py
> @@ -1,6 +1,7 @@
> -for ertype in ('generated', 'used', 'associated_with', 'place_address', 'new_version_of'):
> +for ertype in ('generated', 'used', 'associated_with', 'place_address', 'new_version_of',
> +               'OrganizationUnit'):
>      sync_schema_props_perms(ertype)
>
>
>  sql("DELETE FROM container_relation WHERE EXISTS("
>      "SELECT FROM entities WHERE eid_to=eid AND "
> diff --git a/cubicweb_saem_ref/schema.py b/cubicweb_saem_ref/schema.py
> --- a/cubicweb_saem_ref/schema.py
> +++ b/cubicweb_saem_ref/schema.py
> @@ -96,11 +96,11 @@ class OrganizationUnit(WorkflowableEntit
>          'add': ('managers', ),
>          'update': ('managers', ),
>          'delete': ('managers', ),
>      }
>      __unique_together__ = [('name', 'authority')]
> -    name = String(required=True, fulltextindexed=True, unique=True)
> +    name = String(required=True, fulltextindexed=True)
>
>
>  @groups_permissions
>  class Agent(WorkflowableEntityType):
>      name = String(required=True, fulltextindexed=True)
> diff --git a/test/unittest_schema.py b/test/unittest_schema.py
> --- a/test/unittest_schema.py
> +++ b/test/unittest_schema.py
> @@ -154,10 +154,22 @@ class SchemaConstraintsTC(CubicWebTC):
>              user.cw_set(authority=authority1)
>              # jdoe is in authority2, user in authority1 and attempt to link them KO
>              with self.assertValidationError(cnx):
>                  jdoe.cw_set(agent_user=user)
>
> +    def test_organization_unit_unicity(self):
> +        with self.admin_access.cnx() as cnx:
> +            testutils.agent(cnx, u'bob')
> +            cnx.commit()
> +
> +            with self.assertValidationError(cnx):
> +                testutils.agent(cnx, u'bob')
> +
> +            other_authority = testutils.authority_with_naa(cnx, name=u'other authority')
> +            testutils.agent(cnx, u'bob', authority=other_authority)
> +            cnx.commit()
> +

testutils.agent()? Should be testutils.organizationunit() I guess?



More information about the saem-devel mailing list