From 532bd119b02da5ce89e93382dbbc74e1755f6ef8 Mon Sep 17 00:00:00 2001 From: Ethan Henderson Date: Mon, 26 Jul 2021 02:16:55 +0100 Subject: [PATCH] Updated tests --- noxfile.py | 2 +- tests/test_youtube_analytics.py | 83 +++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index f233009..2f284e2 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,7 +1,7 @@ import nox -@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"], reuse_venv=True) +@nox.session(python=["3.6", "3.7", "3.8", "3.9"], reuse_venv=True) def tests(session: nox.Session) -> None: session.run("pip", "install", "-r", "requirements-test.txt") session.run("pytest", "-s", "--verbose", "--log-level=INFO") diff --git a/tests/test_youtube_analytics.py b/tests/test_youtube_analytics.py index 719c604..e5e7e60 100644 --- a/tests/test_youtube_analytics.py +++ b/tests/test_youtube_analytics.py @@ -924,3 +924,86 @@ def test_report_type_ad_performance(client): assert report.type == "Ad performance" except (InvalidRequest, HTTPError) as exc: assert False, f"{inspect.stack()[0][3]} report raised: {exc}" + + +# Factory reports + + +def test_factory_report_daily_analytics_rows_correct(client): + report = client.daily_analytics() + assert report.type == "Time-based activity" + assert report.shape[0] == 28 + report = client.daily_analytics(last=10) + assert report.type == "Time-based activity" + assert report.shape[0] == 10 + + +def test_factory_report_daily_analytics_start_date(client): + report = client.daily_analytics(since=dt.date(2021, 1, 1)) + assert report.type == "Time-based activity" + assert report.data["rows"][0][0] == "2021-01-01" + + +def test_factory_report_daily_analytics_metrics(client): + report = client.daily_analytics(metrics=("views", "likes", "comments")) + assert report.type == "Time-based activity" + assert report.shape[1] == 4 + + +def test_factory_report_monthly_analytics_rows_correct(client): + report = client.monthly_analytics() + assert report.type == "Time-based activity" + assert report.shape[0] == 3 + report = client.monthly_analytics(last=10) + assert report.type == "Time-based activity" + assert report.shape[0] == 10 + + +def test_factory_report_monthly_analytics_start_date(client): + report = client.monthly_analytics(since=dt.date(2021, 1, 1)) + assert report.type == "Time-based activity" + assert report.data["rows"][0][0] == "2021-01" + report = client.monthly_analytics(since=dt.date(2020, 6, 12)) + assert report.type == "Time-based activity" + assert report.data["rows"][0][0] == "2020-06" + + +def test_factory_report_monthly_analytics_end_date(client): + report = client.monthly_analytics(since=dt.date(2021, 1, 1)) + assert report.type == "Time-based activity" + last_month = dt.date.today() - dt.timedelta(days=30) + assert report.data["rows"][-1][0] == dt.date( + last_month.year, last_month.month, 1 + ).strftime("%Y-%m") + + +def test_factory_report_monthly_analytics_metrics(client): + report = client.monthly_analytics(metrics=("views", "likes", "comments")) + assert report.type == "Time-based activity" + assert report.shape[1] == 4 + + +def test_factory_report_regional_analytics_metrics_sorted(client): + report = client.regional_analytics() + assert report.type == "Geography-based activity" + arr = [r[1] for r in report.data["rows"]] + assert arr == sorted(arr, reverse=True) + + +def test_factory_report_regional_analytics_metrics(client): + report = client.regional_analytics(metrics=("views", "likes", "comments")) + assert report.type == "Geography-based activity" + assert report.shape[1] == 4 + + +def test_factory_report_top_videos_metrics_sorted(client): + report = client.top_videos() + assert report.type == "Top videos by region" + arr = [r[1] for r in report.data["rows"]] + assert arr == sorted(arr, reverse=True) + + +def test_factory_report_top_videos_metrics(client): + report = client.top_videos(metrics=("views", "likes", "comments")) + assert report.type == "Top videos by region" + assert report.shape[1] == 4