Esempio n. 1
0
 def test_get_habits_with_period(self):
     # Arrange
     connection = connect_to_database("testing.db")
     habit_list = get_all_habits(connection)
     habit_collection = HabitCollection(habit_list)
     # Assert
     self.assertEqual(habit_collection.get_habits_with_period(3), "Workout")
     self.assertEqual(habit_collection.get_habits_with_period(1), "Learn")
 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)
Esempio n. 3
0
 def test_get_current_longest_streak(self):
     # Arrange
     connection = connect_to_database("testing.db")
     habit_list = get_all_habits(connection)
     habit_collection = HabitCollection(habit_list)
     # Assert
     habit_name, habit_streak = habit_collection.get_current_longest_streak(
         connection)
     self.assertEqual(habit_name, "Learn")
     self.assertEqual(habit_streak, 29)
def prepare():
    # Prepare connection and set startup parameters
    db_name = "testing.db"
    connection = prepare_connection(db_name)
    start_datetime = datetime.strptime("2021-01-01 12:00:00.76",
                                       "%Y-%m-%d %H:%M:%S.%f")
    end_datetime = start_datetime + timedelta(
        days=28)  # Only create example data for 4 weeks
    # Create data examples
    create_habit_examples(connection, start_datetime)
    habit_collection = utils.get_all_habits(connection)
    create_habit_entries(connection, habit_collection, end_datetime)
Esempio n. 5
0
    def test_get_tracked_habits(self):
        # Arrange
        connection = connect_to_database("testing.db")
        habit_list = get_all_habits(connection)
        habit_collection = HabitCollection(habit_list)
        active_habits = """Workout
Learn
Wash dishes
Change bedding
Call mum"""
        # Assert
        self.assertEqual(habit_collection.get_tracked_habits(), active_habits)
Esempio n. 6
0
 def test_get_longest_streak_for_habit(self):
     # Arrange
     connection = connect_to_database("testing.db")
     habit_list = get_all_habits(connection)
     habit_collection = HabitCollection(habit_list)
     # Assert
     self.assertEqual(
         habit_collection.get_longest_streak_for_habit(
             "Workout", connection), 9)
     self.assertEqual(
         habit_collection.get_longest_streak_for_habit(
             "Wash dishes", connection), 13)
Esempio n. 7
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)