Skip to content

Commit 246f9e1

Browse files
committed
Fix / enrich integration tests
1 parent bb41174 commit 246f9e1

File tree

2 files changed

+100
-8
lines changed

2 files changed

+100
-8
lines changed

CONTRIBUTING.md

+8
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,11 @@ yarn test:e2e
101101
```
102102

103103
On Linux, you might need to install additional dependencies, see [Linux Prerequisites](https://docs.cypress.io/guides/getting-started/installing-cypress#Linux-Prerequisites) in the Cypress documentation.
104+
105+
## running integration tests checking ZIM content
106+
107+
We have a bunch of integration tests checking ZIM content. Once you have a the test ZIM from openZIM channel (see instructions above for Vue.JS ZIM UI), you can run the tests locally as well:
108+
109+
```
110+
ZIM_FILE_PATH="output/openZIM_testing.zim" pytest scraper/tests-integration/integration.py
111+
```

scraper/tests-integration/integration.py

+92-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from zimscraperlib.zim import Archive
55

6-
ZIM_FILE_PATH = "/output/openZIM_testing.zim"
6+
ZIM_FILE_PATH = os.getenv("ZIM_FILE_PATH") or "/output/openZIM_testing.zim"
77

88

99
def test_is_file():
@@ -47,7 +47,7 @@ def test_zim_channel_json():
4747

4848
assert channel_json["id"] == "UC8elThf5TGMpQfQc_VE917Q"
4949
assert channel_json["channelName"] == "openZIM_testing"
50-
assert channel_json["firstPlaylist"] == "uploads_from_openzim_testing-917Q"
50+
assert channel_json["firstPlaylist"] == "videos-917Q"
5151

5252

5353
def test_zim_videos():
@@ -80,17 +80,101 @@ def test_zim_videos():
8080
)
8181

8282

83-
def test_zim_playlists():
83+
def test_zim_playlists_file():
8484
"""Ensure playlists json files are present in ZIM file"""
8585

8686
zim_fh = Archive(ZIM_FILE_PATH)
87+
88+
json_path = "playlists.json"
89+
assert zim_fh.get_item(json_path).mimetype == "application/json"
90+
91+
video_json = zim_fh.get_content(json_path)
92+
video_json = json.loads(video_json)
93+
assert [video["slug"] for video in video_json["playlists"]] == [
94+
"trailers-5Gph",
95+
"timelapses-QgGI",
96+
"coffee-O2wS",
97+
]
98+
assert set(video_json["playlists"][0].keys()) == {
99+
"slug",
100+
"id",
101+
"title",
102+
"thumbnailPath",
103+
"videosCount",
104+
"mainVideoSlug",
105+
}
106+
107+
108+
def test_zim_home_playlists_file():
109+
"""Ensure playlists json files are present in ZIM file"""
110+
111+
zim_fh = Archive(ZIM_FILE_PATH)
112+
113+
json_path = "home_playlists.json"
114+
assert zim_fh.get_item(json_path).mimetype == "application/json"
115+
116+
video_json = zim_fh.get_content(json_path)
117+
video_json = json.loads(video_json)
118+
assert [video["slug"] for video in video_json["playlists"]] == [
119+
"videos-917Q",
120+
"short_videos-917Q",
121+
"trailers-5Gph",
122+
"timelapses-QgGI",
123+
"coffee-O2wS",
124+
]
125+
assert set(video_json["playlists"][0].keys()) == {
126+
"slug",
127+
"id",
128+
"title",
129+
"thumbnailPath",
130+
"author",
131+
"description",
132+
"videosCount",
133+
"publicationDate",
134+
"videos",
135+
}
136+
assert set(video_json["playlists"][0]["videos"][0].keys()) == {
137+
"slug",
138+
"id",
139+
"title",
140+
"thumbnailPath",
141+
"duration",
142+
}
143+
144+
145+
def test_zim_individual_playlists_files():
146+
"""Ensure playlists json files are present in ZIM file"""
147+
148+
zim_fh = Archive(ZIM_FILE_PATH)
149+
87150
playlists_json_list = [
88-
"coffee-O2wS.json",
89-
"timelapses-QgGI.json",
90-
"trailers-5Gph.json",
91-
"uploads_from_openzim_testing-917Q.json",
151+
"videos-917Q",
152+
"short_videos-917Q",
153+
"trailers-5Gph",
154+
"timelapses-QgGI",
155+
"coffee-O2wS",
92156
]
93157

94158
for playlist_json_file in playlists_json_list:
95-
json_path = "playlists/" + playlist_json_file
159+
json_path = f"playlists/{playlist_json_file}.json"
96160
assert zim_fh.get_item(json_path).mimetype == "application/json"
161+
content_json = zim_fh.get_content(json_path)
162+
content_json = json.loads(content_json)
163+
assert set(content_json.keys()) == {
164+
"slug",
165+
"id",
166+
"title",
167+
"thumbnailPath",
168+
"author",
169+
"description",
170+
"videosCount",
171+
"publicationDate",
172+
"videos",
173+
}
174+
assert set(content_json["videos"][0].keys()) == {
175+
"slug",
176+
"id",
177+
"title",
178+
"thumbnailPath",
179+
"duration",
180+
}

0 commit comments

Comments
 (0)