def stop_tracking_last_activity(cls) -> None:
     try:
         a = ActivityGateway.fetch_last_activity_started()
         a.end()
         ActivityGateway.update_activity_in_db(a)
     except IndexError:
         pass
 def test_activity_was_performed_once_today_and_hasnt_ended(
         self, test_activity):
     test_activity.started_at = test_activity.started_at.shift(
         seconds=-1000)
     ActivityGateway.update_activity_in_db(test_activity)
     report = TimeSpentInCategoryReport.generate_for_all_categories_of_activity(
         0)
     assert report[test_activity.category] == 1000
 def test_after_activity_ends_its_status_changes_and_end_time_is_recorded(
         self, test_activity):
     test_activity.end()
     ActivityGateway.update_activity_in_db(test_activity)
     assert test_activity.ended_at is not None
     assert test_activity.status != test_activity.STARTED
     assert ActivityGateway.fetch_activity(
         test_activity).status == test_activity.ENDED
    def test_one_acitivity_returned_when_theres_only_one_with_such_category(
            self, test_activity):
        test_activity.started_at = test_activity.started_at.shift(days=-3)
        ActivityGateway.update_activity_in_db(test_activity)

        assert len(
            ActivityGateway.activities_in_last_n_days_in_this_category(
                3, test_activity.category)) == 1
 def test_total_activity_length_is_correct_activity_was_performed_once_today_and_hasnt_ended(
         self, test_db, test_activity):
     test_activity.started_at = test_activity.started_at.shift(
         seconds=-1000)
     ActivityGateway.update_activity_in_db(test_activity)
     report = TimeSpentInCategoryReport.generate_for_this_category_of_activity(
         test_activity.category, 0)
     assert report[test_activity.category] == 1000
    def test_activity_updated_is_persisted(self, test_activity):
        a = ActivityGateway.fetch_activity(test_activity)
        assert a.ended is False

        test_activity.end()
        ActivityGateway.update_activity_in_db(test_activity)

        a = ActivityGateway.fetch_activity(test_activity)
        assert a.ended is True
    def test_new_activity_turns_up_in_search_results(self, test_db,
                                                     test_activity):
        assert len(ActivityGateway.activities()) == 1
        test_activity.end()
        ActivityGateway.update_activity_in_db(test_activity)

        a = ActivityManager.start_new_activity('test2_activity')
        ActivityGateway.add_new_activity_to_db(a)
        assert len(ActivityGateway.activities()) == 2
    def test_no_activities_returned_when_there_are_no_activitie_on_or_after_specificed_day(
            self, test_activity):
        test_activity.started_at = test_activity.started_at.shift(days=-4)
        test_activity.end()
        ActivityGateway.update_activity_in_db(test_activity)

        assert len(
            ActivityGateway.activities_in_last_n_days_in_this_category(
                3, test_activity.category)) == 0
 def test_no_activities_returned_when_activitie_with_such_category_dont_exist_at_all(
         self, test_activity):
     test_activity.started_at = test_activity.started_at.shift(days=-2)
     test_activity.end()
     ActivityGateway.update_activity_in_db(test_activity)
     ActivityManager.start_new_activity('sleeping')
     assert len(
         ActivityGateway.activities_in_last_n_days_in_this_category(
             2, 'working')) == 0
    def test_multiple_activities_that_started_today_and_have_ended(
            self, test_activity):
        test_activity.started_at = test_activity.started_at.shift(
            seconds=-1000)
        ActivityGateway.update_activity_in_db(test_activity)
        make_activity(0, 200, 'sleeping')

        report = TimeSpentInCategoryReport.generate_for_all_categories_of_activity(
            0)
        assert report[test_activity.category] == 1000
        assert report['sleeping'] == 200
Ejemplo n.º 11
0
def make_activity(started_days_ago, length_in_seconds, category):
    if started_days_ago == 0:
        seconds_to_shift = length_in_seconds
    else:
        seconds_to_shift = 0

    act1 = ActivityManager.start_tracking_new_activity(category)
    act1.started_at = act1.started_at.shift(days=-started_days_ago,
                                            seconds=-seconds_to_shift)
    act1.end()
    act1.ended_at = act1.started_at.shift(seconds=length_in_seconds)
    ActivityGateway.update_activity_in_db(act1)
Ejemplo n.º 12
0
    def test_one_day_report_shown_when_days_argument_is_not_given_and_activity_is_specified(
            self, test_activity):
        test_activity.end()
        test_activity.ended_at = test_activity.started_at.shift(seconds=120)
        ActivityGateway.update_activity_in_db(test_activity)

        runner = CliRunner()
        result = runner.invoke(cli, ['--activity', 'test_activity'])

        assert result.exit_code == 0
        assert result.output.count('\n') == 1
        _assert_in_output(result.output,
                          ['test_activity', 'today', '2 minutes'])
    def test_activity_performed_multiple_times_on_different_days(
            self, test_activity):
        test_activity.started_at = test_activity.started_at.shift(
            seconds=-2000)
        test_activity.end()
        ActivityGateway.update_activity_in_db(test_activity)

        make_activity(1, 3000, test_activity.category)
        make_activity(2, 1000, test_activity.category)
        make_activity(3, 500, test_activity.category)

        report = TimeSpentInCategoryReport.generate_for_this_category_of_activity(
            test_activity.category, 2)
        assert report[test_activity.category] == 6000
Ejemplo n.º 14
0
def test_user_with_multiple_activities_on_multiple_days(test_activity):
    test_activity.end()
    ActivityGateway.update_activity_in_db(test_activity)

    test_sleeping_activity = ActivityManager.start_new_activity('sleeping')
    test_sleeping_activity.started_at = test_sleeping_activity.started_at.shift(
        days=-1)
    test_sleeping_activity.end()
    ActivityGateway.add_new_activity_to_db(test_sleeping_activity)

    test_working_activity = ActivityManager.start_new_activity('working')
    test_working_activity.started_at = test_working_activity.started_at.shift(
        days=-2)
    test_working_activity.end()
    ActivityGateway.add_new_activity_to_db(test_working_activity)
Ejemplo n.º 15
0
def test_user_with_multiple_activities_of_same_category_done_today(
        test_activity):
    test_activity.end()
    test_activity.ended_at = test_activity.started_at.shift(seconds=2000)
    ActivityGateway.update_activity_in_db(test_activity)

    second_activity = ActivityManager.start_new_activity(
        test_activity.category)
    second_activity.end()
    second_activity.ended_at = second_activity.started_at.shift(seconds=3000)
    ActivityGateway.add_new_activity_to_db(second_activity)

    third_activity = ActivityManager.start_new_activity(test_activity.category)
    third_activity.end()
    third_activity.ended_at = third_activity.started_at.shift(seconds=3000)
    ActivityGateway.add_new_activity_to_db(third_activity)
    def test_one_acitivity_returned_when_theres_only_one_activity_in_the_given_range(
            self, test_activity):
        test_activity.started_at = test_activity.started_at.shift(days=-3)
        ActivityGateway.update_activity_in_db(test_activity)

        assert len(ActivityGateway.activities_in_the_last_n_days(3)) == 1