[doc] remove mentions of pyro and reposity instance type
from the concepts chapter
Related to #4832808
# -*- coding: utf-8 -*-# copyright 2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.# contact http://www.logilab.fr -- mailto:contact@logilab.fr## This program is free software: you can redistribute it and/or modify it under# the terms of the GNU Lesser General Public License as published by the Free# Software Foundation, either version 2.1 of the License, or (at your option)# any later version.## This program is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more# details.## You should have received a copy of the GNU Lesser General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>."""Tests for cubicweb.dataimport.importer"""fromcollectionsimportdefaultdictfromlogilab.common.testlibimportunittest_mainfromcubicwebimportValidationErrorfromcubicweb.devtools.testlibimportCubicWebTCfromcubicweb.dataimportimportRQLObjectStore,ucsvreaderfromcubicweb.dataimport.importerimportExtEntity,ExtEntitiesImporter,SimpleImportLog,RelationMappingclassRelationMappingTC(CubicWebTC):deftest_nosource(self):withself.admin_access.repo_cnx()ascnx:alice_eid=cnx.create_entity('Personne',nom=u'alice').eidbob_eid=cnx.create_entity('Personne',nom=u'bob',connait=alice_eid).eidcnx.commit()mapping=RelationMapping(cnx)self.assertEqual(mapping['connait'],set([(bob_eid,alice_eid),(alice_eid,bob_eid)]))deftest_with_source(self):withself.admin_access.repo_cnx()ascnx:alice_eid=cnx.create_entity('Personne',nom=u'alice').eidbob_eid=cnx.create_entity('Personne',nom=u'bob',connait=alice_eid).eidcnx.commit()mapping=RelationMapping(cnx,cnx.find('CWSource',name=u'system').one())self.assertEqual(mapping['connait'],set([(bob_eid,alice_eid),(alice_eid,bob_eid)]))classExtEntitiesImporterTC(CubicWebTC):defimporter(self,cnx):store=RQLObjectStore(cnx)returnExtEntitiesImporter(self.schema,store,raise_on_error=True)deftest_simple_import(self):withself.admin_access.repo_cnx()ascnx: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')deftest_import_missing_required_attribute(self):"""Check import of ext entity with missing required attribute"""withself.admin_access.repo_cnx()ascnx:importer=self.importer(cnx)tag=ExtEntity('Personne',2,{'prenom':set([u'Jean'])})self.assertRaises(ValidationError,importer.import_entities,[tag])deftest_import_inlined_relation(self):"""Check import of ext entities with inlined relation"""withself.admin_access.repo_cnx()ascnx: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([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.enfant[0].nom,'Athos')deftest_import_non_inlined_relation(self):"""Check import of ext entities with non inlined relation"""withself.admin_access.repo_cnx()ascnx: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')deftest_import_missing_inlined_relation(self):"""Check import of ext entity with missing inlined relation"""withself.admin_access.repo_cnx()ascnx: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)deftest_import_missing_non_inlined_relation(self):"""Check import of ext entity with missing non-inlined relation"""withself.admin_access.repo_cnx()ascnx: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)deftest_update(self):"""Check update of ext entity"""withself.admin_access.repo_cnx()ascnx:importer=self.importer(cnx)# First importrichelieu=ExtEntity('Personne',11,{'nom':{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 importrichelieu=ExtEntity('Personne',11,{'nom':{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')defextentities_from_csv(fpath):"""Yield ExtEntity read from `fpath` CSV file."""withopen(fpath)asf:foruri,name,knowsinucsvreader(f,skipfirst=True,skip_empty=False):yieldExtEntity('Personne',uri,{'nom':set([name]),'connait':set([knows])})classDataimportFunctionalTC(CubicWebTC):deftest_csv(self):extenties=extentities_from_csv(self.datapath('people.csv'))withself.admin_access.repo_cnx()ascnx:store=RQLObjectStore(cnx)importer=ExtEntitiesImporter(self.schema,store)importer.import_entities(extenties)cnx.commit()rset=cnx.execute('String N WHERE X nom N, X connait Y, Y nom "Alice"')self.assertEqual(rset[0][0],u'Bob')if__name__=='__main__':unittest_main()