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_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')