Skip to content

Commit 7462867

Browse files
authored
Add snapshot testing (#65)
1 parent 2f803b7 commit 7462867

File tree

4 files changed

+45
-88
lines changed

4 files changed

+45
-88
lines changed

poetry.lock

Lines changed: 34 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pytest-cov = "4.1.0"
4747
ruff = "0.0.280"
4848
safety = "2.4.0b1"
4949
yamllint = "1.32.0"
50+
syrupy = "^4.0.8"
5051

5152
[tool.poetry.urls]
5253
"Bug Tracker" = "https://github.com/joostlek/python-youtube/issues"
@@ -81,7 +82,7 @@ disallow_untyped_calls = true
8182
disallow_untyped_decorators = true
8283
disallow_untyped_defs = true
8384
no_implicit_optional = true
84-
no_implicit_reexport = true
85+
#no_implicit_reexport = true
8586
strict_optional = true
8687
warn_incomplete_stub = true
8788
warn_no_return = true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# serializer version: 1
2+
# name: test_fetch_video
3+
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'))
4+
# ---

tests/test_video.py

Lines changed: 5 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Tests for the YouTube client."""
22
import json
3-
from datetime import datetime, timezone
43

54
import aiohttp
65
import pytest
76
from aiohttp.web_request import BaseRequest
87
from aresponses import Response, ResponsesMockServer
8+
from syrupy import SnapshotAssertion
99

1010
from youtubeaio.helper import first
1111
from youtubeaio.models import YouTubeVideoThumbnails
@@ -19,6 +19,7 @@
1919

2020
async def test_fetch_video(
2121
aresponses: ResponsesMockServer,
22+
snapshot: SnapshotAssertion,
2223
) -> None:
2324
"""Test retrieving a video."""
2425
aresponses.add(
@@ -28,85 +29,12 @@ async def test_fetch_video(
2829
aresponses.Response(
2930
status=200,
3031
headers={"Content-Type": "application/json"},
31-
text=load_fixture("video_response_snippet.json"),
32+
text=json.dumps(construct_fixture("video", ["snippet"], 1)),
3233
),
3334
)
34-
async with aiohttp.ClientSession() as session:
35-
youtube = YouTube(session=session)
35+
async with aiohttp.ClientSession() as session, YouTube(session=session) as youtube:
3636
video = await youtube.get_video(video_id="Ks-_Mh1QhMc")
37-
assert video
38-
assert video.snippet
39-
assert video.snippet.published_at == datetime(
40-
2012,
41-
10,
42-
1,
43-
15,
44-
27,
45-
35,
46-
tzinfo=timezone.utc,
47-
)
48-
assert video.snippet.channel_id == "UCAuUUnT6oDeKwE6v1NGQxug"
49-
assert (
50-
video.snippet.title
51-
== "Your body language may shape who you are | Amy Cuddy"
52-
)
53-
assert (
54-
video.snippet.description
55-
== "Body language affects how others see us, but it may also change how "
56-
'we see ourselves. Social psychologist Amy Cuddy argues that "power '
57-
"posing\" -- standing in a posture of confidence, even when we don't "
58-
"feel confident -- can boost feelings of confidence, and might have an "
59-
"impact on our chances for success. (Note: Some of the findings "
60-
"presented in this talk have been referenced in an ongoing debate "
61-
"among social scientists about robustness and reproducibility. Read "
62-
"Amy Cuddy's response here: "
63-
"http://ideas.ted.com/inside-the-debate-about-power-posing-a-q-a-with"
64-
"-amy-cuddy/)\n\nGet TED Talks recommended just for you! Learn more at "
65-
"https://www.ted.com/signup.\n\nThe TED Talks channel features the "
66-
"best talks and performances from the TED Conference, where the "
67-
"world's leading thinkers and doers give the talk of their lives in 18 "
68-
"minutes (or less). Look for talks on Technology, Entertainment and "
69-
"Design -- plus science, business, global issues, the arts and "
70-
"more.\n\nFollow TED on Twitter: http://www.twitter.com/TEDTalks\nLike "
71-
"TED on Facebook: https://www.facebook.com/TED\n\nSubscribe to our "
72-
"channel: https://www.youtube.com/TED"
73-
)
74-
assert video.snippet.thumbnails
75-
assert (
76-
video.snippet.thumbnails.default.url
77-
== "https://i.ytimg.com/vi/Ks-_Mh1QhMc/default.jpg"
78-
)
79-
assert video.snippet.thumbnails.default.width == 120
80-
assert video.snippet.thumbnails.default.height == 90
81-
assert video.snippet.thumbnails.medium
82-
assert (
83-
video.snippet.thumbnails.medium.url
84-
== "https://i.ytimg.com/vi/Ks-_Mh1QhMc/mqdefault.jpg"
85-
)
86-
assert video.snippet.thumbnails.medium.width == 320
87-
assert video.snippet.thumbnails.medium.height == 180
88-
assert video.snippet.thumbnails.high
89-
assert (
90-
video.snippet.thumbnails.high.url
91-
== "https://i.ytimg.com/vi/Ks-_Mh1QhMc/hqdefault.jpg"
92-
)
93-
assert video.snippet.thumbnails.high.width == 480
94-
assert video.snippet.thumbnails.high.height == 360
95-
assert video.snippet.thumbnails.standard
96-
assert (
97-
video.snippet.thumbnails.standard.url
98-
== "https://i.ytimg.com/vi/Ks-_Mh1QhMc/sddefault.jpg"
99-
)
100-
assert video.snippet.thumbnails.standard.width == 640
101-
assert video.snippet.thumbnails.standard.height == 480
102-
assert video.snippet.thumbnails.maxres
103-
assert (
104-
video.snippet.thumbnails.maxres.url
105-
== "https://i.ytimg.com/vi/Ks-_Mh1QhMc/maxresdefault.jpg"
106-
)
107-
assert video.snippet.thumbnails.maxres.width == 1280
108-
assert video.snippet.thumbnails.maxres.height == 720
109-
await youtube.close()
37+
assert video == snapshot
11038

11139

11240
async def test_fetch_videos(

0 commit comments

Comments
 (0)