示例#1
0
 def test_exception_on_standard_verify(self):
     '''
     Test that sandbox geni is not fixed
     '''
     try:
         profile.profile("1149101")
         assert (False)
     except:
         assert (True)
    def test_creating_a_child(self):
        '''
        Test creation of a child profile
        '''
        child_profile = gen_profile(ACTUAL_NAME, FATHER_SURNAME)
        child_profile.setCheckedGender("M")
        child_profile.set_name_2_show(ACTUAL_NAME)
        child_profile.setCheckedDate("birth_date", date(2017, 11, 20), "ABOUT")
        child_profile.setCheckedDate("death_date", date(2017, 12, 1), "EXACT")
        child_profile.add_nickname("my_nickname")
        profile.profile.create_as_a_child(child_profile,
                                          union=UNION_MAIN_PROFILE)

        data_id = child_profile.geni_specific_data['guid']
        assert (child_profile.properly_executed)
        assert (child_profile.existing_in_geni)
        #Check input of data
        assert (child_profile.data["gender"] == "male")
        assert (child_profile.data["last_name"] == FATHER_SURNAME)
        #Checking dates
        assert (child_profile.data["birth"]["date"]["year"] == 2017)
        assert (child_profile.data["birth"]["date"]["circa"] == True)
        self.assertFalse("month" in child_profile.data["birth"]["date"].keys())
        assert (child_profile.data["death"]["date"]["year"] == 2017)
        assert (child_profile.data["death"]["date"]["month"] == 12)
        assert (child_profile.data["death"]["date"]["day"] == 1)
        assert (child_profile.data["public"] == False)
        assert ("my_nickname" in child_profile.data["nicknames"])
        prof_relations = profile.profile(MAIN_SANDBOX_PROFILE, type_geni="")

        assert (len(prof_relations.marriage_union) == 1)
        for dif_union in prof_relations.marriage_union:
            assert ("union-156" in dif_union.union_id)
        for dif_union in prof_relations.parent_union:
            assert ("union-155" in dif_union.union_id)

        #We introduce other 2 childs using different methods
        second_profile = gen_profile(ACTUAL_SECOND, FATHER_SURNAME)
        profile.profile.create_as_a_child(second_profile,
                                          profile=prof_relations)
        third_profile = gen_profile(ACTUAL_THIRD, FATHER_SURNAME)
        profile.profile.create_as_a_child(third_profile,
                                          geni_input=MAIN_SANDBOX_PROFILE,
                                          type_geni="")
        assert (second_profile.properly_executed)
        assert (third_profile.properly_executed)

        #We delete to avoid creation of data
        assert (child_profile.delete_profile())
        assert (second_profile.delete_profile())
        assert (third_profile.delete_profile())
        self.assertFalse(child_profile.existing_in_geni)

        #We check is deleted
        existing = profile.profile(data_id)

        assert (existing.geni_specific_data['deleted'])
