cubicweb/dataimport/test/unittest_importer.py
author Jérémy Bobbio <jeremy.bobbio@irq7.fr>
Wed, 19 Jun 2019 15:44:17 +0200
changeset 12655 5b0ce10a7046
parent 12625 ba5231e1aa45
permissions -rw-r--r--
[crypto] Use Cryptodome namespace instead of Crypto PyCryptodome comes in two flavors: “an almost drop-in replacement for the old PyCrypto library” and “a library independent of the old PyCrypto”. The former uses the Crypto namespace, and is shipped as `pycryptodome` while the latter uses Cryptodome instead and lies in the `pycryptodomex` package. Given the reason to switch to PyCryptodome is that PyCrypto in unmaintained, its probably better to avoid any mistake and mandate the specific usage of the Cryptodome namespace by requiring `pycryptodomex` instead of `pycryptodome`. A more present reason is that Debian buster will only provide a package with the separate namespace flavor. The current Recommends is not working with the current code. Although it's important to note that the package name will probably have to be changed to `python3-pycryptodomex` once https://bugs.debian.org/886291 is solved.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10460
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
11139
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
     2
# copyright 2015-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
10460
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
     3
# contact http://www.logilab.fr -- mailto:contact@logilab.fr
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
     4
#
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
     5
# This program is free software: you can redistribute it and/or modify it under
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
     6
# the terms of the GNU Lesser General Public License as published by the Free
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
     7
# Software Foundation, either version 2.1 of the License, or (at your option)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
     8
# any later version.
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
     9
#
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    10
# This program is distributed in the hope that it will be useful, but WITHOUT
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    12
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    13
# details.
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    14
#
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    15
# You should have received a copy of the GNU Lesser General Public License along
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    16
# with this program. If not, see <http://www.gnu.org/licenses/>.
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    17
"""Tests for cubicweb.dataimport.importer"""
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    18
10514
b29d9904482e add use_extid_as_cwuri ext entity transform, that will be often necessary and not so easy to write at once
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10460
diff changeset
    19
from logilab.common.testlib import TestCase, unittest_main
10460
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    20
11393
e148b384a782 [dataimport] Restore handling of Binary in ExtEntity's values
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11342
diff changeset
    21
from cubicweb import Binary, ValidationError
10460
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    22
from cubicweb.devtools.testlib import CubicWebTC
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    23
from cubicweb.dataimport import RQLObjectStore, ucsvreader
11139
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
    24
from cubicweb.dataimport.importer import (ExtEntity, ExtEntitiesImporter, RelationMapping,
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
    25
                                          SimpleImportLog, use_extid_as_cwuri, drop_extra_values)
10460
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    26
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    27
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    28
class RelationMappingTC(CubicWebTC):
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    29
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    30
    def test_nosource(self):
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    31
        with self.admin_access.repo_cnx() as cnx:
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    32
            alice_eid = cnx.create_entity('Personne', nom=u'alice').eid
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    33
            bob_eid = cnx.create_entity('Personne', nom=u'bob', connait=alice_eid).eid
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    34
            cnx.commit()
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    35
            mapping = RelationMapping(cnx)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    36
            self.assertEqual(mapping['connait'],
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    37
                             set([(bob_eid, alice_eid), (alice_eid, bob_eid)]))
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    38
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    39
    def test_with_source(self):
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    40
        with self.admin_access.repo_cnx() as cnx:
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    41
            alice_eid = cnx.create_entity('Personne', nom=u'alice').eid
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    42
            bob_eid = cnx.create_entity('Personne', nom=u'bob', connait=alice_eid).eid
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    43
            cnx.commit()
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    44
            mapping = RelationMapping(cnx, cnx.find('CWSource', name=u'system').one())
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    45
            self.assertEqual(mapping['connait'],
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    46
                             set([(bob_eid, alice_eid), (alice_eid, bob_eid)]))
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    47
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    48
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    49
class ExtEntitiesImporterTC(CubicWebTC):
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    50
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    51
    def importer(self, cnx):
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    52
        store = RQLObjectStore(cnx)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    53
        return ExtEntitiesImporter(self.schema, store, raise_on_error=True)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    54
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    55
    def test_simple_import(self):
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    56
        with self.admin_access.repo_cnx() as cnx:
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    57
            importer = self.importer(cnx)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    58
            personne = ExtEntity('Personne', 1, {'nom': set([u'de la lune']),
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    59
                                                 'prenom': set([u'Jean'])})
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    60
            importer.import_entities([personne])
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    61
            cnx.commit()
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    62
            rset = cnx.execute('Any X WHERE X is Personne')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    63
            entity = rset.get_entity(0, 0)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    64
            self.assertEqual(entity.nom, u'de la lune')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    65
            self.assertEqual(entity.prenom, u'Jean')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    66
