[PATCH 2 of 4 saem_ref] [schema] Add a unicity constraint on Agent(name, authority)

Sylvain Thénault sylvain.thenault at logilab.fr
Wed Apr 12 10:15:14 CEST 2017


seems like I have messed test name / content :$


Le 12/04/2017 à 09:54, Denis Laxalde a écrit :
> Sylvain Thenault a écrit :
>> # HG changeset patch
>> # User Sylvain Thénault <sylvain.thenault at logilab.fr>
>> # Date 1491978511 -7200
>> #      Wed Apr 12 08:28:31 2017 +0200
>> # Node ID e945a9931564701d19912a702fed5f9ccfe4a1a9
>> # Parent  bda3689076b1a6622c3b940b50b7e314440d39f8
>> [schema] Add a unicity constraint on Agent(name, authority)
>>
>> It seems to make sense and is consistent with OrganizationUnit.
>>
>> 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,7 +1,7 @@
>>  for ertype in ('generated', 'used', 'associated_with',
>> 'place_address', 'new_version_of',
>> -               'OrganizationUnit'):
>> +               'OrganizationUnit', 'Agent'):
>>      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
>> @@ -101,10 +101,11 @@ class OrganizationUnit(WorkflowableEntit
>>      name = String(required=True, fulltextindexed=True)
>>
>>
>>  @groups_permissions
>>  class Agent(WorkflowableEntityType):
>> +    __unique_together__ = [('name', 'authority')]
>>      name = String(required=True, fulltextindexed=True)
>>
>>
>>  class user_authority(RelationDefinition):
>>      __permissions__ = {
>> 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,23 @@ 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_agent_unicity(self):
>> +        with self.admin_access.cnx() as cnx:
>> +            testutils.organization_unit(cnx, u'arch',
>> archival_roles=[u'archival'])
>> +            cnx.commit()
>> +
>> +            with self.assertValidationError(cnx):
>> +                testutils.organization_unit(cnx, u'arch',
>> archival_roles=[u'archival'])
>> +
>> +            other_authority = testutils.authority_with_naa(cnx,
>> name=u'other authority')
>> +            testutils.organization_unit(cnx, u'arch',
>> archival_roles=[u'archival'],
>> +                                        authority=other_authority)
>> +            cnx.commit()
>> +
>
> organization_unit -> agent
>
>>      def test_organization_unit_unicity(self):
>>          with self.admin_access.cnx() as cnx:
>>              testutils.agent(cnx, u'bob')
>>              cnx.commit()
>>
>>
>

-- 
Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org



More information about the saem-devel mailing list