Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
parafoxia committed Jul 26, 2021
1 parent f97ae0e commit 532bd11
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
83 changes: 83 additions & 0 deletions tests/test_youtube_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 532bd11

Please sign in to comment.