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_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
    def test_some_activities_were_performed_today_some_were_not(self):
        make_activity(0, 3000, 'sleeping')
        make_activity(1, 1000, 'sleeping')
        make_activity(1, 500, 'working')
        make_activity(0, 500, 'working')

        report = TimeSpentInCategoryReport.generate_for_all_categories_of_activity(
            0)
        assert report['sleeping'] == 3000
        assert report['working'] == 500
    def test_correct_activities_returned_when_there_are_activities_on_and_after_specified_day(
            self):
        make_activity(2, 10000, 'working')
        make_activity(3, 20000, 'sleeping')
        make_activity(4, 20000, 'eating')

        assert len(ActivityGateway.activities_in_the_last_n_days(4)) == 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_two_report_shows_correct_information_about_specified_category_of_activity(
            self):
        make_activity(0, 1000, 'working')
        make_activity(1, 2000, 'working')
        make_activity(2, 3000, 'working')
        make_activity(0, 100, 'workin')
        make_activity(-1, 200, 'workin')

        runner = CliRunner()
        result = runner.invoke(cli, ['--activity', 'working', '--days', '2'])

        print(ActivityGateway.activities())

        assert result.exit_code == 0
        assert result.output.count('\n') == 1
        _assert_in_output(result.output,
                          ['working', 'last 2 days', '1 hour', '40 minutes'])

        runner = CliRunner()
        result = runner.invoke(cli, ['--activity', 'workin', '--days', '1'])

        assert result.exit_code == 0
        assert result.output.count('\n') == 1
        _assert_in_output(result.output, ['since yesterday', '5 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
    def test_number_of_days_is_zero(self, test_activity):
        make_activity(1, 10000, 'working')
        make_activity(3, 20000, 'sleeping')

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