示例#1
0
    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)