Beispiel #1
0
 def test_import_order(self):
     """Check import of ext entity in both order"""
     with self.admin_access.repo_cnx() as cnx:
         importer = self.importer(cnx)
         richelieu = ExtEntity('Personne', 3, {
             'nom': set([u'Richelieu']),
             'enfant': set([4])
         })
         athos = ExtEntity('Personne', 4, {'nom': set([u'Athos'])})
         importer.import_entities([richelieu, athos])
         cnx.commit()
         rset = cnx.execute('Any X WHERE X is Personne, X nom "Richelieu"')
         entity = rset.get_entity(0, 0)
         self.assertEqual(entity.enfant[0].nom, 'Athos')
Beispiel #2
0
 def test_import_non_inlined_relation(self):
     """Check import of ext entities with non inlined relation"""
     with self.admin_access.repo_cnx() as cnx:
         importer = self.importer(cnx)
         richelieu = ExtEntity('Personne', 5, {
             'nom': set([u'Richelieu']),
             'connait': set([6])
         })
         athos = ExtEntity('Personne', 6, {'nom': set([u'Athos'])})
         importer.import_entities([athos, richelieu])
         cnx.commit()
         rset = cnx.execute('Any X WHERE X is Personne, X nom "Richelieu"')
         entity = rset.get_entity(0, 0)
         self.assertEqual(entity.connait[0].nom, 'Athos')
         rset = cnx.execute('Any X WHERE X is Personne, X nom "Athos"')
         entity = rset.get_entity(0, 0)
         self.assertEqual(entity.connait[0].nom, 'Richelieu')
Beispiel #3
0
def extentities_from_csv(fpath):
    """Yield ExtEntity read from `fpath` CSV file."""
    with open(fpath, 'rb') as f:
        for uri, name, knows in ucsvreader(f, skipfirst=True,
                                           skip_empty=False):
            yield ExtEntity('Personne', uri, {
                'nom': set([name]),
                'connait': set([knows])
            })
Beispiel #4
0
 def test_bytes_attribute(self):
     with self.admin_access.repo_cnx() as cnx:
         importer = self.importer(cnx)
         personne = ExtEntity('Personne', 1, {
             'photo': set([b'poilu']),
             'nom': set([u'alf'])
         })
         importer.import_entities([personne])
         cnx.commit()
         entity = cnx.find('Personne').one()
         self.assertEqual(entity.photo.getvalue(), b'poilu')
Beispiel #5
0
 def test(self):
     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([u'1']))
     mapping[b'1'] = 'whatever'
     personne.values.pop('cwuri')
     list(set_cwuri((personne, )))
     self.assertNotIn('cwuri', personne.values)
     personne = ExtEntity('Personne', u'ééé', {})
     mapping = {}
     set_cwuri = use_extid_as_cwuri(mapping)
     list(set_cwuri((personne, )))
     self.assertIn('cwuri', personne.values)
     self.assertEqual(personne.values['cwuri'], set([u'ééé']))
Beispiel #6
0
 def test_update(self):
     """Check update of ext entity"""
     with self.admin_access.repo_cnx() as cnx:
         importer = self.importer(cnx)
         # First import
         richelieu = ExtEntity('Personne', 11,
                               {'nom': set([u'Richelieu Diacre'])})
         importer.import_entities([richelieu])
         cnx.commit()
         rset = cnx.execute('Any X WHERE X is Personne')
         entity = rset.get_entity(0, 0)
         self.assertEqual(entity.nom, u'Richelieu Diacre')
         # Second import
         richelieu = ExtEntity('Personne', 11,
                               {'nom': set([u'Richelieu Cardinal'])})
         importer.import_entities([richelieu])
         cnx.commit()
         rset = cnx.execute('Any X WHERE X is Personne')
         self.assertEqual(len(rset), 1)
         entity = rset.get_entity(0, 0)
         self.assertEqual(entity.nom, u'Richelieu Cardinal')
Beispiel #7
0
 def test_import_missing_inlined_relation(self):
     """Check import of ext entity with missing inlined relation"""
     with self.admin_access.repo_cnx() as cnx:
         importer = self.importer(cnx)
         richelieu = ExtEntity('Personne', 7, {
             'nom': set([u'Richelieu']),
             'enfant': set([8])
         })
         self.assertRaises(Exception, importer.import_entities, [richelieu])
         cnx.commit()
         rset = cnx.execute('Any X WHERE X is Personne, X nom "Richelieu"')
         self.assertEqual(len(rset), 0)
Beispiel #8
0
 def test_binary_in_values(self):
     with self.admin_access.repo_cnx() as cnx:
         importer = self.importer(cnx)
         # Use a list to put a Binary in "values" (since Binary is not
         # hashable, a set cannot be used).
         personne = ExtEntity('Personne', 1, {
             'photo': [Binary(b'poilu')],
             'nom': set([u'alf'])
         })
         importer.import_entities([personne])
         cnx.commit()
         entity = cnx.find('Personne').one()
         self.assertEqual(entity.photo.getvalue(), b'poilu')
Beispiel #9
0
 def test_simple_import(self):
     with self.admin_access.repo_cnx() as cnx:
         importer = self.importer(cnx)
         personne = ExtEntity('Personne', 1, {
             'nom': set([u'de la lune']),
             'prenom': set([u'Jean'])
         })
         importer.import_entities([personne])
         cnx.commit()
         rset = cnx.execute('Any X WHERE X is Personne')
         entity = rset.get_entity(0, 0)
         self.assertEqual(entity.nom, u'de la lune')
         self.assertEqual(entity.prenom, u'Jean')
Beispiel #10
0
 def test(self):
     personne = ExtEntity(
         'Personne', b'1', {
             'nom': set([u'de la lune', 'di la luna']),
             'prenom': set([u'Jean']),
             'enfant': set('23'),
             'connait': set('45')
         })
     log = SimpleImportLog('<unspecified>')
     list(drop_extra_values((personne, ), self.schema, log))
     self.assertEqual(len(personne.values['nom']), 1)
     self.assertEqual(len(personne.values['enfant']), 1)
     self.assertEqual(len(personne.values['connait']), 2)
     self.assertEqual(len(log.logs), 2)
Beispiel #11
0
 def test_import_missing_non_inlined_relation(self):
     """Check import of ext entity with missing non-inlined relation"""
     with self.admin_access.repo_cnx() as cnx:
         importer = self.importer(cnx)
         richelieu = ExtEntity('Personne', 9, {
             'nom': set([u'Richelieu']),
             'connait': set([10])
         })
         self.assertRaises(Exception, importer.import_entities, [richelieu])
         cnx.commit()
         rset = cnx.execute('Any X WHERE X is Personne, X nom "Richelieu"')
         entity = rset.get_entity(0, 0)
         self.assertEqual(entity.nom, u'Richelieu')
         self.assertEqual(len(entity.connait), 0)
Beispiel #12
0
 def test_import_missing_required_attribute(self):
     """Check import of ext entity with missing required attribute"""
     with self.admin_access.repo_cnx() as cnx:
         importer = self.importer(cnx)
         tag = ExtEntity('Personne', 2, {'prenom': set([u'Jean'])})
         self.assertRaises(ValidationError, importer.import_entities, [tag])