def test_number_of_days_is_zero(self, test_activity): make_activity(1, 10000, 'working') make_activity(3, 20000, 'working') assert len( ActivityGateway.activities_in_last_n_days_in_this_category( 0, test_activity.category)) == 1
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_correct_activities_returned_when_there_are_activities_on_and_after_specified_day( self): make_activity(2, 10000, 'working') make_activity(3, 20000, 'working') make_activity(4, 20000, 'working') assert len( ActivityGateway.activities_in_last_n_days_in_this_category( 4, 'working')) == 3
def test_only_one_activity_returned_when_the_rest_the_activities_with_such_category_are_on_previous_days( self): make_activity(2, 10000, 'working') make_activity(3, 20000, 'working') make_activity(4, 20000, 'working') assert len( ActivityGateway.activities_in_last_n_days_in_this_category( 2, 'working')) == 1
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 generate_for_this_category_of_activity(cls, category: str, days: int) -> Dict[str, int]: total_activity_length = 0 if days == 0: for activity in ActivityGateway.activities_today_in_this_category( category): total_activity_length += activity.length else: for activity in ActivityGateway.activities_in_last_n_days_in_this_category( days, category): total_activity_length += activity.length return {category: total_activity_length}