示例#3
0
    def test_different_geni_inptus(self):
        '''
        Test different Geni inputs to profile
        '''
        prof = profile.profile(SANDBOX_MAIN_ADDRESS)
        prof2 = profile.profile(SANDBOX_MAIN_API_G)
        prof3 = profile.profile(SANDBOX_MAIN_API_NOG)

        assert (prof.geni_specific_data["id"] == MAIN_SANDBOX_PROFILE_ID)
        assert (prof2.geni_specific_data["id"] == MAIN_SANDBOX_PROFILE_ID)
        assert (prof3.geni_specific_data["id"] == MAIN_SANDBOX_PROFILE_ID)
 def create_profiles_in_Geni(self, geni_data):
     '''
     This method will create the needed profiles directly in Geni
     '''
     if not self.correct_execution:
         logging.error(NO_GENI_EXECUTION)
         return False
     else:
         connector = geni_calls()
         valid = connector.check_valid_genikey()
         if not valid:
             #Ok, it appears the call is not correct and we are getting an error message
             logging.error(NO_GENI_KEY)
             return False
         else:
             parent_data = profile.profile(geni_input=geni_data)
             other_parent = None
             #We only make it for a single partner
             if len(parent_data.partner) == 1:
                 other_parent = profile.profile(geni_input=parent_data.partner[0])
             #We need to understand if it is mother of father, and then the logic diverts
             if (parent_data.gen_data["gender"] == "M"):
                 self.father_profile.merge_profile(parent_data, language = self.language, convention = self.naming_convention)
                 if other_parent: self.mother_profile.merge_profile(other_parent, language = self.language, convention = self.naming_convention)
             else:
                 self.mother_profile.merge_profile(parent_data, language = self.language, convention = self.naming_convention)
                 if other_parent: self.father_profile.merge_profile(other_parent, language = self.language, convention = self.naming_convention)
             #Once parents have been read, we proceed to create the profiles.
             for profile_obtained in self.profiles:
                 logging.info(profile_obtained.returnFullName())
                 profile.profile.create_as_a_child(profile_obtained, geni_input=geni_data )
                 self.geni_profiles.append(profile_obtained)
                 logging.info(profile_obtained.geni_specific_data["url"])
                 if profile_obtained.gen_data.get("marriage_link", None) in self.related_profiles.keys():
                     id_of_marriage = profile_obtained.gen_data["marriage_link"]
                     partner = self.related_profiles[id_of_marriage]
                     profile.profile.create_as_a_partner(partner, geni_input=profile_obtained.geni_specific_data["id"],
                                                 type_geni="" )
                     self.related_geni_profiles.append(partner)
                     logging.info(partner.geni_specific_data["url"])
                     if id_of_marriage in self.parents_profiles.keys():
                         father = self.parents_profiles[id_of_marriage][0]
                         mother = self.parents_profiles[id_of_marriage][1]
                         profile.profile.create_as_a_parent(father, geni_input=partner.geni_specific_data["id"], type_geni="" )
                         profile.profile.create_as_a_parent(mother, geni_input=partner.geni_specific_data["id"], type_geni="" )
                         self.parents_geni_profiles.append(father)
                         self.parents_geni_profiles.append(mother)
     logging.info(ENDED)
     return True
 def test_error_adding_marriage(self):
     '''
     Test no adding marriage data due to error
     '''
     prof = profile.profile(GENI_TWO_MARRIAGES_PROFILE, type_geni="")
     self.assertFalse(prof.add_marriage_in_geni())
     self.assertFalse(prof.delete_profile())
示例#6
0
 def get_several_profile_by_ID(self, ID_array):
     '''
     Returns a dict of profiles from Geni
     ID_array is a list of profile IDs.
     '''
     input_array = ""
     if (len(ID_array) ==1): return {ID_array[0] : self.get_profile_by_ID(ID_array[0])}
     #This variable is used to check the case all profiles are already available to avoid a call
     all_profiles_existing = True
     for id_one in ID_array:
         if id_one not in self.profiles.keys(): all_profiles_existing = False
         input_array = input_array + "," + id_one
     #We have 2 options, if all profiles are existing in the interface, we do not need to do the call...
     output_array = {}
     if all_profiles_existing:
         for id_one in ID_array:
             output_array[id_one] = self.get_profile_by_ID(id_one)
     else:
         #There is a bug in the API, apparently is not working....
         DUMMY_INPUT = "profile-1"
         url = s.GENI_PLUS_PROFILES + input_array[1:]+ "," + DUMMY_INPUT + self.token_string()
         r = s.geni_request_get(url)
         data = r.json()
         for prof_data in data["results"]:
             if not ( prof_data["id"] == DUMMY_INPUT):
                 output_array[prof_data["id"]] = profile(prof_data["id"], prof_data)
     return output_array
    def test_reading_sandbox_profile(self):
        '''
        Test reading a profile in sandbox
        '''
        prof = profile.profile(MAIN_SANDBOX_PROFILE, type_geni="")
        assert ("Testing" in prof.nameLifespan())
        assert (prof.properly_executed)

        assert (prof.gen_data["gender"] == "M")
        assert (prof.gen_data["surname"] == "Profile")
        assert (prof.gen_data["name"] == "Testing")
        #Testing using profile input

        prof = profile.profile(MAIN_SANDBOX_PROFILE_API)
        assert (prof.gen_data["name"] == "Testing")
        assert (prof.properly_executed)
    def testGettingCorrectName(self):
        '''
        This test checks that the name of philip the IV of Spain is properly detected
        '''
        assert ("Philip" in self.philip.nameLifespan())
        assert ("1605" in self.philip.nameLifespan())
        assert ("1665" in self.philip.nameLifespan())
        assert (self.philip.gen_data["birth"].get_date() == date(1605, 4, 8))
        assert (self.philip.gen_data["baptism"].year == 1605)
        assert (self.philip.gen_data["baptism"].month == 5)
        assert (self.philip.gen_data["death"].get_date() == date(1665, 9, 17))
        assert (self.philip.gen_data["burial"].get_date() == date(1665, 9, 20))

        assert (self.philip.gen_data["birth"].location["city"] == 'Valladolid')
        assert (self.philip.gen_data["baptism"].location["place_name"] ==
                'Iglesia Conventual San Pablo')
        assert (
            self.philip.gen_data["death"].location["city"] == 'El Escorial')
        assert (self.philip.gen_data["burial"].location["place_name"] ==
                'San Lorenzo de El Escorial')
        assert (self.philip.getLiving() == False)
        #Simplifies the previous file into only 1 test
        assert (self.philip.get_id() == PHILIPIVid)
        philip_bis = profile.profile(PHILIPIVget, "")
        assert (philip_bis.get_id() == self.philip.get_id())
