def test_simple_process(self):
        '''
        Testing basic execution of the checker
        '''
        input_file = os.path.join(self.filelocation, "Rootstest.rmgc")
        working_file = os.path.join(self.filelocation,
                                    "Rootstest_process.rmgc")

        if os.path.exists(working_file): os.remove(working_file)
        copyfile(input_file, working_file)

        db = database_rm(working_file)
        db_geni = geni_database_interface()
        processor = process_a_db(db, db_geni, event_year_task=1)
        processor.process()

        aunt_prof = db_geni.get_profile_by_ID(
            "https://sandbox.geni.com/people/Aunt-Profile/1231306")
        partners = db_geni.get_partners_from_profile(aunt_prof.get_id())
        for prof_id in partners:
            partner_prof = db_geni.get_profile_by_ID(prof_id)
            if "Aunt Other Partner" in partner_prof.nameLifespan():
                partner_prof.delete_profile()

        db.close_db()
        if os.path.exists(working_file): os.remove(working_file)
    def test_insert_methods(self):
        '''
        Testing insert methods inside RootsMagic
        '''
        initial_file = os.path.join(self.filelocation, "Rootstest.rmgc")
        working_file = os.path.join(self.filelocation, "Rootstest_insert.rmgc")

        if os.path.exists(working_file): os.remove(working_file)
        copyfile(initial_file, working_file)

        db = database_rm(working_file)

        prof = db.get_profile_by_ID(5)
        prof.setWebReference([TEST_GOOGLE, TEST_FACEBOOK])
        prof.setWebReference(TEST_WIKIPEDIA,
                             name="Wikipedia",
                             notes="introduced")

        assert (prof.get_all_webs()[0]["name"] == "")
        prof.update_web_ref(TEST_GOOGLE, "Google", "A note")
        assert (prof.get_all_webs()[0]["name"] == "Google")
        assert (TEST_GOOGLE in prof.get_all_urls())
        assert (TEST_WIKIPEDIA in prof.get_all_urls())

        prof.set_task("TEST")

        db.close_db()
        if os.path.exists(working_file): os.remove(working_file)
Beispiel #3
0
    def test_single_match(self):
        '''
        Tests a single match in GENI
        '''
        #First we create the files for testing
        input_file = os.path.join(self.filelocation, "Rootstest.rmgc")
        working_file = os.path.join(self.filelocation, "Rootstest_sync.rmgc")

        if os.path.exists(working_file): os.remove(working_file)
        copyfile(input_file, working_file)
        ########
        #EXECUTION PART
        ########
        #Preparing the inputs
        db = database_rm(working_file)
        db_geni = geni_database_interface()

        sync_class = sync_profiles(db,
                                   db_geni,
                                   data_language="es",
                                   name_convention="spanish_surname")

        sync_class.execute_sync()

        #We delete the testing data
        db.close_db()
        if os.path.exists(working_file): os.remove(working_file)
Beispiel #4
0
 def test_using_roots_magic(self):
     '''
     Test using climber with RootsMagic database
     '''
     file_rm = os.path.join(self.filelocation, "Rootstest.rmgc")
     rm_db = database_rm(file_rm)
     #We create the climber with the RM database
     climber = climb(rm_db)
     prof = rm_db.get_profile_by_ID(1)
Beispiel #5
0
    def test_open_dabatase_and_read(self):
        '''
        Test accessing the RootsMagic database and basic information access
        '''
        input_file = os.path.join(self.filelocation, "Rootstest.rmgc")
        db = database_rm(input_file)

        #Let's take one profile and test is properly taken
        prof = db.profiles[4]
        assert (prof.getName() == "GrandMother")
        assert (prof.getSurname() == "Profile")
        event_birth = prof.get_specific_event("birth")
        assert (event_birth.get_date() == date(1860, 7, 15))
        assert (event_birth.get_accuracy() == "EXACT")
        event_death = prof.get_specific_event("death")
        assert (event_death.get_year() == 1950)
        assert (event_death.get_accuracy() == "EXACT")
        assert (prof.getGender() == "F")

        #This profile has a date "ABOUT"
        prof2 = db.profiles[2]
        event_birth2 = prof2.get_specific_event("birth")
        assert (event_birth2.get_year() == 1910)
        assert (event_birth2.get_accuracy() == "ABOUT")
        event_death2 = prof2.get_specific_event("death")
        assert (not event_death2)

        #This profile has a date "BEFORE"
        prof3 = db.profiles[3]
        event_death3 = prof3.get_specific_event("death")
        assert (event_death3.get_year() == 1970)
        assert (event_death3.get_accuracy() == "BEFORE")
        assert (prof3.getGender() == "M")

        #This profile includes a wrong sex, it will check the file works properly
        prof4 = db.profiles[5]
        assert (prof4.getGender() == "U")

        #This profile has a date BETWEEN
        prof3 = db.profiles[5]
        event_death4 = prof3.get_specific_event("birth")
        assert (event_death4.get_date() == None)
        assert (event_death4.get_year() == 1820)
        assert (event_death4.get_accuracy() == "BETWEEN")
        assert (event_death4.year_end == 1821)
        assert (event_death4.month_end == 3)
        self.assertFalse(event_death4.day_end)

        db.close_db()
    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)
