Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 def test_delete_habit(self):
     connection = connect_to_database("testing.db")
     habit_list = get_all_habits(connection)
     habit_collection = HabitCollection(habit_list)
     self.assertEqual(
         delete_habit(connection, habit_collection, "Call son"), False)
     self.assertEqual(
         delete_habit(connection, habit_collection, "Call dad"), True)
     close_connection_to_database(connection)
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
    def test_get_open_tasks(self):
        # Arrange
        connection = connect_to_database("testing.db")
        habit_list = get_all_habits(connection)
        habit_collection = HabitCollection(habit_list)
        open_tasks_1 = """Workout
Wash dishes
Change bedding
Call mum"""
        open_tasks_2 = """Workout
Wash dishes
Change bedding
Call mum
test_habit_open"""
        open_tasks_3 = """Workout
Wash dishes
Change bedding
test_habit_open"""
        # Assert 1
        self.assertEqual(habit_collection.get_open_tasks(), open_tasks_1)
        # Arrange for 2
        create_new_habit(connection, "test_habit_open", 1,
                         datetime.now() - timedelta(days=2))
        habit_list = get_all_habits(connection)
        habit_collection = HabitCollection(habit_list)
        # Assert for 2
        self.assertEqual(habit_collection.get_open_tasks(), open_tasks_2)
        # Arrange for 3
        call_mum_habit = habit_collection._get_habit_by_name("Call mum")
        call_mum_habit.confirm_task(connection)
        # Assert for 3
        self.assertEqual(habit_collection.get_open_tasks(), open_tasks_3)
        # Close
        open_habit = habit_collection._get_habit_by_name("test_habit_open")
        open_habit.delete_habit_in_database(connection)
        close_connection_to_database(connection)
Ejemplo n.º 7
0
 def test_create_new_habit(self):
     connection = connect_to_database("testing.db")
     self.assertEqual(create_new_habit(connection, "Call mum", 5), False)
     self.assertEqual(create_new_habit(connection, "Call dad", 5), True)
     close_connection_to_database(connection)