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
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 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_last_activity_ends_no_new_activity_is_created( self, test_activity): assert len(ActivityGateway.activities()) == 1 assert test_activity.ended is False runner = CliRunner() result = runner.invoke(cli, ['stop']) assert result.exit_code == 0 assert result.output.count('\n') == 1 _assert_in_output(result.output, ['Stopped', test_activity.category]) assert ActivityGateway.fetch_last_activity_started().ended is True 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_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
def test_error_thrown_for_last_activity_started_when_theres_no_activities_in_db( self): with pytest.raises(IndexError): ActivityGateway.fetch_last_activity_started()
def test_correct_last_activity_returned_when_theres_only_one_activity_in_db( self, test_activity): assert ActivityGateway.fetch_last_activity_started( )._id == test_activity._id
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