def test_save_load_remove_user(): obj = data.Data() userObj = user.User('Testguy', 1234) obj.save_user(userObj) assert_equal(obj.load_user('Testguy', '1234').name, 'Testguy') obj._remove_user('Testguy', '1234') assert_raises(Exception, obj.load_user, 'Testguy', '1234')
def create_user_obj(): yearObj = year.Year(2017) monthObj = month.Month('jan') month2Obj = month.Month('feb') yearObj.add_month(monthObj) yearObj.add_month(month2Obj) obj = user.User('Lucas', 'randomPassword') obj.add_year(yearObj) year2Obj = year.Year(2018) year2Obj.add_month(month2Obj) obj.add_year(year2Obj) return obj
def test_return_user_obj_or_None(): assert_equal(return_user_obj_or_None('NotExistingGuy', 1234, False), None) #I have used try/finally because I want to be absolutely sure that, even if #test would fail, user will still be removed from database to not to cause #further problems. data.Data().save_user(user.User('GuyForMainTest', 1234)) returnValue = return_user_obj_or_None('GuyForMainTest', 1234, False) try: assert_equal(returnValue.password, '1234') except: raise Exception('Test of main file (isNew = False) has failed.') finally: data.Data()._remove_user(returnValue.name, returnValue.password) #Same here. try: assert_equal( return_user_obj_or_None('NowCreatedGuy', 'banana', True).password, 'banana') except: raise Exception('Test of main file (isNew = True) has failed.') finally: data.Data()._remove_user('NowCreatedGuy', 'banana')
def test_init(): obj = user.User('Lucas', 12345) assert_equal(obj.name, 'Lucas') assert_equal(obj.password, '12345')
# would be an error if importing it in the beginning. from yourFinance import configure_menu configure_menu.ConfigureMenu(self.userObj) # I need to load user from file, because configure menu was # working on its own object of the same user and saved it at # the end. self.userObj = data.Data().load_user( self.userObj.name, self.userObj.password) def exit(self): sys.exit() if __name__ == '__main__': userObj = user.User('Lucas', 1234) try: userLoaded = data.Data().load_user(userObj.name, userObj.password) logging.debug('User succesfully loaded.') isLoaded = True # Using general except as I want here the program to continue, regardless # of what caused the error. except: logging.debug('User not loaded.') isLoaded = False if isLoaded: Menu(userLoaded) else: logging.debug('Saving and using created user.') notify_observers(userObj)