11342
62a7100d774b [dataimport] Handle Bytes data in ExtEntity and convert them to Binary
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11279
diff changeset
    67
    def test_bytes_attribute(self):
62a7100d774b [dataimport] Handle Bytes data in ExtEntity and convert them to Binary
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11279
diff changeset
    68
        with self.admin_access.repo_cnx() as cnx:
62a7100d774b [dataimport] Handle Bytes data in ExtEntity and convert them to Binary
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11279
diff changeset
    69
            importer = self.importer(cnx)
62a7100d774b [dataimport] Handle Bytes data in ExtEntity and convert them to Binary
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11279
diff changeset
    70
            personne = ExtEntity('Personne', 1, {'photo': set([b'poilu']),
62a7100d774b [dataimport] Handle Bytes data in ExtEntity and convert them to Binary
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11279
diff changeset
    71
                                                 'nom': set([u'alf'])})
62a7100d774b [dataimport] Handle Bytes data in ExtEntity and convert them to Binary
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11279
diff changeset
    72
            importer.import_entities([personne])
62a7100d774b [dataimport] Handle Bytes data in ExtEntity and convert them to Binary
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11279
diff changeset
    73
            cnx.commit()
62a7100d774b [dataimport] Handle Bytes data in ExtEntity and convert them to Binary
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11279
diff changeset
    74
            entity = cnx.find('Personne').one()
62a7100d774b [dataimport] Handle Bytes data in ExtEntity and convert them to Binary
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11279
diff changeset
    75
            self.assertEqual(entity.photo.getvalue(), b'poilu')
62a7100d774b [dataimport] Handle Bytes data in ExtEntity and convert them to Binary
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11279
diff changeset
    76
11393
e148b384a782 [dataimport] Restore handling of Binary in ExtEntity's values
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11342
diff changeset
    77
    def test_binary_in_values(self):
e148b384a782 [dataimport] Restore handling of Binary in ExtEntity's values
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11342
diff changeset
    78
        with self.admin_access.repo_cnx() as cnx:
e148b384a782 [dataimport] Restore handling of Binary in ExtEntity's values
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11342
diff changeset
    79
            importer = self.importer(cnx)
e148b384a782 [dataimport] Restore handling of Binary in ExtEntity's values
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11342
diff changeset
    80
            # Use a list to put a Binary in "values" (since Binary is not
e148b384a782 [dataimport] Restore handling of Binary in ExtEntity's values
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11342
diff changeset
    81
            # hashable, a set cannot be used).
e148b384a782 [dataimport] Restore handling of Binary in ExtEntity's values
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11342
diff changeset
    82
            personne = ExtEntity('Personne', 1, {'photo': [Binary(b'poilu')],
e148b384a782 [dataimport] Restore handling of Binary in ExtEntity's values
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11342
diff changeset
    83
                                                 'nom': set([u'alf'])})
e148b384a782 [dataimport] Restore handling of Binary in ExtEntity's values
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11342
diff changeset
    84
            importer.import_entities([personne])
e148b384a782 [dataimport] Restore handling of Binary in ExtEntity's values
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11342
diff changeset
    85
            cnx.commit()
e148b384a782 [dataimport] Restore handling of Binary in ExtEntity's values
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11342
diff changeset
    86
            entity = cnx.find('Personne').one()
e148b384a782 [dataimport] Restore handling of Binary in ExtEntity's values
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11342
diff changeset
    87
            self.assertEqual(entity.photo.getvalue(), b'poilu')
e148b384a782 [dataimport] Restore handling of Binary in ExtEntity's values
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11342
diff changeset
    88
