Skip to content

Commit

Permalink
Add e2e tests for zim metadata, channel.json, videos, and playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-niles committed Jul 15, 2024
1 parent 1ba45c3 commit 666c585
Showing 1 changed file with 62 additions and 5 deletions.
67 changes: 62 additions & 5 deletions scraper/tests-integration/integration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os

from zimscraperlib.zim import Archive
Expand All @@ -18,12 +19,68 @@ def test_zim_main_page():
assert main_entry.get_redirect_entry().path == "index.html"


def test_zim_scraper():
def test_zim_metadata():
"""Ensure scraper and zim title are present in metadata"""

zim_fh = Archive(ZIM_FILE_PATH)
scraper = zim_fh.get_text_metadata("scraper")
zim_title = zim_fh.get_text_metadata("Title")

assert "youtube2zim " in scraper
assert "openZIM_testing" in zim_title
assert "youtube2zim " in zim_fh.get_text_metadata("scraper")
assert "openZIM_testing" in zim_fh.get_text_metadata("Title")
assert "-" in zim_fh.get_text_metadata("Description")
assert "en" in zim_fh.get_text_metadata("Language")
assert "openZIM" in zim_fh.get_text_metadata("Publisher")
assert "openZIM_testing" in zim_fh.get_text_metadata("Creator")

assert zim_fh.get_item("profile.jpg").mimetype == "image/jpeg"
assert zim_fh.get_item("favicon.png").mimetype == "image/png"


def test_zim_channel_json():
"""Ensure channel.json exists and is valid"""

zim_fh = Archive(ZIM_FILE_PATH)
channel_json = zim_fh.get_content("channel.json")
channel_json = json.loads(channel_json)

assert channel_json["id"] == "UC8elThf5TGMpQfQc_VE917Q"
assert channel_json["channelName"] == "openZIM_testing"
assert channel_json["collectionType"] == "channel"
assert channel_json["mainPlaylist"] == "uploads_from_openzim_testing-917Q"


def test_zim_videos():
"""Ensure videos and video thumbnails are present in ZIM file"""

zim_fh = Archive(ZIM_FILE_PATH)
videos_json_list = [
"cloudy_sky_time_lapse_4k_free_footage_video_gopro_11-k02q.json",
"coffee_machine-DYvY.json",
"marvel_studios_avengers_endgame_official_trailer-TcMB.json",
"timelapse-9Tgo.json",
]

for video_json_file in videos_json_list:
json_path = "videos/" + video_json_file
assert zim_fh.get_item(json_path).mimetype == "application/json"

video_json = zim_fh.get_content(json_path)
video_json = json.loads(video_json)

assert zim_fh.get_item(video_json["videoPath"]).mimetype == "video/webm"
assert zim_fh.get_item(video_json["thumbnailPath"]).mimetype == "image/webp"


def test_zim_playlists():
"""Ensure playlists json files are present in ZIM file"""

zim_fh = Archive(ZIM_FILE_PATH)
playlists_json_list = [
"coffee-O2wS.json",
"timelapses-QgGI.json",
"trailers-5Gph.json",
"uploads_from_openzim_testing-917Q.json",
]

for playlist_json_file in playlists_json_list:
json_path = "playlists/" + playlist_json_file
assert zim_fh.get_item(json_path).mimetype == "application/json"

0 comments on commit 666c585

Please sign in to comment.