示例#9
0
 def testCousinsExecution(self):
     '''
     We will test the cousins execution in different way. Will be tested by
     number, not by person
     '''
     #Database creation
     geni_db = geni_database_interface()
     philip = profile(COUSIN_PROFILE)
     generations = 2
     
     climber = climb(geni_db)
     ancestors, anc_count, profiles = climber.get_cousins(philip, generations)
     
     total_center = 0
     total_outside = 0
     for i in range(0, generations+1):
         total_center = total_center + anc_count[i][i]
         for j in range(i+1, generations + 1):
             total_outside = total_outside + anc_count[i][j]
     assert(total_center == 7) 
     assert(total_outside == 0) 
     
     total_final = 0
     #We are counting here the number of cousing of the generation selected.
     #However, I noticed that this number varies... I selected an historical person
     #Philip IV of Spain, but apparently hundreds of years after... still new cousins appear.
     #TODO: fix this with a more stable profile, potentially from sandbox.
     for i in range(0, generations+1):
         for j in range(0, generations + 1):
             total_final = total_final + anc_count[i][j]
     assert(total_final == 32)
     assert(len(profiles) == 32)
示例#10
0
 def test_parser_profile_input(self):
     '''
     Tests that a profile inputs provide the right result
     '''
     prof = profile.profile(GENI_TWO_MARRIAGES_PROFILE, type_geni="")
     example = profile.process_profile_input(profile=prof)
     assert (example == GENI_TWO_MARRIAGES_PROFILE_LINK)
def main():
    logging.basicConfig(filename='GeniToools.log', level=logging.INFO)
    logging.info('Starting GeniTools\n' + "=" * 20 + "\n")

    #Firstly the Input File is Read
    data = reader_input.reader_input("INPUT")

    base_call = geni_calls(data.genikey)

    if (data.continue_execution and base_call.check_valid_genikey()):
        #We only continue if inputs are correct!
        test_profile = profile.profile(data.profile, data.genikey)

        if (data.climbancestors or data.climbcousins):
            climber = climb(test_profile)
            if (data.climbcousins):
                ancestors, matrix_count, included_profiles = climber.get_cousins(
                    data.generations)
                print(matrix_count)
            if (data.climbancestors):
                ancestors, affected_profiles = climber.get_ancestors(
                    data.generations)
    else:
        logging.error(ERROR_MISSING_DATA)

    logging.info('Finishing GeniTools' + "=" * 20 + "\n")
示例#12
0
 def test_delete_not_existing_profile(self):
     '''
     Test deleting a not existing profile
     '''
     prof3 = profile.profile(OLD_DELETED_SON, type_geni="")
     assert (prof3.geni_specific_data['deleted'])
     assert (prof3.delete_profile() == False)
