Esempio n. 1
0
def add_spouse(from_member, to_member_name, gender, family_tree):
    to_member = member_model.Member(to_member_name, gender)
    from_member.set_spouse(to_member)
    to_member.set_spouse(from_member)
    updated_family_tree = family_tree_service.add_member(
        to_member, family_tree)
    success_msg = output_messages['SPOUSE_ADDITION_SUCCEEDED']
    return {'updated_family_tree': updated_family_tree, 'msg': success_msg}
Esempio n. 2
0
 def test_family_tree_update(self):
     command = 'ADD_CHILD Anga Chit Male'
     new_member = member_model.Member('Anga', member_gender['FEMALE'])
     members_obj = {'Anga': new_member}
     family_tree_obj = family_tree_model.FamilyTree(members_obj)
     family_tree_obj.set_head_member(new_member)
     result = family_tree_service.update_family_tree(
         family_tree_obj, command)
     self.assertEqual(result['success_msg'],
                      output_messages['CHILD_ADDITION_SUCCEEDED'])
     newly_created_child = result['updated_family_tree'].members['Chit']
     self.assertEqual(newly_created_child.get_parent(), new_member)
Esempio n. 3
0
def initialise_family_tree():
    new_member = member.Member('Anga', member_gender['FEMALE'])
    members = {'Anga': new_member}
    family_tree_obj = family_tree.FamilyTree(members)
    logging.debug('Initialised family tree')

    family_tree_obj.set_head_member(new_member)
    test_data_file = open("initial_input_commands.txt", "r")
    data_file_lines = test_data_file.readlines()

    logging.debug('Starting File handling for set up commands')
    for line in data_file_lines:
        updated_info = family_tree_service.update_family_tree(
            family_tree_obj, line.rstrip())

        family_tree_obj = updated_info['updated_family_tree']

    test_data_file.close()
    logging.debug('Finished File handling for set up commands')
    return family_tree_obj
Esempio n. 4
0
def add_child(from_member, to_member_name, gender, family_tree):
    if from_member.gender == member_gender_constant['MALE']:
        return {
            'success_msg': output_messages['CHILD_ADDITION_FAILED'],
            'updated_family_tree': family_tree,
        }
    to_member = member_model.Member(to_member_name, gender)
    from_member.set_children(to_member)
    from_member_spouse = from_member.get_spouse()
    if from_member_spouse:
        from_member_spouse.set_children(to_member)
    to_member_parent = to_member.get_parent()
    if not to_member_parent:
        to_member.set_parent(from_member)
    updated_family_tree = family_tree_service.add_member(
        to_member, family_tree)
    success_msg = output_messages['CHILD_ADDITION_SUCCEEDED']
    return {
        'updated_family_tree': updated_family_tree,
        'success_msg': success_msg
    }
Esempio n. 5
0
def create_test_member(name, gender):
    return member.Member(name, gender)
Esempio n. 6
0
 def test_member_init(self):
     new_member = member.Member('King Shan', member_gender['MALE'])
     self.assertEqual(new_member.gender, member_gender['MALE'])
     self.assertEqual(new_member.name, 'King Shan')
Esempio n. 7
0
from src.action import member as member_action
from src.models import member as member_model, family_tree as family_tree_model
from src.constants import valid_actions, member_gender, output_messages
import unittest

child_action = valid_actions['ADD_CHILD']
get_relationship_action = valid_actions['GET_RELATIONSHIP']

first_member = member_model.Member('Anga', member_gender['FEMALE'])
members_obj = {'Anga': first_member}

family_tree_obj = family_tree_model.FamilyTree(members_obj)
family_tree_obj.set_head_member(first_member)


class TestMemberAction(unittest.TestCase):
    def test_add_child_action_success(self):
        result = member_action.execute(child_action, family_tree_obj,
                                       ['Anga', 'Chit', 'Male'])
        self.assertEqual(result['success_msg'],
                         output_messages['CHILD_ADDITION_SUCCEEDED'])
        newly_added_member = result['updated_family_tree'].members['Chit']
        parent = newly_added_member.get_parent()
        self.assertEqual(parent, first_member)

    def test_get_relationship_action_success(self):
        member_action.execute(child_action, family_tree_obj,
                              ['Anga', 'Chit', 'Male'])
        result = member_action.execute(get_relationship_action,
                                       family_tree_obj, ['Chit', 'Mother'])
        self.assertEqual(len(result['members_list']), 1)
Esempio n. 8
0
 def test_family_tree_init(self):
     member = member_model.Member('Sherlock', member_gender['MALE'])
     members = {'Sherlock': member}
     family_tree = family_tree_model.FamilyTree(members)
     self.assertEqual(family_tree.members['Sherlock'], member)
Esempio n. 9
0
 def test_family_tree_head(self):
     member = member_model.Member('Sherlock', member_gender['MALE'])
     family_tree = family_tree_model.FamilyTree()
     family_tree.set_head_member(member)
     self.assertEqual(family_tree.get_head_member(), member)