def test_save_biography(self): # set up a source src = Source(id='123') self.repo.save_source(src) bio1 = Biography(id='id1', source_id=src.id, repository=self.repo) bio1.from_args(naam_publisher="1", url_biografie="http://www.url.com/1", url_publisher="http:///url1.com", naam="name1", text='text1') self.db.save_biography(bio1, user=self.db.user, comment='test') bio1.from_args(naam_publisher="1", url_biografie="http://www.url.com/1", url_publisher="http:///url1.com", naam="name1", text='text2') self.db.save_biography(bio1, user=self.db.user, comment='test') bio = self.db.get_biography(local_id=bio1.id) # basic sanity check self.assertEqual(bio.snippet(), 'text2') person = self.db.get_person(bio1.get_bioport_id()) self.db.update_person(person.bioport_id) person = self.db.get_person(bio1.get_bioport_id()) self.assertEqual(person.snippet(), 'text2')
def test_manipulate_biographies(self): """tests for adding and deleting biographies""" n_bios = n_base = self.db.count_biographies() n_base_soundex = self.db.get_session().query(PersonSoundex).count() self.assertEqual(len(self.db.get_session().query(BiographyRecord).all()), n_base) src = Source(id='123') self.repo.save_source(src) bio1 = Biography(id='ladida', source_id=src.id, repository=self.repo) bio1.from_args(naam_publisher="1", url_biografie="http://www.url.com/1", url_publisher="http:///url2.com", naam="jantje") self.db.save_biography(bio1, user=self.db.user, comment='test') # we have added one new biography, with one name that corresponds to one single soundex n_bios += 1 self.assertEqual(self.db.count_biographies(), n_bios) self.assertEqual(len(self.db.get_session().query(BiographyRecord).all()), n_bios) self.assertEqual(len(self.db.get_session().query(PersonSoundex).all()), n_base_soundex + 1) # this biography has one oauthor bio1.set_value('auteur', ['Johan']) self.db.save_biography(bio1, user=self.db.user, comment='test') # now we have a new version of this biography self.assertEqual(len(self.db.get_session().query(BiographyRecord).all()), n_bios + 1) # but the number of biographies (with version 0) is still the ssame self.assertEqual(len(list(self.db.get_biographies())), n_bios) self.assertEqual(len(bio1.get_value('auteur', [])), 1, bio1.to_string()) bio2 = Biography(id='ladida2', source_id=src.id, repository=self.repo) bio2.from_args(naam_publisher="1", url_biografie="http://www.url.com/1", url_publisher="http:///url2.com", naam="jantje") self.db.save_biography(bio2, user=self.db.user, comment='test') # we added one more biography n_bios += 1 self.assertEqual(len(list(self.db.get_biographies())), n_bios)
def test_add_person(self): # this is what we want to do # add a source source_id = u'bioport_test' # bioport_id = self.db.fresh_identifier() name = u'name, test' source = Source(source_id, repository=self.repo) source.save() # add a biography args = { 'naam_publisher': u'x', 'url_biografie': u'http://placeholder.com', 'url_publisher': u'http://placeholder.com', 'name':name, 'local_id':'1' } biography = Biography(repository=self.repo, source_id=source_id) biography.from_args(**args) # now at this point, the biography does not have a bioport_id yet self.assertEqual(biography.get_bioport_id(), None) biography.save(user=u'test') # this biography should be connected with the source self.assertEqual(biography.get_source(), source) # the biography has a local_id defined self.assertEqual(biography.create_id(), u'bioport_test/1') # the biography should be in the repository bioport_id = biography.get_bioport_id() assert bioport_id # is our biography available in the repository? self.assertEqual(self.repo.get_biography(biography.create_id()), biography) self.assertEqual(self.repo.get_biographies(bioport_id=bioport_id), [biography]) # #now we check if we have added a corresponding person # qry = self.repo.db.get_session().query(PersonRecord).filter(PersonRecord.bioport_id==bioport_id) # assert qry.all(), qry.statement # self.assertEqual(len(qry.all()), 1) # self.assertEqual(qry.one().naam, name) # qry = self.repo.db.get_session().query(PersonSource).filter(PersonSource.bioport_id==bioport_id) # assert qry.all(), qry.statement # # qry = self.repo.db._get_persons_query(full_records=True, hide_invisible=False) person = biography.get_person() self.assertTrue(person.bioport_id, bioport_id) self.assertEqual(person.record.naam, name) person1 = self.db.get_person(bioport_id) self.assertEqual(person1, person) # bioport_id = self.db.fresh_identifier() bioport_id = self.db.fresh_identifier() # we cannot add a person without a biography self.assertRaises(BioPortException, self.db.add_person, bioport_id) # so we first create a biography defaults = { 'naam_publisher': u'x', 'url_biografie': u'http://placeholder.com', 'url_publisher': u'http://placeholder.com', 'name':name, 'bioport_id':bioport_id, } other_source_id = u'this does not exist' biography = Biography(repository=self.repo, source_id=other_source_id) biography.from_args(**defaults) # now, saving this biography should raise an exception, because no source was found self.assertRaises(Exception, biography.save, u'test')