10460
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    89
    def test_import_missing_required_attribute(self):
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    90
        """Check import of ext entity with missing required attribute"""
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    91
        with self.admin_access.repo_cnx() as cnx:
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    92
            importer = self.importer(cnx)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    93
            tag = ExtEntity('Personne', 2, {'prenom': set([u'Jean'])})
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    94
            self.assertRaises(ValidationError, importer.import_entities, [tag])
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    95
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    96
    def test_import_inlined_relation(self):
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    97
        """Check import of ext entities with inlined relation"""
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    98
        with self.admin_access.repo_cnx() as cnx:
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
    99
            importer = self.importer(cnx)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   100
            richelieu = ExtEntity('Personne', 3, {'nom': set([u'Richelieu']),
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   101
                                                  'enfant': set([4])})
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   102
            athos = ExtEntity('Personne', 4, {'nom': set([u'Athos'])})
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   103
            importer.import_entities([athos, richelieu])
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   104
            cnx.commit()
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   105
            rset = cnx.execute('Any X WHERE X is Personne, X nom "Richelieu"')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   106
            entity = rset.get_entity(0, 0)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   107
            self.assertEqual(entity.enfant[0].nom, 'Athos')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   108
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   109
    def test_import_non_inlined_relation(self):
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   110
        """Check import of ext entities with non inlined relation"""
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   111
        with self.admin_access.repo_cnx() as cnx:
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   112
            importer = self.importer(cnx)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   113
            richelieu = ExtEntity('Personne', 5, {'nom': set([u'Richelieu']),
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   114
                                                  'connait': set([6])})
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   115
            athos = ExtEntity('Personne', 6, {'nom': set([u'Athos'])})
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   116
            importer.import_entities([athos, richelieu])
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   117
            cnx.commit()
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   118
            rset = cnx.execute('Any X WHERE X is Personne, X nom "Richelieu"')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   119
            entity = rset.get_entity(0, 0)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   120
            self.assertEqual(entity.connait[0].nom, 'Athos')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   121
            rset = cnx.execute('Any X WHERE X is Personne, X nom "Athos"')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   122
            entity = rset.get_entity(0, 0)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   123
            self.assertEqual(entity.connait[0].nom, 'Richelieu')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   124
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   125
    def test_import_missing_inlined_relation(self):
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   126
        """Check import of ext entity with missing inlined relation"""
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   127
        with self.admin_access.repo_cnx() as cnx:
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   128
            importer = self.importer(cnx)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   129
            richelieu = ExtEntity('Personne', 7,
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   130
                                  {'nom': set([u'Richelieu']), 'enfant': set([8])})
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   131
            self.assertRaises(Exception, importer.import_entities, [richelieu])
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   132
            cnx.commit()
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   133
            rset = cnx.execute('Any X WHERE X is Personne, X nom "Richelieu"')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   134
            self.assertEqual(len(rset), 0)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   135
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   136
    def test_import_missing_non_inlined_relation(self):
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   137
        """Check import of ext entity with missing non-inlined relation"""
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   138
        with self.admin_access.repo_cnx() as cnx:
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   139
            importer = self.importer(cnx)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   140
            richelieu = ExtEntity('Personne', 9,
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   141
                                  {'nom': set([u'Richelieu']), 'connait': set([10])})
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   142
            self.assertRaises(Exception, importer.import_entities, [richelieu])
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   143
            cnx.commit()
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   144
            rset = cnx.execute('Any X WHERE X is Personne, X nom "Richelieu"')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   145
            entity = rset.get_entity(0, 0)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   146
            self.assertEqual(entity.nom, u'Richelieu')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   147
            self.assertEqual(len(entity.connait), 0)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   148