示例#13
0
 def test_alternative_data_in_profile(self):
     '''
     Test other data in the profile
     '''
     prof = profile.profile(BROTHER_PROFILE_SANDBOX)
     assert (len(prof.gen_data["nicknames"]) == 2)
     assert ("brother" in prof.gen_data["nicknames"])
示例#14
0
 def testCousinsExecution(self):
     '''
     We will test the cousins execution in different way. Will be tested by
     number, not by person
     '''
     philip = profile(COUSIN_PROFILE)
     generations = 2
     
     climber = climb(philip)
     ancestors, anc_count, profiles = climber.get_cousins(generations)
     
     total_center = 0
     total_outside = 0
     for i in range(0, generations+1):
         total_center = total_center + anc_count[i][i]
         for j in range(i+1, generations + 1):
             total_outside = total_outside + anc_count[i][j]
     assert(total_center == 7) 
     assert(total_outside == 0) 
     
     total_final = 0
     for i in range(0, generations+1):
         for j in range(0, generations + 1):
             total_final = total_final + anc_count[i][j]
     assert(total_final == 36)
     assert(len(profiles) == 36)
示例#15
0
    def test_reading_sandbox_profile(self):
        '''
        Test reading a profile in sandbox
        '''
        prof = profile.profile(MAIN_SANDBOX_PROFILE, type_geni="")
        assert ("Testing" in prof.nameLifespan())
        assert (prof.properly_executed)

        assert (prof.gen_data["gender"] == "M")
        assert (prof.gen_data["surname"] == "Profile")
        assert (prof.gen_data["name"] == "Testing")
        #Securing before is properly captured
        assert (prof.get_accuracy_event("baptism") == "BEFORE")

        prof = profile.profile(MAIN_SANDBOX_PROFILE_API)
        assert (prof.gen_data["name"] == "Testing")
        assert (prof.properly_executed)
示例#16
0
 def test_error_adding_marriage(self):
     '''
     Test no adding marriage data due to error
     '''
     prof = profile.profile(GENI_2_MARRIAGES_IN_GENI, type_geni="")
     assert (prof.get_specific_event("baptism").get_accuracy() == "ABOUT")
     self.assertFalse(prof.add_marriage_in_geni())
     self.assertFalse(prof.delete_profile())
示例#17
0
 def test_geni_to_gedcom(self):
     '''
     Test a geni profile to Gedcom
     '''
     prof = profile.profile(MAIN_SANDBOX_PROFILE, type_geni="")
     assert ("Testing" in prof.nameLifespan())
     gedcom_profile.convert_gedcom(prof)
     location = prof.get_location_event("baptism")
     #We crosscheck the value is properly included in the file
     assert ("STAE" in prof.individual["BAPM"]["ADDR"].keys())
     assert (location["city"] == "La Mata")
示例#18
0
 def testStopWithNoAncestors(self):
     '''
     If there are no longer ancestors, the ancestor climb should stop.
     Checking if that works! This profile has only one generation available
     '''
     flavia = profile(FLAVIAg)
     
     climber = climb(flavia)
     ancestors = climber.get_ancestors(6)
     
     assert(len(ancestors) == 2)
示例#19
0
 def test_reading_sandbox_profile(self):
     '''
     Test reading a profile in sandbox
     '''
     prof = profile.profile(MAIN_SANDBOX_PROFILE, type_geni="")
     assert( "Testing" in prof.nameLifespan())
     assert(prof.properly_executed)
     
     assert(prof.gen_data["gender"] == "M")
     assert(prof.gen_data["surname"] == "Profile")
     assert(prof.gen_data["name"] == "Testing")
     #Securing before is properly captured
     assert(prof.get_accuracy_event("baptism") == "BEFORE")
     
     #Be careful! If the profile gets changed, this checking might fail
     assert(prof.get_update_datetime().year == 2018)
     
     prof = profile.profile(MAIN_SANDBOX_PROFILE_API)
     assert(prof.gen_data["name"] == "Testing")
     assert(prof.properly_executed)
