def initApp(self):
     '''
     This function initializes the home controller and view
     '''
     self.logger = Logger();
     self.viewObj = GiftExchangeCLI(self.logger, APP_LANGUAGE_FILE);
     self.homeScreenController = HomeScreen(self.logger, self.viewObj);
     self.memberController = MemberController(self.logger, self.viewObj, SAVED_MEMBER_FILE);
     self.hatController = HatController(self.logger, self.viewObj, self.memberController.getRegisteredMembers());
     self.simController = SimController(self.logger, self.viewObj, self.memberController.getRegisteredMembers());
     self.welcomeMessage();
     return;
class TestMemberController(unittest.TestCase):

    memberController = None

    def setUp(self):
        self.langFilePath = dirname(
            os.getcwd()) + "\\Resources\\EnglishMessages.txt"
        self.memberFilePath = dirname(
            os.getcwd()) + "\\Resources\\testMemberList.txt"
        self.memberObjs = [
            FamilyMember("testMemOne", None, Gift("testMemOne")),
            FamilyMember("testMemTwo", None, Gift("testMemTwo"))
        ]
        self.namesInHat = ["vj", "a"]

        f = open(self.memberFilePath, "w")
        f.write("vj\na")
        f.close()

        self.logger = Logger()
        self.viewObj = GiftExchangeCLI(self.logger, self.langFilePath)
        self.homeScreenController = HomeScreen(self.logger, self.viewObj)
        self.memberController = MemberController(self.logger, self.viewObj,
                                                 self.memberFilePath)
        return

    def tearDown(self):
        pass

    def testHandleChoice(self):
        self.assertEqual(self.memberController.handleChoice(5),
                         SYS_STATE_RESULTS)
        return

    def testGenerateAvailableOptions(self):
        self.assertEqual(len(self.memberController.generateAvailableOptions()),
                         4)
        return

    def testShowMembers(self):
        self.assertEqual(self.memberController.handleShowMembers(),
                         SYS_STATE_MEMBER)
        return

    def testCheckPreviousSaves(self):
        self.assertEqual(
            self.memberController.checkPreviousSaves(self.memberFilePath),
            len(self.memberObjs))
        return

    def testGetRegisteredMembers(self):
        self.assertNotEqual(self.memberController.getRegisteredMembers(), None)