Beispiel #7
0
    def test_single_match(self):
        '''
        Tests a single match in GENI
        '''
        #First we create the files for testing
        input_file = os.path.join(self.filelocation, "Rootstest.rmgc")
        working_file = os.path.join(self.filelocation, "Rootstest_sync.rmgc")

        if os.path.exists(working_file): os.remove(working_file)
        copyfile(input_file, working_file)
        ########
        #EXECUTION PART
        ########
        #Preparing the inputs
        db = database_rm(working_file)
        db_geni = geni_database_interface()

        sync_class = sync_profiles(db,
                                   db_geni,
                                   data_language="es",
                                   name_convention="spanish_surname")

        logging.basicConfig(level=logging.INFO)

        ########
        #PRE-CHECK PART
        ########
        #In RootsMagic there is not baptism
        assert ("baptism" not in db.get_profile_by_ID(2).getEventsDict())
        #The update has been done several days ago
        assert ((datetime.today() -
                 db.get_profile_by_ID(2).get_update_datetime()).days > 0)

        sync_class.execute_sync()

        ########
        #CHECKING STEP
        ########
        #Baptism should have been copied from the profile in Geni, so now it should have been created
        assert ("baptism" in db.get_profile_by_ID(2).getEventsDict())
        #The update has been done today
        assert ((datetime.today() -
                 db.get_profile_by_ID(2).get_update_datetime()).days == 0)

        #We delete the testing data
        db.close_db()
        if os.path.exists(working_file): os.remove(working_file)
    def test_qualify_of_db(self):
        '''
        Test quality parameters
        '''
        #Just in case the file was created before
        if os.path.exists(FILE2DELETE_QUALITY): os.remove(FILE2DELETE_QUALITY)

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

        qdata = qcheck(dbroots)
        issue, issue_dict = qdata.execute()

        assert (issue == 7)
        assert (6 in issue_dict["gender"])
        assert (9 in issue_dict["existing_date"])

        dbroots.close_db()

        if os.path.exists(FILE2DELETE_QUALITY): os.remove(FILE2DELETE_QUALITY)
    def test_using_roots_magic(self):
        '''
        Test using climber with RootsMagic database
        '''
        file_rm = os.path.join(self.filelocation, "Rootstest.rmgc")
        rm_db = database_rm(file_rm)
        #We create the climber with the RM database
        climber = climb(rm_db)
        prof = rm_db.get_profile_by_ID(1)
        #We execute the ancestors
        ancestors, data_gen = climber.get_ancestors(prof, 4)
        i = 0
        for generation in ancestors:
            i = i + len(generation)
        assert (i == 7)
        total = 0
        for id_value in data_gen.values():
            total += id_value
        assert (total == 3.0)

        cousins, cousins_count, profiles_score = climber.get_cousins(prof, 2)
        assert (cousins[2][2] == [4, 5, 8])
        assert (cousins_count[2][1] == 1)
        assert (sum(list(profiles_score.values())) == 3.5)