示例#20
0
 def get_profile_by_ID(self, id_profile):
     '''
     Returns the profile by the input ID
     '''
     if not ( (id_profile in self.profiles.keys()) or (id_profile in self.equivalence.keys()) ):
         prof = profile(id_profile)
         #We use an unique id with profile in front
         self.profiles[prof.get_id()] = prof
         if id_profile != prof.get_id():
             self.equivalence[id_profile] = prof.get_id()
     if id_profile in self.profiles.keys(): return self.profiles[id_profile]
     else: return self.profiles[self.equivalence[id_profile]]
示例#21
0
 def test_geni_to_gedcom(self):
     '''
     Test a geni profile to Gedcom
     '''
     prof = profile.profile(MAIN_SANDBOX_PROFILE, type_geni="")
     assert ("Testing" in prof.nameLifespan())
     gedcom_profile.convert_gedcom(prof)
     data_event = prof.get_event_element("birth")
     element_top = data_event[1]
     element_sub = element_top.child_elements[1]
     #We crosscheck the value is properly included in the file
     assert (element_sub.tag == "PLAC")
     assert ("Gallegos" in element_sub.value)
示例#22
0
 def test_adding_a_parent(self):
     '''
     Test adding a parent in Geni
     '''
     
     father_profile = gen_profile(ACTUAL_NAME, FATHER_SURNAME)
     father_profile.setCheckedGender("M")
     
     profile.profile.create_as_a_parent(father_profile, geni_input=FATHER_PROFILE_SANDBOX)
     
     prof3 = profile.profile(FATHER_PROFILE_SANDBOX)
     assert(father_profile.geni_specific_data["id"] in prof3.parents)
     assert(father_profile.delete_profile())
示例#23
0
 def testStopWithNoAncestors(self):
     '''
     If there are no longer ancestors, the ancestor climb should stop.
     Checking if that works! This profile has only one generation available
     '''
     #Database creation
     geni_db = geni_database_interface()
     flavia = profile(FLAVIAg)
     
     climber = climb(geni_db)
     ancestors = climber.get_ancestors(flavia, 6)
     
     assert(len(ancestors) == 2)
    def testCountingOfAncestors(self):
        '''
        Testing the right calculation of ancestors. We know Philip IV was
        having duplicated ancestors, so the number will be lower than the 
        generation count.
        '''
        #Database creation
        geni_db = geni_database_interface()
        philip = profile(PHILIPIVg)

        climber = climb(geni_db)

        ancest = climber.get_ancestors(philip, 4)
        assert (len(ancest[1].keys()) == 23)
示例#25
0
 def force_update_profile(self, profile_id):
     '''
     It will force the update of the profile id used by functions which include
     new profiles inside database
     '''
     #Profile data is updated
     self.profiles[profile_id] = profile(profile_id)
     id_prof = self.profiles[profile_id].get_id()
     #The link to the families is updated.
     self.inmediate[id_prof] = immediate_family(id_prof)
     #Update of families of the profile
     unions = list(self.inmediate[id_prof].parent_union) + list(self.inmediate[id_prof].marriage_union)
     for union_now in unions:
         self.families[union_now.get_id()] = union(union_now.get_id())
示例#26
0
 def testCountingOfAncestors(self):
     '''
     Testing the right calculation of ancestors. We know Philip IV was
     having duplicated ancestors, so the number will be lower than the 
     generation count.
     '''
     philip = profile(PHILIPIVg)
     
     climber = climb(philip)
     ancestors, profiles = climber.get_ancestors(4)
     i = 0
     for generation in ancestors:
         i = i + len(generation.values())
     assert(i == 23)
     assert(len(profiles) == 23)