예제 #3
0
class TestHatController(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.langFilePath = dirname(
            os.getcwd()) + "\\Resources\\EnglishMessages.txt"
        self.memberFilePath = dirname(
            os.getcwd()) + "\\Resources\\testMemberList.txt"
        self.memberObjs = [
            FamilyMember("testMemOne", None, Gift("testMemOne")),
            FamilyMember("testMemTwo", None, Gift("testMemTwo"))
        ]
        self.namesInHat = ["vj", "a"]

        f = open(self.memberFilePath, "w")
        f.write("vj\na")
        f.close()

        self.logger = Logger()
        self.viewObj = GiftExchangeCLI(self.logger, self.langFilePath)
        self.homeScreenController = HomeScreen(self.logger, self.viewObj)
        self.memberController = MemberController(self.logger, self.viewObj,
                                                 self.memberFilePath)
        self.hatController = HatController(
            self.logger, self.viewObj,
            self.memberController.getRegisteredMembers())

    def testHatDriver(self):
        self.assertEqual(self.hatController.hatDriver(), SYS_STATE_HOME)
        return
예제 #4
0
class TestMagicHat(unittest.TestCase):

    magicHatObj = None
    namesInHat = None
    memberObjs = None

    def setUp(self):
        unittest.TestCase.setUp(self)
        self.langFilePath = dirname(
            os.getcwd()) + "\\Resources\\EnglishMessages.txt"
        self.memberFilePath = dirname(
            os.getcwd()) + "\\Resources\\testMemberList.txt"
        self.memberObjs = [
            FamilyMember("testMemOne", None, Gift("testMemOne")),
            FamilyMember("testMemTwo", None, Gift("testMemTwo"))
        ]
        self.namesInHat = ["vj", "a"]

        f = open(self.memberFilePath, "w")
        f.write("vj\na")
        f.close()

        self.logger = Logger()
        self.viewObj = GiftExchangeCLI(self.logger, self.langFilePath)
        self.memberController = MemberController(self.logger, self.viewObj,
                                                 self.memberFilePath)
        self.magicHatObj = MagicHat(
            self.logger, self.viewObj,
            self.memberController.getRegisteredMembers())

    def testShuffleMemberNames(self):
        memberNames, memberObjs = self.magicHatObj.shuffleMemberNames()
        self.assertNotEqual(memberNames, None)
        self.assertNotEqual(memberObjs, None)
        self.assertEqual(len(memberNames), 2)
        self.assertEqual(len(memberObjs), 2)
        pass

    def testPickFromHat(self):
        idx = self.magicHatObj.pickFromHat(self.namesInHat)
        self.assertLessEqual(idx, len(self.namesInHat))
        return

    def testPickAndValidate(self):
        res, name = self.magicHatObj.pickAndValidate(self.namesInHat[1],
                                                     self.memberObjs[0])
        self.assertEqual(res, True)
        self.assertEqual(name, 'a')
        return

    def testDistributeGifts(self):
        resDistribution = self.magicHatObj.distributeGifts(
            self.namesInHat, self.memberObjs)
        self.assertEqual(len(resDistribution), 2)
        return
    def setUp(self):
        self.langFilePath = dirname(
            os.getcwd()) + "\\Resources\\EnglishMessages.txt"
        self.memberFilePath = dirname(
            os.getcwd()) + "\\Resources\\testMemberList.txt"
        self.memberObjs = [
            FamilyMember("testMemOne", None, Gift("testMemOne")),
            FamilyMember("testMemTwo", None, Gift("testMemTwo"))
        ]
        self.namesInHat = ["vj", "a"]

        f = open(self.memberFilePath, "w")
        f.write("vj\na")
        f.close()

        self.logger = Logger()
        self.viewObj = GiftExchangeCLI(self.logger, self.langFilePath)
        self.homeScreenController = HomeScreen(self.logger, self.viewObj)
        self.memberController = MemberController(self.logger, self.viewObj,
                                                 self.memberFilePath)
        return
예제 #6
0
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.langFilePath = dirname(
            os.getcwd()) + "\\Resources\\EnglishMessages.txt"
        self.memberFilePath = dirname(
            os.getcwd()) + "\\Resources\\testMemberList.txt"
        self.memberObjs = [
            FamilyMember("testMemOne", None, Gift("testMemOne")),
            FamilyMember("testMemTwo", None, Gift("testMemTwo"))
        ]
        self.namesInHat = ["vj", "a"]

        f = open(self.memberFilePath, "w")
        f.write("vj\na")
        f.close()

        self.logger = Logger()
        self.viewObj = GiftExchangeCLI(self.logger, self.langFilePath)
        self.memberController = MemberController(self.logger, self.viewObj,
                                                 self.memberFilePath)
        self.magicHatObj = MagicHat(
            self.logger, self.viewObj,
            self.memberController.getRegisteredMembers())
class GiftExchange(object):
    '''
    Automation of gift exchange process for Mr. Raccoon
    '''
    
    ''' Controller and Other Class Objects '''
    homeScreenController = None;
    memberController = None;
    hatController = None;
    viewObj = None;
    logger = None;
    
    ''' Internal Processing Variables '''
    state = None;
    
    def __init__(self):
        '''
        Default Constructor
        '''
        self.state = SYS_STATE_HOME;
        self.appDriver();
        
    def appDriver(self):
        '''
        The driver that runs the application
        '''
        self.initApp();
        while(True):
            if(self.state == SYS_STATE_HOME):
                self.state = self.processStateHome();
            if(self.state == SYS_STATE_MEMBER):
                self.state = self.processStateMember();
            if(self.state == SYS_STATE_RESULTS):
                self.state = self.procesStateResults();
            if(self.state == SYS_STATE_SIMULATION):
                self.state = self.processStateSimulation();
            
    def welcomeMessage(self):
        '''
        A welcome message whenever application starts
        '''
        print("*********************************************");
        self.viewObj.displayGeneralMessage(MSG_WELLCOME_MESSAGE);
        return;
    
    def processStateHome(self):
        '''
        Initiate controller for home screen
        return: The new state of system
        '''
        oprResult = self.homeScreenController.homeScreenDriver();
        if(oprResult == SYS_STATE_EXIT):
            self.viewObj.displayGeneralMessage(MSG_GOOD_BYE);
            exit();
            
        return oprResult;
    
    def processStateMember(self):
        '''
        Initiate controller for member screen
        return: The new state of system
        '''
        oprResult = self.memberController.memberDriver();
        return oprResult;
        
    def procesStateResults(self):
        '''
        Initiate controller for results calculation
        return: The new state of system
        '''
        oprResult = self.hatController.hatDriver();
        return oprResult;
    
    def processStateSimulation(self):
        oprResult = self.simController.simDriver();
        return oprResult;
    
    def initApp(self):
        '''
        This function initializes the home controller and view
        '''
        self.logger = Logger();
        self.viewObj = GiftExchangeCLI(self.logger, APP_LANGUAGE_FILE);
        self.homeScreenController = HomeScreen(self.logger, self.viewObj);
        self.memberController = MemberController(self.logger, self.viewObj, SAVED_MEMBER_FILE);
        self.hatController = HatController(self.logger, self.viewObj, self.memberController.getRegisteredMembers());
        self.simController = SimController(self.logger, self.viewObj, self.memberController.getRegisteredMembers());
        self.welcomeMessage();
        return;