Beispiel #10
0
    def test_single_match(self):
        '''
        Tests a single match in GENI
        '''

        input_file = os.path.join(self.filelocation, "Rootstest.rmgc")
        working_file = os.path.join(self.filelocation, "Rootstest_match.rmgc")

        if os.path.exists(working_file): os.remove(working_file)
        copyfile(input_file, working_file)

        db = database_rm(working_file)
        db_geni = geni_database_interface()
        #Delete existing profiles from this testing area
        clean_geni_prof(db_geni)
        matcher = match_single_profile(db,
                                       db_geni,
                                       data_language="es",
                                       name_convention="spanish_surname")
        #Testing profile, no GENI. It will provide an ERROR message, but is expected
        assert (matcher.match(1) == False)
        non_matched_profiles_rm, non_matched_profiles_geni, conflict_profiles, matched_profiles = matcher.match(
            2)
        #=================================================
        #Now we check executions properly done
        #=================================================
        #Profile URL is matched
        matched_total = True
        for id_prof in [4, 5, 1]:
            prof_matched = db.get_profile_by_ID(id_prof)
            is_matched_by_geni = False
            for web_dict in prof_matched.get_all_webs():
                if (web_dict["name"] == "GENI"): is_matched_by_geni = True
            if (not is_matched_by_geni): matched_total = False
        assert (matched_total)
        #Matched is consistent
        assert (4 in matched_profiles.keys())
        assert (5 in matched_profiles.keys())
        assert (3 in matched_profiles.keys())
        assert (1 in matched_profiles.keys())
        #Secure detected conflicts
        assert (7 in conflict_profiles.keys())
        #Check not matched profiles
        assert ('profile-518' in non_matched_profiles_geni.keys())
        #No missing match in RM part
        assert (len(non_matched_profiles_rm.keys()) == 0)

        geni_detected = False
        for task in db.get_profile_by_ID(7).get_all_tasks():
            if ("GENI" in task["task_details"]): geni_detected = True
        assert (geni_detected)

        #===============================================
        # New test with different parameter
        #===============================================
        non_matched_profiles_rm2, non_matched_profiles_geni2, conflict_profiles2, matched_profiles2 = matcher.match(
            11)
        assert (12 in non_matched_profiles_rm2.keys())
        #assert(13 in non_matched_profiles_rm2.keys())
        assert ("profile-553" in non_matched_profiles_geni2.keys())
        assert ("profile-579" in non_matched_profiles_geni2.keys())
        assert (not conflict_profiles2)
        assert (10 in matched_profiles2.keys())
        #Delete existing profiles from this testing area
        clean_geni_prof(db_geni)

        db.close_db()
        if os.path.exists(working_file): os.remove(working_file)
    def test_open_dabatase_and_read(self):
        '''
        Test accessing the RootsMagic database and basic information access
        '''
        input_file = os.path.join(self.filelocation, "Rootstest.rmgc")
        db = database_rm(input_file)
        assert (db.get_db_kind() == "ROOTSMAGIC")
        #Let's take one profile and test is properly taken
        prof = db.get_profile_by_ID(5)
        assert (prof.getName() == "GrandMother")
        assert (prof.getSurname() == "Profile")
        event_birth = prof.get_specific_event("birth")
        assert (event_birth.get_date() == date(1860, 7, 15))
        assert (event_birth.get_accuracy() == "EXACT")
        assert (prof.get_accuracy_event("birth") == "EXACT")

        event_death = prof.get_specific_event("death")
        assert (event_death.get_year() == 1950)
        assert (event_death.get_accuracy() == "EXACT")
        assert (prof.getGender() == "F")
        assert (len(prof.getEvents()) == 4)
        assert (prof.getLiving() == False)

        #This profile has a date "ABOUT"
        prof2 = db.get_profile_by_ID(3)
        event_birth2 = prof2.get_specific_event("birth")
        assert (event_birth2.get_year() == 1910)
        assert (event_birth2.get_accuracy() == "ABOUT")
        event_death2 = prof2.get_specific_event("death")
        assert (not event_death2)
        #Also includes web_references
        iswebthere = False
        for web in prof2.get_all_urls().keys():
            if "familysearch.org/tree/person" in web: iswebthere = True
        assert (iswebthere)

        #This profile has a date "BEFORE"
        prof3 = db.get_profile_by_ID(4)
        event_marriage = prof3.get_specific_event("marriage")
        assert (event_marriage[0].get_year() == 1880)
        event_death3 = prof3.get_specific_event("death")
        assert (event_death3.get_year() == 1970)
        assert (event_death3.get_accuracy() == "BEFORE")
        assert (prof3.getGender() == "M")

        #This profile includes a wrong sex, it will check the file works properly
        prof4 = db.get_profile_by_ID(6)
        assert (prof4.getGender() == "U")
        event_death4 = prof4.get_specific_event("birth")
        assert (event_death4.get_date() == None)
        assert (event_death4.get_year() == 1820)
        assert (event_death4.get_accuracy() == "BETWEEN")
        assert (event_death4.year_end == 1821)
        assert (event_death4.month_end == 3)
        self.assertFalse(event_death4.day_end)
        #Also includes web_references
        assert (len(prof4.get_all_webs()) == 2)

        #This profile has a date BETWEEN
        prof5 = db.get_profile_by_ID(1)
        eventsof1 = prof5.getEvents()
        no_marriage = True
        assert ("Mariano Profile" in prof5.get_nicknames())
        for event in eventsof1:
            if event.get_event_type() == "marriage": no_marriage = False
        assert (no_marriage)
        event_birth3 = prof5.get_specific_event("birth")
        assert (event_birth3.get_location()["county"] == "Segovia")
        assert (event_birth3.get_location()["latitude"] < 41.08)
        assert (prof5.getLiving())

        #Now we check that None is provided if there is no profile in
        assert (db.get_profile_by_ID("dsdf") == None)
        assert (db.get_profile_by_ID(2325) == None)

        #Let's check all families
        assert (db.get_family_by_ID(2325) == None)

        #Let's check the proper data of a family
        assert (db.get_family_by_ID(1).getFather() == 2)
        assert (db.get_family_by_ID(1).getMother() == 3)
        assert (db.get_family_by_ID(3).getMother() == None)
        assert (db.get_family_by_ID(4).getFather() == None)
        assert (db.get_family_by_ID(1).getChildren() == [1, 7])
        assert (len(db.get_family_by_ID(5).getChildren()) == 0)
        #Check getting the family id from the child
        assert (db.get_family_from_child(7)[0] == 1)
        assert (db.get_father_from_child(7)[0] == 2)
        assert (db.get_mother_from_child(7)[0] == 3)

        #This will provide the children of a given profile
        assert (2 in db.get_all_family_ids_is_parent(5))
        children = db.get_all_children(2)
        assert (1 in children)
        assert (1 in children)

        assert (10 in db.get_partners_from_profile(11))
        assert (13 in db.get_partners_from_profile(11))
    def test_insert_methods(self):
        '''
        Testing insert methods inside RootsMagic
        '''
        initial_file = os.path.join(self.filelocation, "Rootstest.rmgc")
        working_file = os.path.join(self.filelocation, "Rootstest_insert.rmgc")

        if os.path.exists(working_file): os.remove(working_file)
        copyfile(initial_file, working_file)

        db = database_rm(working_file)

        prof = db.get_profile_by_ID(5)
        prof.setWebReference([TEST_GOOGLE, TEST_FACEBOOK])
        prof.setWebReference(TEST_WIKIPEDIA,
                             name="Wikipedia",
                             notes="introduced")
        webs = prof.get_all_webs()
        google_found = False
        for web in webs:
            if web["url"] == "http://www.google.com":
                if web["name"] == "": google_found = True
        assert (google_found)
        assert (prof.update_web_ref(TEST_GOOGLE, "Google", "A note"))
        google_found = False
        webs = prof.get_all_webs()
        for web in webs:
            if web["name"] == "Google": google_found = True
        assert (google_found)
        assert (TEST_GOOGLE in prof.get_all_urls())
        assert (TEST_WIKIPEDIA in prof.get_all_urls())
        assert (prof.get_specific_web("Google"))
        assert (not prof.get_specific_web("Not existing"))

        prof.del_web_ref(TEST_WIKIPEDIA)
        assert (not (TEST_WIKIPEDIA in prof.get_all_urls()))
        #It does not essent
        assert (prof.update_web_ref("DOES NOT EXISTS", "Googles", "A note") is
                None)

        prof.set_task("TEST", details="HAHA")

        #Introduce a research log
        row_id = prof.set_task("TEST_OF_LOG", task_type=2)
        assert (prof.get_specific_research_log("TEST_OF_LOG"))
        assert (prof.get_specific_research_log("TEST_NOT_EXISTING") == None)

        prof.set_research_item(row_id,
                               repository="www.google.com",
                               source="GOOGLE",
                               result="GOOD")
        prof.update_research_item(row_id,
                                  "www.google.com",
                                  source="GOOGLE2",
                                  result="BAD")
        #Error when 2 research logs of the same name in the same profile.
        profb = db.get_profile_by_ID(6)
        with self.assertLogs("rootsmagic", level="WARNING") as cm:
            profb.get_specific_research_log("TWICE")
            assert ("TWICE" in cm.output[0])

        prof2 = db.get_profile_by_ID(1)

        assert (len(prof2.get_all_research_item()) == 2)

        prof3 = db.get_profile_by_ID(3)

        assert (len(prof3.get_all_research_item()) == 0)

        #Setting up the sources
        assert (prof2.get_source_id_ref("TESTING") == None)
        prof2.set_source_id("TESTING")
        prof2.setWebReference("http//here.com", "NEW_URL")
        assert (prof2.get_source_id_ref("TESTING") == 1)
        assert (prof2.get_citation_with_comments("http://test.com") == None)
        prof2.set_citation(1, details="http://test.com")
        assert (prof2.get_citation_with_comments("http://test.com") == 1)

        #Testing the insert of the profiles
        insert_profile = gen_profile("RootsMagic", "Adding")
        insert_profile.setCheckedGender("M")
        insert_profile.setCheckedDate("birth", 1820, accuracy="ABOUT")

        event_both = event_profile("birth")
        event_both.setLocationAlreadyProcessed(
            {"formatted_location": "Gallegos, Segovia"})
        event_both.setDate(1820, accuracy="ABOUT")
        event_date = event_profile("death")
        event_date.setDate(1902, month=2, day=1, accuracy="EXACT")
        event_location = event_profile("burial")
        event_location.setLocation("Aldealaguna, Segovia, Spain")

        insert_profile.setNewEvent(event_both)
        insert_profile.setNewEvent(event_date)
        insert_profile.setNewEvent(event_location)

        prof_id = db.add_profile(insert_profile)
        #Check the results
        prof_entered = db.get_profile_by_ID(prof_id)
        assert (prof_entered.getName() == "RootsMagic")
        assert (prof_entered.get_specific_event("birth").get_year() == 1820)
        assert (
            prof_entered.get_specific_event("birth").get_accuracy() == "ABOUT")
        assert (prof_entered.get_specific_event("birth").get_location()["raw"]
                == "Gallegos, Segovia")
        assert (prof_entered.get_specific_event("death").get_year() == 1902)
        assert (
            prof_entered.get_specific_event("death").get_accuracy() == "EXACT")
        assert (
            prof_entered.get_specific_event("death").get_location() == None)
        assert (prof_entered.get_specific_event("burial").get_year() == None)
        assert (prof_entered.get_specific_event("burial").get_location()["raw"]
                == 'Aldealaguna, Segovia, Spain')

        #Now, let's also create a family for this profile
        insert_wife = gen_profile("RootsMagic", "Wife")
        insert_wife.setCheckedGender("F")
        wife_id = db.add_profile(insert_wife)
        prof_wife = db.get_profile_by_ID(wife_id)
        event_marriage = event_profile("marriage")
        event_marriage.setDate(1815, accuracy="ABOUT")
        assert (prof_wife.get_specific_event("marriage") == [])
        fam_id = db.add_family(father=prof_id,
                               mother=wife_id,
                               children=[6],
                               marriage=event_marriage)
        assert (prof_wife.get_specific_event("marriage")[0].get_year() == 1815)
        assert (db.get_family_from_child(6)[0] == fam_id)

        #Methods for updating the family of RootsMagic
        assert (not db.update_family(fam_id))
        new_husband = gen_profile("New", "Husband")
        new_wife = gen_profile("New", "Wife")
        new_child = gen_profile("New", "Child")
        new_husband_id = db.add_profile(new_husband)
        new_wife_id = db.add_profile(new_wife)
        new_child_id = db.add_profile(new_child)
        marriage = event_profile("marriage")
        marriage.setDate(1900)
        fam3 = db.get_family_by_ID(3)
        assert (fam3.getMother() == None)
        db.update_family(3,
                         mother_id=new_wife_id,
                         children=[new_child_id],
                         marriage=marriage)
        assert (fam3.getMother() == new_wife_id)

        fam4 = db.get_family_by_ID(4)
        assert (fam4.getFather() == None)
        db.update_family(4, father_id=new_husband_id, marriage=marriage)
        assert (fam4.getFather() == new_husband_id)

        new_child2 = gen_profile("Newer", "Child")
        new_child3 = gen_profile("Older", "Child")
        previous_len = len(fam4.getChildren())
        db.add_child(4, [new_child2, new_child3])
        assert (len(fam4.getChildren()) - previous_len == 2)

        new_partner1 = gen_profile("New", "Partner")
        new_marriage = event_profile("birth")
        new_marriage.set_year("2019")
        previous_partners = len(db.get_partners_from_profile(4))
        db.add_partner(4, new_partner1, new_marriage)
        assert (len(db.get_partners_from_profile(4)) - previous_partners == 1)

        db.close_db()
        if os.path.exists(working_file): os.remove(working_file)