[schema] Make attributes of PostalAddress non-required
authorDenis Laxalde <denis.laxalde@logilab.fr>
Fri, 12 Jan 2018 11:50:43 +0100
changeset 237 70ff345d7b0c
parent 236 b0cb42f78923
child 238 0e28cc54aaa4
[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.
cubicweb_eac/migration/0.6.0_Any.py
cubicweb_eac/schema.py
test/test_schema.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb_eac/migration/0.6.0_Any.py	Fri Jan 12 11:50:43 2018 +0100
@@ -0,0 +1,1 @@
+sync_schema_props_perms('PostalAddress')
--- a/cubicweb_eac/schema.py	Tue Dec 19 17:09:12 2017 +0100
+++ b/cubicweb_eac/schema.py	Fri Jan 12 11:50:43 2018 +0100
@@ -22,9 +22,15 @@
 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.
--- a/test/test_schema.py	Tue Dec 19 17:09:12 2017 +0100
+++ b/test/test_schema.py	Fri Jan 12 11:50:43 2018 +0100
@@ -38,6 +38,18 @@
 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