[dataimport] extid must be a bytes object
authorJulien Cristau <julien.cristau@logilab.fr>
Fri, 16 Oct 2015 17:06:12 +0200
changeset 10809 359cbdf3a515
parent 10808 b6b2e1bcd1b2
child 10810 0768bf2333a7
[dataimport] extid must be a bytes object
dataimport/importer.py
dataimport/stores.py
dataimport/test/unittest_importer.py
--- a/dataimport/importer.py	Fri Oct 16 17:04:30 2015 +0200
+++ b/dataimport/importer.py	Fri Oct 16 17:06:12 2015 +0200
@@ -69,7 +69,7 @@
     def use_extid_as_cwuri_filter(extentities):
         for extentity in extentities:
             if extentity.extid not in extid2eid:
-                extentity.values.setdefault('cwuri', set([unicode(extentity.extid)]))
+                extentity.values.setdefault('cwuri', set([extentity.extid.decode('utf-8')]))
             yield extentity
     return use_extid_as_cwuri_filter
 
--- a/dataimport/stores.py	Fri Oct 16 17:04:30 2015 +0200
+++ b/dataimport/stores.py	Fri Oct 16 17:06:12 2015 +0200
@@ -61,6 +61,8 @@
 from datetime import datetime
 from copy import copy
 
+from six import text_type
+
 from logilab.common.deprecation import deprecated
 from logilab.common.decorators import cached
 
@@ -298,7 +300,7 @@
             genfunc = self.generate(attr)
             if genfunc:
                 entity.cw_edited.edited_attribute(attr, genfunc(entity))
-        if isinstance(extid, unicode):
+        if isinstance(extid, text_type):
             extid = extid.encode('utf-8')
         return self.source, extid
 
--- a/dataimport/test/unittest_importer.py	Fri Oct 16 17:04:30 2015 +0200
+++ b/dataimport/test/unittest_importer.py	Fri Oct 16 17:06:12 2015 +0200
@@ -152,14 +152,14 @@
 class UseExtidAsCwuriTC(TestCase):
 
     def test(self):
-        personne = ExtEntity('Personne', 1, {'nom': set([u'de la lune']),
-                                             'prenom': set([u'Jean'])})
+        personne = ExtEntity('Personne', b'1', {'nom': set([u'de la lune']),
+                                                'prenom': set([u'Jean'])})
         mapping = {}
         set_cwuri = use_extid_as_cwuri(mapping)
         list(set_cwuri((personne,)))
         self.assertIn('cwuri', personne.values)
-        self.assertEqual(personne.values['cwuri'], set(['1']))
-        mapping[1] = 'whatever'
+        self.assertEqual(personne.values['cwuri'], set([u'1']))
+        mapping[b'1'] = 'whatever'
         personne.values.pop('cwuri')
         list(set_cwuri((personne,)))
         self.assertNotIn('cwuri', personne.values)