Skip to content

Commit

Permalink
Add snapshot testing (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Jul 25, 2023
1 parent 2f803b7 commit 7462867
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 88 deletions.
44 changes: 34 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pytest-cov = "4.1.0"
ruff = "0.0.280"
safety = "2.4.0b1"
yamllint = "1.32.0"
syrupy = "^4.0.8"

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/joostlek/python-youtube/issues"
Expand Down Expand Up @@ -81,7 +82,7 @@ disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
no_implicit_reexport = true
#no_implicit_reexport = true
strict_optional = true
warn_incomplete_stub = true
warn_no_return = true
Expand Down
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_video.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_fetch_video
YouTubeVideo(video_id='Ks-_Mh1QhMc', nullable_snippet=YouTubeVideoSnippet(published_at=datetime.datetime(2012, 10, 1, 15, 27, 35, tzinfo=TzInfo(UTC)), channel_id='UCAuUUnT6oDeKwE6v1NGQxug', title='Your body language may shape who you are | Amy Cuddy', description='Body language affects how others see us, but it may also change how we see ourselves. Social psychologist Amy Cuddy argues that "power posing" -- standing in a posture of confidence, even when we don\'t feel confident -- can boost feelings of confidence, and might have an impact on our chances for success. (Note: Some of the findings presented in this talk have been referenced in an ongoing debate among social scientists about robustness and reproducibility. Read Amy Cuddy\'s response here: http://ideas.ted.com/inside-the-debate-about-power-posing-a-q-a-with-amy-cuddy/)\n\nGet TED Talks recommended just for you! Learn more at https://www.ted.com/signup.\n\nThe TED Talks channel features the best talks and performances from the TED Conference, where the world\'s leading thinkers and doers give the talk of their lives in 18 minutes (or less). Look for talks on Technology, Entertainment and Design -- plus science, business, global issues, the arts and more.\n\nFollow TED on Twitter: http://www.twitter.com/TEDTalks\nLike TED on Facebook: https://www.facebook.com/TED\n\nSubscribe to our channel: https://www.youtube.com/TED', thumbnails=YouTubeVideoThumbnails(default=YouTubeThumbnail(url='https://i.ytimg.com/vi/Ks-_Mh1QhMc/default.jpg', width=120, height=90), medium=YouTubeThumbnail(url='https://i.ytimg.com/vi/Ks-_Mh1QhMc/mqdefault.jpg', width=320, height=180), high=YouTubeThumbnail(url='https://i.ytimg.com/vi/Ks-_Mh1QhMc/hqdefault.jpg', width=480, height=360), standard=YouTubeThumbnail(url='https://i.ytimg.com/vi/Ks-_Mh1QhMc/sddefault.jpg', width=640, height=480), maxres=YouTubeThumbnail(url='https://i.ytimg.com/vi/Ks-_Mh1QhMc/maxresdefault.jpg', width=1280, height=720)), channel_title='TED', tags=['Amy Cuddy', 'TED', 'TEDTalk', 'TEDTalks', 'TED Talk', 'TED Talks', 'TEDGlobal', 'brain', 'business', 'psychology', 'self', 'success'], live_broadcast_content=<LiveBroadcastContent.NONE: 'none'>, default_language='en', default_audio_language='en'))
# ---
82 changes: 5 additions & 77 deletions tests/test_video.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Tests for the YouTube client."""
import json
from datetime import datetime, timezone

import aiohttp
import pytest
from aiohttp.web_request import BaseRequest
from aresponses import Response, ResponsesMockServer
from syrupy import SnapshotAssertion

from youtubeaio.helper import first
from youtubeaio.models import YouTubeVideoThumbnails
Expand All @@ -19,6 +19,7 @@

async def test_fetch_video(
aresponses: ResponsesMockServer,
snapshot: SnapshotAssertion,
) -> None:
"""Test retrieving a video."""
aresponses.add(
Expand All @@ -28,85 +29,12 @@ async def test_fetch_video(
aresponses.Response(
status=200,
headers={"Content-Type": "application/json"},
text=load_fixture("video_response_snippet.json"),
text=json.dumps(construct_fixture("video", ["snippet"], 1)),
),
)
async with aiohttp.ClientSession() as session:
youtube = YouTube(session=session)
async with aiohttp.ClientSession() as session, YouTube(session=session) as youtube:
video = await youtube.get_video(video_id="Ks-_Mh1QhMc")
assert video
assert video.snippet
assert video.snippet.published_at == datetime(
2012,
10,
1,
15,
27,
35,
tzinfo=timezone.utc,
)
assert video.snippet.channel_id == "UCAuUUnT6oDeKwE6v1NGQxug"
assert (
video.snippet.title
== "Your body language may shape who you are | Amy Cuddy"
)
assert (
video.snippet.description
== "Body language affects how others see us, but it may also change how "
'we see ourselves. Social psychologist Amy Cuddy argues that "power '
"posing\" -- standing in a posture of confidence, even when we don't "
"feel confident -- can boost feelings of confidence, and might have an "
"impact on our chances for success. (Note: Some of the findings "
"presented in this talk have been referenced in an ongoing debate "
"among social scientists about robustness and reproducibility. Read "
"Amy Cuddy's response here: "
"http://ideas.ted.com/inside-the-debate-about-power-posing-a-q-a-with"
"-amy-cuddy/)\n\nGet TED Talks recommended just for you! Learn more at "
"https://www.ted.com/signup.\n\nThe TED Talks channel features the "
"best talks and performances from the TED Conference, where the "
"world's leading thinkers and doers give the talk of their lives in 18 "
"minutes (or less). Look for talks on Technology, Entertainment and "
"Design -- plus science, business, global issues, the arts and "
"more.\n\nFollow TED on Twitter: http://www.twitter.com/TEDTalks\nLike "
"TED on Facebook: https://www.facebook.com/TED\n\nSubscribe to our "
"channel: https://www.youtube.com/TED"
)
assert video.snippet.thumbnails
assert (
video.snippet.thumbnails.default.url
== "https://i.ytimg.com/vi/Ks-_Mh1QhMc/default.jpg"
)
assert video.snippet.thumbnails.default.width == 120
assert video.snippet.thumbnails.default.height == 90
assert video.snippet.thumbnails.medium
assert (
video.snippet.thumbnails.medium.url
== "https://i.ytimg.com/vi/Ks-_Mh1QhMc/mqdefault.jpg"
)
assert video.snippet.thumbnails.medium.width == 320
assert video.snippet.thumbnails.medium.height == 180
assert video.snippet.thumbnails.high
assert (
video.snippet.thumbnails.high.url
== "https://i.ytimg.com/vi/Ks-_Mh1QhMc/hqdefault.jpg"
)
assert video.snippet.thumbnails.high.width == 480
assert video.snippet.thumbnails.high.height == 360
assert video.snippet.thumbnails.standard
assert (
video.snippet.thumbnails.standard.url
== "https://i.ytimg.com/vi/Ks-_Mh1QhMc/sddefault.jpg"
)
assert video.snippet.thumbnails.standard.width == 640
assert video.snippet.thumbnails.standard.height == 480
assert video.snippet.thumbnails.maxres
assert (
video.snippet.thumbnails.maxres.url
== "https://i.ytimg.com/vi/Ks-_Mh1QhMc/maxresdefault.jpg"
)
assert video.snippet.thumbnails.maxres.width == 1280
assert video.snippet.thumbnails.maxres.height == 720
await youtube.close()
assert video == snapshot


async def test_fetch_videos(
Expand Down

0 comments on commit 7462867

Please sign in to comment.