|
3 | 3 |
|
4 | 4 | from zimscraperlib.zim import Archive
|
5 | 5 |
|
6 |
| -ZIM_FILE_PATH = "/output/openZIM_testing.zim" |
| 6 | +ZIM_FILE_PATH = os.getenv("ZIM_FILE_PATH") or "/output/openZIM_testing.zim" |
7 | 7 |
|
8 | 8 |
|
9 | 9 | def test_is_file():
|
@@ -47,7 +47,7 @@ def test_zim_channel_json():
|
47 | 47 |
|
48 | 48 | assert channel_json["id"] == "UC8elThf5TGMpQfQc_VE917Q"
|
49 | 49 | assert channel_json["channelName"] == "openZIM_testing"
|
50 |
| - assert channel_json["firstPlaylist"] == "uploads_from_openzim_testing-917Q" |
| 50 | + assert channel_json["firstPlaylist"] == "videos-917Q" |
51 | 51 |
|
52 | 52 |
|
53 | 53 | def test_zim_videos():
|
@@ -80,17 +80,101 @@ def test_zim_videos():
|
80 | 80 | )
|
81 | 81 |
|
82 | 82 |
|
83 |
| -def test_zim_playlists(): |
| 83 | +def test_zim_playlists_file(): |
84 | 84 | """Ensure playlists json files are present in ZIM file"""
|
85 | 85 |
|
86 | 86 | 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 | + |
87 | 150 | 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", |
92 | 156 | ]
|
93 | 157 |
|
94 | 158 | for playlist_json_file in playlists_json_list:
|
95 |
| - json_path = "playlists/" + playlist_json_file |
| 159 | + json_path = f"playlists/{playlist_json_file}.json" |
96 | 160 | 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