Skip to content

Commit

Permalink
Setup integration test and workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-niles committed Jul 2, 2024
1 parent 51e6fb6 commit 8142191
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,21 @@ jobs:
cd zimui
$(yarn bin)/cypress run
build-docker:
# this job replaces the standard "build_docker" job since it builds the docker image
run-integration-tests:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3

- name: Ensure we can build the Docker image
run: |
docker build -t testimage .
docker build -t youtube2zim .
- name: Ensure we can start the Docker image
run: |
docker run --rm testimage
- name: Run scraper
env:
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
OPTIMIZATION_CACHE_URL: ${{ secrets.OPTIMIZATION_CACHE_URL }}
run: docker run -v $PWD/output:/output youtube2zim youtube2zim --api-key "$YOUTUBE_API_KEY" --optimization-cache "$OPTIMIZATION_CACHE_URL" --type channel --id "UC8elThf5TGMpQfQc_VE917Q" --name "openZIM_testing" --zim-file "openZIM_testing.zim"

- name: Run integration test suite
run: docker run -v $PWD/scraper/tests-integration/integration.py:/src/scraper/tests-integration/integration.py -v $PWD/output:/output youtube2zim bash -c "pip install pytest; pytest -v /src/scraper/tests-integration/integration.py"
1 change: 1 addition & 0 deletions scraper/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ ban-relative-imports = "all"
[tool.ruff.lint.per-file-ignores]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252"]
"tests-integration/**/*" = ["PLR2004", "S101", "TID252"]

[tool.pytest.ini_options]
minversion = "7.3"
Expand Down
29 changes: 29 additions & 0 deletions scraper/tests-integration/integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os

from zimscraperlib.zim import Archive

ZIM_FILE_PATH = "/output/openZIM_testing.zim"


def test_is_file():
"""Ensure ZIM file exists"""
assert os.path.isfile(ZIM_FILE_PATH)


def test_zim_main_page():
"""Ensure main page is a redirect to index.html"""

main_entry = Archive(ZIM_FILE_PATH).main_entry
assert main_entry.is_redirect
assert main_entry.get_redirect_entry().path == "index.html"


def test_zim_scraper():
"""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

0 comments on commit 8142191

Please sign in to comment.