def get_all_profiles(self):
     '''
     Returns all profiles in the database
     '''
     profiles = []
     for id_key in self.gedcom:
         if self.gedcom[id_key].get("VALUE", None) == "INDI":
             profiles.append(gedcom_profile(self.gedcom[id_key]))
     return profiles
 def test_adding_and_saving_database(self):
     '''
     Test of addition to the gedcom file of new persons, families and saving it
     '''
     input_file = os.path.join(self.filelocation, "gedcom_test.gedcom")
     initial_gedcom = db_gedcom(input_file)
     no_gedcom = db_gedcom()
     #Profile to add an play :)
     profile1 = gedcom_profile(name="Juana", surname="Bargas")
     profile2 = gedcom_profile(name="José", surname="Sánchez")
     profile3 = gedcom_profile(name="José", surname="Bargas Sánchez")
     profile4 = gedcom_profile(name="Juana", surname="Bargas Sánchez")
     #Adding to initial gedcom
     assert (not "@I2@" in initial_gedcom.gedcom.keys())
     initial_gedcom.add_profile(profile1)
     assert ("@I2@" in initial_gedcom.gedcom.keys())
     initial_gedcom.save_gedcom_file("delete_me_if_found.ged")
     assert (os.path.exists("delete_me_if_found.ged"))
     #Testing that I can read my own output
     initial_gedcom_again = db_gedcom("delete_me_if_found.ged")
     assert ("@I2@" in initial_gedcom_again.gedcom.keys())
     os.remove("delete_me_if_found.ged")
     #Adding to the not existing database and also gedcom
     id1 = no_gedcom.add_profile(profile1)
     id2 = no_gedcom.add_profile(profile2)
     id3 = no_gedcom.add_profile(profile3)
     assert (profile4.get_id() == None)
     id4 = no_gedcom.add_profile(profile4)
     assert (profile4.get_id() == "@I4@")
     assert ("@I4@" in no_gedcom.gedcom.keys())
     fm1 = no_gedcom.add_family(father=id1, mother=id2, children=[id3, id4])
     assert (fm1 == "@F1@")
     assert (no_gedcom.gedcom["@F1@"]["HUSB"]["VALUE"] == "@I1@")
     assert (len(no_gedcom.gedcom["@F1@"]["CHIL"]["VALUE"]) == 2)
     profs = no_gedcom.get_all_profiles()
     assert (len(profs) == 4)
    def test_output_from_gedcom(self):
        '''
        It will take a gedcom dataclass and perform all executions available
        '''
        #Just in case the file was created before
        if os.path.exists(FILE2DELETE): os.remove(FILE2DELETE)
        if os.path.exists(ROOTS_MAGIC_GEN_ANALYZER):
            os.remove(ROOTS_MAGIC_GEN_ANALYZER)
        profile = gen_profile("Julián", "Gómez Gómez")
        profile.setCheckedDate("baptism", 1970, 4, 2)
        profile.setCheckedDate("birth", 1960, 4, 2)
        profile.setCheckedDate("death", 2017, 2, 12)
        gedcom_profile.convert_gedcom(profile)

        dbgenea = gen_database()
        dbgenea.add_profile(profile)

        profile2 = gedcom_profile(name="Julián", surname="Gómez Gómez")
        profile2.setCheckedDate("baptism", 1970, 4, 2)
        profile2.setCheckedDate("birth", 1960, 4, 2)
        profile2.setCheckedDate("death", 2017, 2, 12)
        assert ("BIRT" in profile2.individual)
        dbged = db_gedcom()
        dbged.add_profile(profile2)

        #Test that works with RootsMagic

        input_file = os.path.join(self.filelocation,
                                  "RootsMagic_analyzer.rmgc")
        copyfile(input_file, ROOTS_MAGIC_GEN_ANALYZER)
        dbroots = database_rm(ROOTS_MAGIC_GEN_ANALYZER)

        analysis = gen_analyzer()
        analysis.execute(dbgenea, FILE2DELETE)
        analysis.execute(dbged)
        #Threshold will make any analysis to be ignored
        analysis.execute(dbroots, storage=True, threshold=360)
        urls = 0
        for person in dbroots.get_all_profiles():
            urls += len(person.get_all_urls())
        assert (urls > 6)
        assert (os.path.exists(FILE2DELETE))
        dbroots.close_db()
        #We just delete the file once finishes
        if os.path.exists(FILE2DELETE): os.remove(FILE2DELETE)
        if os.path.exists(ROOTS_MAGIC_GEN_ANALYZER):
            os.remove(ROOTS_MAGIC_GEN_ANALYZER)
示例#4
0
    def test_creating_gedcom_profile(self):
        '''
        Test Creating a GedCom Profile
        '''
        name_data = "MyName"
        surname = "MySurname"
        total_name = name_data + "/" + surname + "/"

        individual = gedcom.Individual()
        name = gedcom.Element(tag="NAME", value=total_name)
        name_given = gedcom.Element(tag="GIVN", value=name_data)
        name_surname = gedcom.Element(tag="SURN", value=surname)
        name.add_child_element(name_given)
        name.add_child_element(name_surname)
        individual.add_child_element(name)

        profile = gedcom_profile(individual)

        assert (profile.gen_data["name"] == name_data)
        assert (profile.gen_data["surname"] == surname)
 def get_profile_by_ID(self, id_profile):
     '''
     Returns the profile by the input ID
     '''
     return gedcom_profile(self.gedcom[id_profile])