def test_user_cant_engage_in_more_than_one_activity_at_once():
    a = Activity('working')
    a.start()
    db.data = [a]

    with pytest.raises(AnotherActivityInProgressError):
        ActivityManager.start_new_activity('sleeping')
 def test_method_stops_tracking_last_activity_properly_when_there_are_more_than_one_activities_in_db(
         self, test_activity,
         test_user_with_multiple_activities_on_multiple_days):
     ActivityManager.stop_tracking_last_activity()
     assert ActivityGateway.fetch_last_activity_started(
     )._id == test_activity._id
     assert ActivityGateway.fetch_last_activity_started().ended
Ejemplo n.º 3
0
def cli(activity):
    """
    Track how much time you spend on different activities throughout the day!
    ACTIVITY is the type of activity you want to start tracking. Examples: working, reading, studying.
    To see a report, use the "timereport" command.
    """

    if activity in RESERVED_ARGUMENTS:
        if activity.lower() == STOP_TRACKING_TIME_ARGUMENT:
            try:
                last_activity = ActivityGateway.fetch_last_activity_started()
                ActivityManager.stop_tracking_last_activity()
                click.echo('Stopped tracking {}'.format(last_activity.category))
            except IndexError:
                click.echo('I was not tracking any activity!')

    else:
        a = ActivityManager.start_tracking_new_activity(activity)
        click.echo('Started tracking "%s".' % a.category)
        click.echo(
            "So far, you've spent {} on {} today!".format(
                format_seconds_returnbed_by_report(
                    TimeSpentInCategoryReport.generate_for_this_category_of_activity(activity, 0)[activity]
                ),
                activity
            )
        )
 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
Ejemplo n.º 5
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.º 6
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_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_user_has_more_than_one_activity_today_but_only_one_is_what_we_want_and_more_activities_on_other_days(
            self, test_user_with_multiple_activities_on_multiple_days, test_db,
            test_activity):
        test_working_activity = ActivityManager.start_new_activity('working')
        ActivityGateway.add_new_activity_to_db(test_working_activity)

        todays_activities = ActivityGateway.activities_today_in_this_category(
            'working')
        assert len(todays_activities) == 1
        assert test_working_activity._id == todays_activities[0]._id
    def test_user_has_more_than_one_activity_today_and_more_on_other_days(
            self, test_user_with_multiple_activities_on_multiple_days, test_db,
            test_activity):
        test_working_activity = ActivityManager.start_new_activity('working')
        ActivityGateway.add_new_activity_to_db(test_working_activity)

        todays_activities = ActivityGateway.activities_today()
        assert len(todays_activities) == 2
        _ids = [a._id for a in todays_activities]
        assert test_activity._id in _ids
        assert test_working_activity._id in _ids
Ejemplo n.º 10
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)
    def test_activity_was_performed_multiple_times_today_and_all_except_one_already_ended(
            self, test_db,
            test_user_with_multiple_activities_of_same_category_done_today,
            test_activity):
        unfinished_activity = ActivityManager.start_new_activity(
            test_activity.category)
        unfinished_activity.started_at = unfinished_activity.started_at.shift(
            seconds=-500)
        ActivityGateway.add_new_activity_to_db(unfinished_activity)

        report = TimeSpentInCategoryReport.generate_for_this_category_of_activity(
            test_activity.category, 0)
        assert report[test_activity.category] == 8500
 def test_exception_thrown_when_no_activity_found_in_db_with_that_id(
         self, test_db):
     a = ActivityManager.start_new_activity('test_activity')
     with pytest.raises(RecordNotFoundError):
         ActivityGateway.fetch_activity(a)
 def test_method_stops_tracking_last_activity_properly_when_theres_only_one_in_db(
         self, test_activity):
     ActivityManager.stop_tracking_last_activity()
     assert ActivityGateway.fetch_last_activity_started(
     )._id == test_activity._id
     assert ActivityGateway.fetch_last_activity_started().ended
Ejemplo n.º 14
0
def test_working_activity():
    return ActivityManager.start_new_activity('working')
Ejemplo n.º 15
0
def test_activity():
    a = ActivityManager.start_new_activity('test_activity')
    ActivityGateway.add_new_activity_to_db(a)
    return a
Ejemplo n.º 16
0
def test_sleeping_activity():
    return ActivityManager.start_new_activity('sleeping')
 def test_start_tracking_the_first_activity(self):
     ActivityManager.start_tracking_new_activity('break')
     assert len(ActivityGateway.activities()) == 1
 def test_starting_to_track_new_activity_puts_the_activity_int_the_db(
         self, test_activity):
     assert len(ActivityGateway.activities()) == 1
     ActivityManager.start_tracking_new_activity('break')
     assert len(ActivityGateway.activities()) == 2
     assert not ActivityGateway.fetch_last_activity_started().ended
 def test_starting_to_track_new_activity_automatically_stops_tracking_the_last_one(
         self, test_activity):
     assert not test_activity.ended
     ActivityManager.start_tracking_new_activity('break')
     assert ActivityGateway.fetch_activity(test_activity).ended
 def test_correct_last_activity_returned_based_on_when_activity_was_created(
         self, test_user_with_multiple_activities_on_multiple_days):
     latest_activity = ActivityManager.start_new_activity('break')
     ActivityGateway.add_new_activity_to_db(latest_activity)
     assert ActivityGateway.fetch_last_activity_started(
     )._id == latest_activity._id