11275
814f54d6183b [dataimport] order of ExtEntities should be irrelevant (closes #13117472)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 11110
diff changeset
   149
    def test_import_order(self):
814f54d6183b [dataimport] order of ExtEntities should be irrelevant (closes #13117472)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 11110
diff changeset
   150
        """Check import of ext entity in both order"""
814f54d6183b [dataimport] order of ExtEntities should be irrelevant (closes #13117472)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 11110
diff changeset
   151
        with self.admin_access.repo_cnx() as cnx:
814f54d6183b [dataimport] order of ExtEntities should be irrelevant (closes #13117472)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 11110
diff changeset
   152
            importer = self.importer(cnx)
814f54d6183b [dataimport] order of ExtEntities should be irrelevant (closes #13117472)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 11110
diff changeset
   153
            richelieu = ExtEntity('Personne', 3, {'nom': set([u'Richelieu']),
814f54d6183b [dataimport] order of ExtEntities should be irrelevant (closes #13117472)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 11110
diff changeset
   154
                                                  'enfant': set([4])})
814f54d6183b [dataimport] order of ExtEntities should be irrelevant (closes #13117472)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 11110
diff changeset
   155
            athos = ExtEntity('Personne', 4, {'nom': set([u'Athos'])})
814f54d6183b [dataimport] order of ExtEntities should be irrelevant (closes #13117472)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 11110
diff changeset
   156
            importer.import_entities([richelieu, athos])
814f54d6183b [dataimport] order of ExtEntities should be irrelevant (closes #13117472)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 11110
diff changeset
   157
            cnx.commit()
814f54d6183b [dataimport] order of ExtEntities should be irrelevant (closes #13117472)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 11110
diff changeset
   158
            rset = cnx.execute('Any X WHERE X is Personne, X nom "Richelieu"')
814f54d6183b [dataimport] order of ExtEntities should be irrelevant (closes #13117472)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 11110
diff changeset
   159
            entity = rset.get_entity(0, 0)
814f54d6183b [dataimport] order of ExtEntities should be irrelevant (closes #13117472)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 11110
diff changeset
   160
            self.assertEqual(entity.enfant[0].nom, 'Athos')
814f54d6183b [dataimport] order of ExtEntities should be irrelevant (closes #13117472)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 11110
diff changeset
   161
10460
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   162
    def test_update(self):
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   163
        """Check update of ext entity"""
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   164
        with self.admin_access.repo_cnx() as cnx:
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   165
            importer = self.importer(cnx)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   166
            # First import
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   167
            richelieu = ExtEntity('Personne', 11,
11110
68477666401f [dataimport/test] fix python2.6 syntax error
Julien Cristau <julien.cristau@logilab.fr>
parents: 10809
diff changeset
   168
                                  {'nom': set([u'Richelieu Diacre'])})
10460
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   169
            importer.import_entities([richelieu])
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   170
            cnx.commit()
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   171
            rset = cnx.execute('Any X WHERE X is Personne')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   172
            entity = rset.get_entity(0, 0)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   173
            self.assertEqual(entity.nom, u'Richelieu Diacre')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   174
            # Second import
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   175
            richelieu = ExtEntity('Personne', 11,
11110
68477666401f [dataimport/test] fix python2.6 syntax error
Julien Cristau <julien.cristau@logilab.fr>
parents: 10809
diff changeset
   176
                                  {'nom': set([u'Richelieu Cardinal'])})
10460
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   177
            importer.import_entities([richelieu])
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   178
            cnx.commit()
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   179
            rset = cnx.execute('Any X WHERE X is Personne')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   180
            self.assertEqual(len(rset), 1)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   181
            entity = rset.get_entity(0, 0)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   182
            self.assertEqual(entity.nom, u'Richelieu Cardinal')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   183
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   184
10514
b29d9904482e add use_extid_as_cwuri ext entity transform, that will be often necessary and not so easy to write at once
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10460
diff changeset
   185
class UseExtidAsCwuriTC(TestCase):
b29d9904482e add use_extid_as_cwuri ext entity transform, that will be often necessary and not so easy to write at once
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10460
diff changeset
   186
b29d9904482e add use_extid_as_cwuri ext entity transform, that will be often necessary and not so easy to write at once
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10460
diff changeset
   187
    def test(self):
10809
359cbdf3a515 [dataimport] extid must be a bytes object
Julien Cristau <julien.cristau@logilab.fr>
parents: 10807
diff changeset
   188
        personne = ExtEntity('Personne', b'1', {'nom': set([u'de la lune']),
359cbdf3a515 [dataimport] extid must be a bytes object
Julien Cristau <julien.cristau@logilab.fr>
parents: 10807
diff changeset
   189
                                                'prenom': set([u'Jean'])})
10514
b29d9904482e add use_extid_as_cwuri ext entity transform, that will be often necessary and not so easy to write at once
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10460
diff changeset
   190
        mapping = {}
b29d9904482e add use_extid_as_cwuri ext entity transform, that will be often necessary and not so easy to write at once
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10460
diff changeset
   191
        set_cwuri = use_extid_as_cwuri(mapping)
b29d9904482e add use_extid_as_cwuri ext entity transform, that will be often necessary and not so easy to write at once
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10460
diff changeset
   192
        list(set_cwuri((personne,)))
b29d9904482e add use_extid_as_cwuri ext entity transform, that will be often necessary and not so easy to write at once
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10460
diff changeset
   193
        self.assertIn('cwuri', personne.values)
10809
359cbdf3a515 [dataimport] extid must be a bytes object
Julien Cristau <julien.cristau@logilab.fr>
parents: 10807
diff changeset
   194
        self.assertEqual(personne.values['cwuri'], set([u'1']))
359cbdf3a515 [dataimport] extid must be a bytes object
Julien Cristau <julien.cristau@logilab.fr>
parents: 10807
diff changeset
   195
        mapping[b'1'] = 'whatever'
10514
b29d9904482e add use_extid_as_cwuri ext entity transform, that will be often necessary and not so easy to write at once
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10460
diff changeset
   196
        personne.values.pop('cwuri')
b29d9904482e add use_extid_as_cwuri ext entity transform, that will be often necessary and not so easy to write at once
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10460
diff changeset
   197
        list(set_cwuri((personne,)))
b29d9904482e add use_extid_as_cwuri ext entity transform, that will be often necessary and not so easy to write at once
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10460
diff changeset
   198
        self.assertNotIn('cwuri', personne.values)
12625
ba5231e1aa45 [dataimport] Fix case when extid is text in use_extid_as_cwuri()
julien tayon <julien.tayon@logilab.fr>
parents: 11393
diff changeset
   199
        personne = ExtEntity('Personne', u'ééé', {})
ba5231e1aa45 [dataimport] Fix case when extid is text in use_extid_as_cwuri()
julien tayon <julien.tayon@logilab.fr>
parents: 11393
diff changeset
   200
        mapping = {}
ba5231e1aa45 [dataimport] Fix case when extid is text in use_extid_as_cwuri()
julien tayon <julien.tayon@logilab.fr>
parents: 11393
diff changeset
   201
        set_cwuri = use_extid_as_cwuri(mapping)
ba5231e1aa45 [dataimport] Fix case when extid is text in use_extid_as_cwuri()
julien tayon <julien.tayon@logilab.fr>
parents: 11393
diff changeset
   202
        list(set_cwuri((personne,)))
ba5231e1aa45 [dataimport] Fix case when extid is text in use_extid_as_cwuri()
julien tayon <julien.tayon@logilab.fr>
parents: 11393
diff changeset
   203
        self.assertIn('cwuri', personne.values)
ba5231e1aa45 [dataimport] Fix case when extid is text in use_extid_as_cwuri()
julien tayon <julien.tayon@logilab.fr>
parents: 11393
diff changeset
   204
        self.assertEqual(personne.values['cwuri'], set([u'ééé']))
10514
b29d9904482e add use_extid_as_cwuri ext entity transform, that will be often necessary and not so easy to write at once
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10460
diff changeset
   205
b29d9904482e add use_extid_as_cwuri ext entity transform, that will be often necessary and not so easy to write at once
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10460
diff changeset
   206
11139
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
   207
class DropExtraValuesTC(CubicWebTC):
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
   208
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
   209
    def test(self):
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
   210
        personne = ExtEntity('Personne', b'1', {'nom': set([u'de la lune', 'di la luna']),
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
   211
                                                'prenom': set([u'Jean']),
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
   212
                                                'enfant': set('23'),
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
   213
                                                'connait': set('45')})
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
   214
        log = SimpleImportLog('<unspecified>')
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
   215
        list(drop_extra_values((personne,), self.schema, log))
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
   216
        self.assertEqual(len(personne.values['nom']), 1)
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
   217
        self.assertEqual(len(personne.values['enfant']), 1)
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
   218
        self.assertEqual(len(personne.values['connait']), 2)
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
   219
        self.assertEqual(len(log.logs), 2)
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
   220
df928a3a94e3 [dataimport] add a filter function to not fail if some extentity has several values for an attribute of final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
   221
10460
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   222
def extentities_from_csv(fpath):
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   223
    """Yield ExtEntity read from `fpath` CSV file."""
10807
bb0c7dbd1fe7 [dataimport] fix ucsvreader for python3
Julien Cristau <julien.cristau@logilab.fr>
parents: 10514
diff changeset
   224
    with open(fpath, 'rb') as f:
10460
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   225
        for uri, name, knows in ucsvreader(f, skipfirst=True, skip_empty=False):
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   226
            yield ExtEntity('Personne', uri,
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   227
                            {'nom': set([name]), 'connait': set([knows])})
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   228
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   229
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   230
class DataimportFunctionalTC(CubicWebTC):
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   231
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   232
    def test_csv(self):
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   233
        extenties = extentities_from_csv(self.datapath('people.csv'))
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   234
        with self.admin_access.repo_cnx() as cnx:
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   235
            store = RQLObjectStore(cnx)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   236
            importer = ExtEntitiesImporter(self.schema, store)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   237
            importer.import_entities(extenties)
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   238
            cnx.commit()
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   239
            rset = cnx.execute('String N WHERE X nom N, X connait Y, Y nom "Alice"')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   240
            self.assertEqual(rset[0][0], u'Bob')
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   241
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   242
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   243
if __name__ == '__main__':
d260722f2453 [dataimport] introduce the importer and extentity classes
Yann Voté <yann.vote@logilab.fr>
parents:
diff changeset
   244
    unittest_main()