diff --git a/.github/workflows/Tests.yml b/.github/workflows/Tests.yml index 11c1757d..42666fa8 100644 --- a/.github/workflows/Tests.yml +++ b/.github/workflows/Tests.yml @@ -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" diff --git a/scraper/pyproject.toml b/scraper/pyproject.toml index 679d9fa4..102468d6 100644 --- a/scraper/pyproject.toml +++ b/scraper/pyproject.toml @@ -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" diff --git a/scraper/tests-integration/integration.py b/scraper/tests-integration/integration.py new file mode 100644 index 00000000..85602f4f --- /dev/null +++ b/scraper/tests-integration/integration.py @@ -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