[PATCH eac] [schema] Make attributes of PostalAddress non-required

Denis Laxalde denis.laxalde at logilab.fr
Fri Jan 12 11:57:45 CET 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1515754243 -3600
#      Fri Jan 12 11:50:43 2018 +0100
# Node ID 70ff345d7b0c4fbd86302b2cf098ed2f07d30edd
# Parent  b0cb42f7892355a0042a32bbac04849bf465befe
[schema] Make attributes of PostalAddress non-required

This is needed so as to be able to import EAC-CPF data without such data
present, which is perfectly allowed by this specification.

Closes extranet #44640239.

diff --git a/cubicweb_eac/migration/0.6.0_Any.py b/cubicweb_eac/migration/0.6.0_Any.py
new file mode 100644
--- /dev/null
+++ b/cubicweb_eac/migration/0.6.0_Any.py
@@ -0,0 +1,1 @@
+sync_schema_props_perms('PostalAddress')
diff --git a/cubicweb_eac/schema.py b/cubicweb_eac/schema.py
--- a/cubicweb_eac/schema.py
+++ b/cubicweb_eac/schema.py
@@ -22,9 +22,15 @@ from yams.constraints import BoundaryCon
 from cubicweb import _
 from cubicweb.schema import RRQLExpression, RQLVocabularyConstraint
 
+from cubes.addressbook import schema as addressbook
 from cubicweb_prov.schema import Activity
 
 
+# Customization of addressbook schema.
+for attrname in ('street', 'city', 'postalcode'):
+    addressbook.PostalAddress.get_relation(attrname).cardinality = '?1'
+
+
 def dated_entity_type(cls):
     """Class decorator adding `start_date` and `end_date` attribute to an
     EntityType.
diff --git a/test/test_schema.py b/test/test_schema.py
--- a/test/test_schema.py
+++ b/test/test_schema.py
@@ -38,6 +38,18 @@ def assertValidationError(self, cnx):
 class SchemaConstraintsTC(CubicWebTC):
     assertValidationError = assertValidationError
 
+    def test_postaladdress_no_required(self):
+        """Make sure a PostalAddress can be "empty" (useful in data import
+        context).
+        """
+        with self.admin_access.cnx() as cnx:
+            ar = testutils.authority_record(cnx, u'test')
+            cnx.create_entity('AgentPlace',
+                              place_agent=ar,
+                              place_address=cnx.create_entity('PostalAddress'))
+            cnx.commit()
+            # No assert, just make sure db integrity checks pass.
+
     def test_on_create_set_end_date_before_start_date(self):
         """ create an entity whose end_date is before start_date.
         ValidationError expected


More information about the saem-devel mailing list