[datafeed] closes #1875322: empty tag means None value stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 26 Jul 2011 16:50:02 +0200
branchstable
changeset 7700 0010dde5352a
parent 7699 d07cde311630
child 7701 e5ba5de1d485
[datafeed] closes #1875322: empty tag means None value
sobjects/parsers.py
sobjects/test/unittest_parsers.py
--- a/sobjects/parsers.py	Tue Jul 26 16:49:10 2011 +0200
+++ b/sobjects/parsers.py	Tue Jul 26 16:50:02 2011 +0200
@@ -75,7 +75,10 @@
             if rschema == 'eid':
                 continue
             attrtype = eschema.destination(rschema)
-            typeddict[rschema.type] = converters[attrtype](stringdict[rschema])
+            value = stringdict[rschema]
+            if value is not None:
+                value = converters[attrtype](value)
+            typeddict[rschema.type] = value
     return typeddict
 
 def rtype_role_rql(rtype, role):
@@ -294,9 +297,12 @@
                 # relation
                 related = rels.setdefault(role, {}).setdefault(child.tag, [])
                 related += [ritem for ritem, _ in self.parser.parse_etree(child)]
-            else:
+            elif child.text:
                 # attribute
                 item[child.tag] = unicode(child.text)
+            else:
+                # None attribute (empty tag)
+                item[child.tag] = None
         return item, rels
 
 
--- a/sobjects/test/unittest_parsers.py	Tue Jul 26 16:49:10 2011 +0200
+++ b/sobjects/test/unittest_parsers.py	Tue Jul 26 16:50:02 2011 +0200
@@ -261,7 +261,7 @@
         self.assertEqual(user.cwuri, 'http://pouet.org/5')
         self.assertEqual(user.cw_source[0].name, 'myfeed')
 
-    def test_missing_fti_attribute(self):
+    def test_noerror_missing_fti_attribute(self):
         dfsource = self.repo.sources_by_uri['myfeed']
         session = self.repo.internal_session()
         parser = dfsource._get_parser(session)
@@ -273,6 +273,21 @@
 </rset>
 '''], raise_on_error=True)
 
+    def test_noerror_unspecified_date(self):
+        dfsource = self.repo.sources_by_uri['myfeed']
+        session = self.repo.internal_session()
+        parser = dfsource._get_parser(session)
+        dfsource.process_urls(parser, ['''
+<rset size="1">
+ <Card eid="50" cwuri="http://pouet.org/50" cwsource="system">
+  <title>how-to</title>
+  <content>how-to</content>
+  <synopsis>how-to</synopsis>
+  <creation_date/>
+ </Card>
+</rset>
+'''], raise_on_error=True)
+
 if __name__ == '__main__':
     from logilab.common.testlib import unittest_main
     unittest_main()