def __init__(self, myid): ''' The constructor will also make the call to the web to get the right string ''' input_id = myid #This will allow to intoduce the complete direction of the profile if "https" in myid: input_id = "profile" + myid.split("profile")[1] #Initiating base class geni_calls.__init__(self) self.union_url = self.get_profile_url( input_id) + s.GENI_FAMILY + self.token_string() r = s.geni_request_get(self.union_url) self.data = r.json() #we initialize the lists self.error = False self.union_extracted = False self.parents = [] self.sibligns = [] self.partner = [] self.children = [] self.parent_union = [] self.marriage_union = [] self.marriage_events = [] if not ('error' in self.data): #In this case, we have extracted properly the union data self.union_extracted = True #the nodes include the data of the different affected profiles and unions for keydata in self.data["nodes"].keys(): #is easier to go to the usions, so we filter by unions. if "union" in keydata: #Good... let's obtain the data from the union tmp_union = geni_union(self.data["nodes"][keydata], keydata) #Now we need to filter the parents and children as we should not duplicate if tmp_union.is_profile_child(input_id): #We know is a child... so self.parents = self.parents + tmp_union.parents tmp_union.children.remove(input_id) self.sibligns = self.sibligns + tmp_union.children self.parent_union.append(tmp_union) else: #In this case we know is a marriage union tmp_union.parents.remove(input_id) self.partner = self.partner + tmp_union.parents self.children = self.children + tmp_union.children #We obtain the union from Geni in order to introduce the marriage marriage_union = union(tmp_union.union_id) self.marriage_union.append(tmp_union) if "marriage" in marriage_union.union_data.keys(): self.marriage_events.append( marriage_union.union_data.get( 'marriage', None)) else: self.error = True
def __init__(self, myid): ''' The constructor will also make the call to the web to get the right string ''' #Initiating base class geni_calls.__init__(self) self.union_url = self.get_profile_url( myid) + s.GENI_FAMILY + self.token_string() r = s.geni_request_get(self.union_url) self.data = r.json() #we initialize the lists self.union_extracted = False self.parents = [] self.sibligns = [] self.partner = [] self.children = [] self.parent_union = [] self.marriage_union = [] if not ('error' in self.data): #In this case, we have extracted properly the union data self.union_extracted = True #the nodes include the data of the different affected profiles and unions for keydata in self.data["nodes"].keys(): #is easier to go to the usions, so we filter by unions. if "union" in keydata: #Good... let's obtain the data from the union tmp_union = geni_union(self.data["nodes"][keydata], keydata) #Now we need to filter the parents and children as we should not duplicate if tmp_union.is_profile_child(myid): #We know is a child... so self.parents = self.parents + tmp_union.parents tmp_union.children.remove(myid) self.sibligns = self.sibligns + tmp_union.children self.parent_union.append(tmp_union) else: tmp_union.parents.remove(myid) self.partner = self.partner + tmp_union.parents self.children = self.children + tmp_union.children self.marriage_union.append(tmp_union)
def testgenerateunion(self): ''' This test checks that a union is properly registered in the data model when introduced as input from geni ''' union_test = geni_union(FIXTURES.UNION_EXAMPLE, FIXTURES.UNION_EXAMPLE_ID) assert(union_test.union_id == FIXTURES.UNION_EXAMPLE_ID) #Check of the parent assert(union_test.is_profile_parent(FIXTURES.UNION_EXAMPLE_PARENT)) self.assertFalse(union_test.is_profile_child(FIXTURES.UNION_EXAMPLE_PARENT)) #Check the children self.assertFalse(union_test.is_profile_parent(FIXTURES.UNION_EXAMPLE_CHILD)) assert(union_test.is_profile_child(FIXTURES.UNION_EXAMPLE_CHILD)) #Check random profile self.assertFalse(union_test.is_profile_parent(FIXTURES.UNION_EXAMPLE_NOT_INCLUDED)) self.assertFalse(union_test.is_profile_child(FIXTURES.UNION_EXAMPLE_NOT_INCLUDED)) #Check the number of children assert(len(union_test.children) == FIXTURES.UNION_EXAMPLE_NUMBER_CHILDREN)