def test_get_habit_by_name(self): test_habit_1 = Habit("test_habit_create", 4, datetime.now()) test_habit_2 = Habit("Call mum", 4, datetime.now()) habit_collection = HabitCollection([test_habit_1, test_habit_2]) self.assertEqual( habit_collection._get_habit_by_name("test_habit_create"), test_habit_1) self.assertEqual(habit_collection._get_habit_by_name("Call mum"), test_habit_2) self.assertEqual(habit_collection._get_habit_by_name("Wash car"), False)
def test_habit_in_habit_collection(self): new_habit = Habit("number_one", 1, datetime.now()) new_habit_2 = Habit("number_two", 2, datetime.now()) habit_collection = HabitCollection([new_habit, new_habit_2]) self.assertEqual( habit_in_habit_collection("Call son", habit_collection), False) self.assertEqual( habit_in_habit_collection("number_one", habit_collection), new_habit) self.assertEqual( habit_in_habit_collection("number_two", habit_collection), new_habit_2)
def test_get_current_streak(self): connection = connect_to_database("testing.db") test_habit_1 = Habit("Workout", 4, datetime.now()) test_habit_2 = Habit("Wash dishes", 4, datetime.now()) test_habit_3 = Habit("test_habit_3", 4, datetime.now()) self.assertEqual(test_habit_1.get_overall_longest_streak(connection), 9) self.assertEqual(test_habit_2.get_overall_longest_streak(connection), 13) self.assertEqual(test_habit_3.get_overall_longest_streak(connection), 0) close_connection_to_database(connection)
def test_delete_habit_in_database(self): connection = connect_to_database("testing.db") test_habit_1 = Habit("test_habit_delete", 4, datetime.now()) test_habit_1.create_habit_in_database(connection) test_habit_2 = Habit("Call sister", 4, datetime.now()) # Assert self.assertEqual(test_habit_1.delete_habit_in_database(connection), True) self.assertEqual(test_habit_2.delete_habit_in_database(connection), False) close_connection_to_database(connection)
def test_create_habit_in_database(self): connection = connect_to_database("testing.db") test_habit_1 = Habit("test_habit_create", 4, datetime.now()) test_habit_2 = Habit("Call mum", 4, datetime.now()) self.assertEqual(test_habit_1.create_habit_in_database(connection), True) self.assertEqual(test_habit_2.create_habit_in_database(connection), False) # Cleanup test_habit_1.delete_habit_in_database(connection) close_connection_to_database(connection)
def test_confirm_task(self): connection = connect_to_database("testing.db") # First test case = new habit # Create values test_habit_1 = Habit("test_habit_ct", 4, datetime.now()) test_habit_1.create_habit_in_database(connection) # Test first_value = test_habit_1.get_current_streak(connection) test_habit_1.confirm_task(connection) self.assertEqual(test_habit_1.get_current_streak(connection), first_value + 1) test_habit_1.confirm_task(connection) self.assertEqual(test_habit_1.get_current_streak(connection), first_value + 2) # Second test case = existing habit test_habit_2 = Habit("Learn", 1, datetime.now()) first_value = test_habit_2.get_current_streak(connection) test_habit_2.confirm_task(connection) self.assertEqual(test_habit_2.get_current_streak(connection), first_value + 1) test_habit_2.confirm_task(connection) self.assertEqual(test_habit_2.get_current_streak(connection), first_value + 2) # Cleanup test_habit_1.delete_habit_in_database(connection) close_connection_to_database(connection)
def create_habit_examples(connection, start_datetime): # Prepare examples habit_1 = Habit("Workout", 3, start_datetime) habit_2 = Habit("Learn", 1, start_datetime) habit_3 = Habit("Wash dishes", 2, start_datetime) habit_4 = Habit("Change bedding", 7, start_datetime) habit_5 = Habit("Call mum", 4, start_datetime) habit_1.create_habit_in_database(connection) habit_2.create_habit_in_database(connection) habit_3.create_habit_in_database(connection) habit_4.create_habit_in_database(connection) habit_5.create_habit_in_database(connection)