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_add_remove_year(): obj = create_user_obj() assert_equal(len(obj.yearDict), 2) assert_equal(obj.yearDict[2017].number, 2017) assert_equal(len(obj.yearDict[2017].monthDict), 2) yearObj = year.Year(2018) obj.remove_year(yearObj) assert_equal(len(obj.yearDict), 1) assert_raises(Exception, obj.remove_year, 2017)
def analyze_chosen_month(self): """Asks which month to check and runs analyze function with it.""" yearNumber = year.Year().number monthName = month.Month().name try: monthObj = self.userObj.yearDict[yearNumber].monthDict[monthName] except KeyError: input('No such data in database. Hit enter. ') return self.analyze_month(yearNumber, monthObj)
def add_month(self): """Lets user to input and save data for certain month.""" # User inputs about year number and later about month name, # stash names and values are being asked internally, while # creating certain objects. yearObj = year.Year() if yearObj.number in self.userObj.yearDict: yearObj = self.userObj.yearDict[yearObj.number] monthObj = month.Month() # Leaves function if user decided to not to override month. if yearObj.add_month(monthObj) == False: return for stashName in self.userObj.stashNames: yearObj.monthDict[monthObj.name].add_stash(stash.Stash(stashName)) self.userObj.add_year(yearObj) notify_observers(self.userObj) print('\nData for year {} saved:'.format(yearObj.number)) print(yearObj.monthDict[monthObj.name].show_month()) input('\nHit enter to go back to menu.')