示例#27
0
 def test_get_gedcom(self):
     '''
     Test to obtain a gedcom down a profile
     '''
     file_ged = os.path.join(self.filelocation, "output_test_geni2gedcom.ged")
     if os.path.exists(file_ged): os.remove(file_ged)
     prof = profile.profile(GRANDFATHER_SANDBOX)
     tester = geni2gedcom.geni2gedcom(prof)
     geddb = tester.get_gedcom(file_ged)
     
     counts = 0
     for person in geddb.get_all_profiles():
         if GENI2GEDCOM_DUPLICATED in person.getName2Show(): counts += 1
     assert(counts == 1)
     
     if os.path.exists(file_ged): os.remove(file_ged)
    def test_get_gedcom(self):
        '''
        Test to obtain a gedcom down a profile
        '''
        file_ged = os.path.join(self.filelocation,
                                "output_test_geni2gedcom.ged")
        if os.path.exists(file_ged): os.remove(file_ged)
        prof = profile.profile(GRANDFATHER_SANDBOX)
        tester = geni2gedcom.geni2gedcom(prof)
        gedcomfile = tester.get_gedcom(file_ged)

        #gedcomfile = gedcom.parse(file_ged)
        counts = 0
        for person in gedcomfile.individuals:
            firstname, lastname = person.name
            if "Avoid Duplicate in Gedcom" in firstname: counts += 1
        assert (counts == 1)

        if os.path.exists(file_ged): os.remove(file_ged)
 def introduce_family(self, init_profile, gedcom_db):
     '''
     Recursive function to introduce the family in the gedcom database
     '''
     logging.info(NUMBER_OF_PROFILES +
                  str(len(self.added_profiles.keys())) + PROCESSING +
                  init_profile.nameLifespan())
     #Let's take first the children
     children = init_profile.children
     prof_id = init_profile.geni_specific_data["id"]
     #For the first profile we check first if the profile has been generated first
     if not isinstance(init_profile, gedcom_profile):
         #Notice that we will only go through this one a single time, as all the others
         #will be generated in the next step
         gedcom_profile.convert_gedcom(init_profile)
         gedcom_db.add_profile(init_profile)
         self.added_profiles[prof_id] = init_profile
     #Firstly we will create the array with all the partners in it and also with their ids in the database
     children_matrix = {}
     children_ids = {}
     for id_partner in init_profile.partner:
         children_matrix[id_partner] = []
         children_ids[id_partner] = []
     for new_id in children:
         #First thing to check is if we have already added the profile, we might
         #be in the situation of double profiles in intermarriage of descendants.
         new_prof = None
         if not (new_id in self.added_profiles.keys()):
             #Ok, if really a new profile, so we create it, we transfor it and
             #also we add to the added profiles
             new_prof = profile.profile(new_id)
             gedcom_profile.convert_gedcom(new_prof)
             gedcom_db.add_profile(new_prof)
             self.added_profiles[new_id] = new_prof
             #And we investigate, obviously!
             self.introduce_family(new_prof, gedcom_db)
         else:
             new_prof = self.added_profiles[new_id]
         #To avoid removing data from the profile we create a temp array using
         #the method list to avoid a linked copy
         temp_parents = list(new_prof.parents)
         #When not having access to a profile in geni, the parents provided are empty
         if prof_id in temp_parents: temp_parents.remove(prof_id)
         #Notice that we might have the situation of a single parent!
         if (len(temp_parents) > 0):
             #Let's find the profile which is already included.
             correct_parent = None
             if temp_parents[0] in children_matrix.keys():
                 correct_parent = temp_parents[0]
             else:
                 correct_parent = temp_parents[1]
             children_matrix[correct_parent].append(new_prof)
             children_ids[correct_parent].append(new_prof.get_id())
     #Only in case there is a partner, we include him/her!
     if (len(init_profile.partner) > 0):
         #Now let's use the partner as well, we may have several partners
         for id_partner in children_matrix.keys():
             prof_partner = None
             #First thing, we need to check the partner is already identified or not
             if (id_partner in self.added_profiles.keys()):
                 #We take the previous so!
                 prof_partner = self.added_profiles[id_partner]
             else:
                 #We get the profile data
                 prof_partner = profile.profile(id_partner)
                 #We add the profile in!
                 gedcom_profile.convert_gedcom(prof_partner)
                 #Now goes to the gedcom
                 gedcom_db.add_profile(prof_partner)
                 #And we mark is already in added profiles
                 self.added_profiles[id_partner] = prof_partner
             #We create here the family
             gedcom_db.add_family(father=init_profile.get_id(),
                                  mother=prof_partner.get_id(),
                                  children=children_ids[id_partner])
 def setUp(self):
     set_token(os.environ['GENI_KEY'])
     profile.s.update_geni_address("https://www.geni.com")
     profile.s.VERIFY_INPUT = "standard"
     self.philip = profile.profile(PHILIPIVg)