Skip to content

Commit 7be1c27

Browse files
Add unit tests for seasons and episodes
1 parent 38b2b5b commit 7be1c27

4 files changed

Lines changed: 728 additions & 375 deletions

File tree

test/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ ignore = [
1111
"ARG", # Mocks can be unused arguments
1212
"INP001", # __init__.py here seems unnecessary
1313
"PT013", # Kinda don't care, maybe fix one day
14+
"PT019", # Regular "patch" seems fine
1415
]
Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
from simplejustwatchapi.graphql import (
2+
graphql_details_query,
3+
graphql_episodes_query,
4+
graphql_offers_for_countries_query,
5+
graphql_search_query,
6+
graphql_seasons_query,
7+
)
8+
9+
GRAPHQL_SEARCH_QUERY = """
10+
query GetSearchTitles(
11+
$searchTitlesFilter: TitleFilter!,
12+
$country: Country!,
13+
$language: Language!,
14+
$first: Int!,
15+
$formatPoster: ImageFormat,
16+
$formatOfferIcon: ImageFormat,
17+
$profile: PosterProfile,
18+
$backdropProfile: BackdropProfile,
19+
$filter: OfferFilter!,
20+
) {
21+
popularTitles(
22+
country: $country
23+
filter: $searchTitlesFilter
24+
first: $first
25+
sortBy: POPULAR
26+
sortRandomSeed: 0
27+
) {
28+
edges {
29+
node {
30+
...TitleDetails
31+
__typename
32+
}
33+
__typename
34+
}
35+
__typename
36+
}
37+
}
38+
"""
39+
40+
GRAPHQL_DETAILS_QUERY = """
41+
query GetTitleNode(
42+
$nodeId: ID!,
43+
$language: Language!,
44+
$country: Country!,
45+
$formatPoster: ImageFormat,
46+
$formatOfferIcon: ImageFormat,
47+
$profile: PosterProfile,
48+
$backdropProfile: BackdropProfile,
49+
$filter: OfferFilter!,
50+
) {
51+
node(id: $nodeId) {
52+
...TitleDetails
53+
__typename
54+
}
55+
__typename
56+
}
57+
"""
58+
59+
GRAPHQL_SEASONS_QUERY = """
60+
query GetTitleNode(
61+
$nodeId: ID!,
62+
$language: Language!,
63+
$country: Country!,
64+
$formatPoster: ImageFormat,
65+
$formatOfferIcon: ImageFormat,
66+
$profile: PosterProfile,
67+
$backdropProfile: BackdropProfile,
68+
$filter: OfferFilter!,
69+
) {
70+
node(id: $nodeId) {
71+
...on Show {
72+
seasons(sortDirection: ASC) {
73+
...TitleDetails
74+
}
75+
}
76+
__typename
77+
}
78+
__typename
79+
}
80+
"""
81+
82+
GRAPHQL_EPISODES_QUERY = """
83+
query GetTitleNode(
84+
$nodeId: ID!,
85+
$language: Language!,
86+
$country: Country!,
87+
$formatPoster: ImageFormat,
88+
$formatOfferIcon: ImageFormat,
89+
$profile: PosterProfile,
90+
$backdropProfile: BackdropProfile,
91+
$filter: OfferFilter!,
92+
) {
93+
node(id: $nodeId) {
94+
...on Season {
95+
episodes(sortDirection: ASC) {
96+
...TitleDetails
97+
}
98+
}
99+
__typename
100+
}
101+
__typename
102+
}
103+
"""
104+
105+
GRAPHQL_OFFERS_BY_COUNTRY_QUERY = """
106+
query GetTitleOffers(
107+
$nodeId: ID!,
108+
$language: Language!,
109+
$formatOfferIcon: ImageFormat,
110+
$filter: OfferFilter!,
111+
) {{
112+
node(id: $nodeId) {{
113+
... on MovieOrShowOrSeasonOrEpisode {{
114+
{country_entries}
115+
__typename
116+
}}
117+
__typename
118+
}}
119+
__typename
120+
}}
121+
"""
122+
123+
GRAPHQL_DETAILS_FRAGMENT = """
124+
fragment TitleDetails on MovieOrShowOrSeasonOrEpisode {
125+
id
126+
objectId
127+
objectType
128+
content(country: $country, language: $language) {
129+
...ContentDetails
130+
__typename
131+
}
132+
...StreamingChartInfoFragment
133+
...on Show {
134+
totalSeasonCount
135+
}
136+
...on Season {
137+
totalEpisodeCount
138+
}
139+
offers(country: $country, platform: WEB, filter: $filter) {
140+
...TitleOffer
141+
}
142+
__typename
143+
}
144+
145+
fragment StreamingChartInfoFragment on MovieOrShowOrSeason {
146+
streamingCharts(country: $country) {
147+
edges {
148+
streamingChartInfo {
149+
rank
150+
trend
151+
trendDifference
152+
daysInTop3
153+
daysInTop10
154+
daysInTop100
155+
daysInTop1000
156+
topRank
157+
updatedAt
158+
__typename
159+
}
160+
__typename
161+
}
162+
__typename
163+
}
164+
}
165+
166+
fragment ContentDetails on MovieOrShowOrSeasonOrEpisodeContent {
167+
title
168+
originalReleaseYear
169+
originalReleaseDate
170+
runtime
171+
shortDescription
172+
...FullContentDetails
173+
...on MovieOrShowContent {
174+
ageCertification
175+
}
176+
...on SeasonContent {
177+
seasonNumber
178+
}
179+
...on EpisodeContent {
180+
seasonNumber
181+
episodeNumber
182+
}
183+
}
184+
185+
fragment FullContentDetails on MovieOrShowOrSeasonContent {
186+
fullPath
187+
genres {
188+
shortName
189+
__typename
190+
}
191+
externalIds {
192+
imdbId
193+
tmdbId
194+
__typename
195+
}
196+
posterUrl(profile: $profile, format: $formatPoster)
197+
backdrops(profile: $backdropProfile, format: $formatPoster) {
198+
backdropUrl
199+
__typename
200+
}
201+
scoring {
202+
imdbScore
203+
imdbVotes
204+
tmdbPopularity
205+
tmdbScore
206+
tomatoMeter
207+
certifiedFresh
208+
jwRating
209+
__typename
210+
}
211+
interactions {
212+
likelistAdditions
213+
dislikelistAdditions
214+
__typename
215+
}
216+
}
217+
"""
218+
219+
GRAPHQL_OFFER_FRAGMENT = """
220+
fragment TitleOffer on Offer {
221+
id
222+
monetizationType
223+
presentationType
224+
retailPrice(language: $language)
225+
retailPriceValue
226+
currency
227+
lastChangeRetailPriceValue
228+
type
229+
package {
230+
id
231+
packageId
232+
clearName
233+
technicalName
234+
icon(profile: S100, format: $formatOfferIcon)
235+
__typename
236+
}
237+
standardWebURL
238+
elementCount
239+
availableTo
240+
deeplinkRoku: deeplinkURL(platform: ROKU_OS)
241+
subtitleLanguages
242+
videoTechnology
243+
audioTechnology
244+
audioLanguages
245+
__typename
246+
}
247+
"""
248+
249+
GRAPHQL_COUNTRY_OFFERS_ENTRY = """
250+
{country_code}: offers(country: {country_code}, platform: WEB, filter: $filter) {{
251+
...TitleOffer
252+
__typename
253+
}}
254+
"""
255+
256+
257+
def test_graphql_search_query():
258+
expected_query = GRAPHQL_SEARCH_QUERY + GRAPHQL_DETAILS_FRAGMENT + GRAPHQL_OFFER_FRAGMENT
259+
query = graphql_search_query()
260+
assert expected_query == query
261+
262+
263+
def test_graphql_details_query():
264+
expected_query = GRAPHQL_DETAILS_QUERY + GRAPHQL_DETAILS_FRAGMENT + GRAPHQL_OFFER_FRAGMENT
265+
query = graphql_details_query()
266+
assert expected_query == query
267+
268+
269+
def test_graphql_seasons_query():
270+
expected_query = GRAPHQL_SEASONS_QUERY + GRAPHQL_DETAILS_FRAGMENT + GRAPHQL_OFFER_FRAGMENT
271+
query = graphql_seasons_query()
272+
assert expected_query == query
273+
274+
275+
def test_graphql_episodes_query():
276+
expected_query = GRAPHQL_EPISODES_QUERY + GRAPHQL_DETAILS_FRAGMENT + GRAPHQL_OFFER_FRAGMENT
277+
query = graphql_episodes_query()
278+
assert expected_query == query
279+
280+
281+
def test_graphql_offers_for_countries_query():
282+
country_codes = {"gb", "Us", "fR", "CA"}
283+
offer_requests = [
284+
GRAPHQL_COUNTRY_OFFERS_ENTRY.format(country_code=country_code.upper())
285+
for country_code in country_codes
286+
]
287+
main_body = GRAPHQL_OFFERS_BY_COUNTRY_QUERY.format(country_entries="\n".join(offer_requests))
288+
expected_query = main_body + GRAPHQL_OFFER_FRAGMENT
289+
query = graphql_offers_for_countries_query(country_codes)
290+
assert expected_query == query

0 commit comments

Comments
 (0)