From fbad3b301a525a48e2321bb7a2a3d8ce505eeb0f Mon Sep 17 00:00:00 2001 From: Alexander Piskun Date: Sun, 22 Oct 2023 00:19:20 +0300 Subject: [PATCH] fixed tests Signed-off-by: Alexander Piskun --- .github/workflows/analysis-coverage.yml | 263 +++++++++++++----------- nc_py_api/ex_app/integration_fastapi.py | 2 +- tests/_install.py | 6 +- tests/_install_init_handler_models.py | 6 +- 4 files changed, 147 insertions(+), 130 deletions(-) diff --git a/.github/workflows/analysis-coverage.yml b/.github/workflows/analysis-coverage.yml index 998d6632..c1a3f281 100644 --- a/.github/workflows/analysis-coverage.yml +++ b/.github/workflows/analysis-coverage.yml @@ -304,7 +304,7 @@ jobs: - name: Enable Talk run: php occ app:enable spreed - - name: Generate coverage report + - name: Generate coverage report (1) working-directory: nc_py_api run: | coverage run --data-file=.coverage.talk_bot tests/_talk_bot.py & @@ -313,6 +313,23 @@ jobs: kill -15 $(cat /tmp/_talk_bot.pid) timeout 3m tail --pid=$(cat /tmp/_talk_bot.pid) -f /dev/null coverage run --data-file=.coverage.at_the_end -m pytest tests/_tests_at_the_end.py + + - name: Uninstall NcPyApi + run: | + php occ app_api:app:unregister "$APP_ID" --silent + php occ app_api:daemon:unregister manual_install + + - name: Generate coverage report (2) + working-directory: nc_py_api + run: | + coverage run --data-file=.coverage.ci_install_models tests/_install_init_handler_models.py & + echo $! > /tmp/_install_models.pid + python3 tests/_install_wait.py http://127.0.0.1:$APP_PORT/heartbeat "\"status\":\"ok\"" 15 0.5 + cd .. + sh nc_py_api/scripts/ci_register.sh "$APP_ID" "$APP_VERSION" "$APP_SECRET" "localhost" "$APP_PORT" + kill -15 $(cat /tmp/_install_models.pid) + timeout 3m tail --pid=$(cat /tmp/_install_models.pid) -f /dev/null + cd nc_py_api coverage combine && coverage xml && coverage html - name: HTML coverage to artifacts @@ -340,127 +357,127 @@ jobs: path: data/nextcloud.log if-no-files-found: warn -# tests-oci: -# needs: [analysis] -# runs-on: ubuntu-22.04 -# name: ${{ matrix.nextcloud }} • 🐘${{ matrix.php-version }} • 🐍${{ matrix.python }} • OCI -# strategy: -# fail-fast: false -# matrix: -# nextcloud: [ "27.1.2" ] -# python: [ "3.11" ] -# php-version: [ "8.2" ] -# -# services: -# oracle: -# image: ghcr.io/gvenzl/oracle-xe:11 -# env: -# ORACLE_RANDOM_PASSWORD: true -# APP_USER: useroracle -# APP_USER_PASSWORD: userpassword -# options: >- -# --health-cmd healthcheck.sh -# --health-interval 10s -# --health-timeout 5s -# --health-retries 10 -# ports: -# - 1521:1521/tcp -# -# steps: -# - name: Set up php -# uses: shivammathur/setup-php@v2 -# with: -# php-version: ${{ matrix.php-version }} -# extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, \ -# posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, oci8 -# -# - uses: actions/setup-python@v4 -# with: -# python-version: ${{ matrix.python }} -# -# - name: cache-nextcloud -# id: nextcloud_setup -# uses: actions/cache@v3 -# with: -# path: nextcloud-${{ matrix.nextcloud }}.tar.bz2 -# key: ${{ matrix.nextcloud }} -# -# - name: Download Nextcloud -# if: steps.nextcloud_setup.outputs.cache-hit != 'true' -# run: wget -q https://download.nextcloud.com/server/releases/nextcloud-${{ matrix.nextcloud }}.tar.bz2 -# -# - name: Set up Nextcloud -# run: | -# tar -xjf nextcloud-${{ matrix.nextcloud }}.tar.bz2 --strip-components 1 -# mkdir data -# php occ maintenance:install --verbose --database=oci --database-name=XE \ -# --database-host=127.0.0.1 --database-port=1521 --database-user=useroracle --database-pass=userpassword \ -# --admin-user admin --admin-pass ${{ env.NC_AUTH_PASS }} -# php occ config:system:set loglevel --value=1 --type=integer -# php occ config:system:set debug --value=true --type=boolean -# PHP_CLI_SERVER_WORKERS=2 php -S localhost:8080 & -# -# - name: Checkout NcPyApi -# uses: actions/checkout@v4 -# with: -# path: nc_py_api -# -# - name: Install NcPyApi -# working-directory: nc_py_api -# run: python3 -m pip -v install ".[app,dev-min]" -# -# - name: Checkout AppAPI -# uses: actions/checkout@v4 -# with: -# path: apps/app_api -# repository: cloud-py-api/app_api -# -# - name: Install AppAPI -# run: | -# php occ app:enable app_api -# cd nc_py_api -# coverage run --data-file=.coverage.ci_install tests/_install.py & -# echo $! > /tmp/_install.pid -# python3 tests/_install_wait.py http://127.0.0.1:$APP_PORT/heartbeat "\"status\":\"ok\"" 15 0.5 -# python3 tests/_app_security_checks.py http://127.0.0.1:$APP_PORT -# cd .. -# sh nc_py_api/scripts/ci_register.sh "$APP_ID" "$APP_VERSION" "$APP_SECRET" "localhost" "$APP_PORT" -# kill -15 $(cat /tmp/_install.pid) -# timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null -# -# - name: Generate coverage report -# working-directory: nc_py_api -# run: | -# coverage run --data-file=.coverage.ci -m pytest -# coverage run --data-file=.coverage.at_the_end -m pytest tests/_tests_at_the_end.py -# coverage combine && coverage xml && coverage html -# env: -# SKIP_NC_CLIENT_TESTS: 1 -# -# - name: HTML coverage to artifacts -# uses: actions/upload-artifact@v3 -# with: -# name: coverage_oci_${{ matrix.nextcloud }}_${{ matrix.python }}_${{ matrix.php-version }} -# path: nc_py_api/htmlcov -# if-no-files-found: error -# -# - name: Upload report to Codecov -# uses: codecov/codecov-action@v3 -# with: -# token: ${{ secrets.CODECOV_TOKEN }} -# name: coverage_oci_${{ matrix.nextcloud }}_${{ matrix.python }}_${{ matrix.php-version }} -# file: coverage.xml -# fail_ci_if_error: true -# verbose: true -# working-directory: nc_py_api -# -# - name: Upload NC logs -# if: always() -# uses: actions/upload-artifact@v3 -# with: -# name: nc_log_oci_${{ matrix.nextcloud }}_${{ matrix.python }}_${{ matrix.php-version }} -# path: data/nextcloud.log -# if-no-files-found: warn + tests-oci: + needs: [analysis] + runs-on: ubuntu-22.04 + name: ${{ matrix.nextcloud }} • 🐘${{ matrix.php-version }} • 🐍${{ matrix.python }} • OCI + strategy: + fail-fast: false + matrix: + nextcloud: [ "27.1.2" ] + python: [ "3.11" ] + php-version: [ "8.2" ] + + services: + oracle: + image: ghcr.io/gvenzl/oracle-xe:11 + env: + ORACLE_RANDOM_PASSWORD: true + APP_USER: useroracle + APP_USER_PASSWORD: userpassword + options: >- + --health-cmd healthcheck.sh + --health-interval 10s + --health-timeout 5s + --health-retries 10 + ports: + - 1521:1521/tcp + + steps: + - name: Set up php + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, \ + posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, oci8 + + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + + - name: cache-nextcloud + id: nextcloud_setup + uses: actions/cache@v3 + with: + path: nextcloud-${{ matrix.nextcloud }}.tar.bz2 + key: ${{ matrix.nextcloud }} + + - name: Download Nextcloud + if: steps.nextcloud_setup.outputs.cache-hit != 'true' + run: wget -q https://download.nextcloud.com/server/releases/nextcloud-${{ matrix.nextcloud }}.tar.bz2 + + - name: Set up Nextcloud + run: | + tar -xjf nextcloud-${{ matrix.nextcloud }}.tar.bz2 --strip-components 1 + mkdir data + php occ maintenance:install --verbose --database=oci --database-name=XE \ + --database-host=127.0.0.1 --database-port=1521 --database-user=useroracle --database-pass=userpassword \ + --admin-user admin --admin-pass ${{ env.NC_AUTH_PASS }} + php occ config:system:set loglevel --value=1 --type=integer + php occ config:system:set debug --value=true --type=boolean + PHP_CLI_SERVER_WORKERS=2 php -S localhost:8080 & + + - name: Checkout NcPyApi + uses: actions/checkout@v4 + with: + path: nc_py_api + + - name: Install NcPyApi + working-directory: nc_py_api + run: python3 -m pip -v install ".[app,dev-min]" + + - name: Checkout AppAPI + uses: actions/checkout@v4 + with: + path: apps/app_api + repository: cloud-py-api/app_api + + - name: Install AppAPI + run: | + php occ app:enable app_api + cd nc_py_api + coverage run --data-file=.coverage.ci_install tests/_install.py & + echo $! > /tmp/_install.pid + python3 tests/_install_wait.py http://127.0.0.1:$APP_PORT/heartbeat "\"status\":\"ok\"" 15 0.5 + python3 tests/_app_security_checks.py http://127.0.0.1:$APP_PORT + cd .. + sh nc_py_api/scripts/ci_register.sh "$APP_ID" "$APP_VERSION" "$APP_SECRET" "localhost" "$APP_PORT" + kill -15 $(cat /tmp/_install.pid) + timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null + + - name: Generate coverage report + working-directory: nc_py_api + run: | + coverage run --data-file=.coverage.ci -m pytest + coverage run --data-file=.coverage.at_the_end -m pytest tests/_tests_at_the_end.py + coverage combine && coverage xml && coverage html + env: + SKIP_NC_CLIENT_TESTS: 1 + + - name: HTML coverage to artifacts + uses: actions/upload-artifact@v3 + with: + name: coverage_oci_${{ matrix.nextcloud }}_${{ matrix.python }}_${{ matrix.php-version }} + path: nc_py_api/htmlcov + if-no-files-found: error + + - name: Upload report to Codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + name: coverage_oci_${{ matrix.nextcloud }}_${{ matrix.python }}_${{ matrix.php-version }} + file: coverage.xml + fail_ci_if_error: true + verbose: true + working-directory: nc_py_api + + - name: Upload NC logs + if: always() + uses: actions/upload-artifact@v3 + with: + name: nc_log_oci_${{ matrix.nextcloud }}_${{ matrix.python }}_${{ matrix.php-version }} + path: data/nextcloud.log + if-no-files-found: warn tests-latest-maria: needs: [analysis] @@ -882,7 +899,7 @@ jobs: permissions: contents: none runs-on: ubuntu-22.04 - needs: [tests-maria, tests-pgsql, tests-latest-maria, test-latest-pgsql, tests-client-sqlite] + needs: [tests-maria, tests-pgsql, tests-oci, tests-latest-maria, test-latest-pgsql, tests-client-sqlite] name: Tests-OK steps: - run: echo "Tests passed successfully" diff --git a/nc_py_api/ex_app/integration_fastapi.py b/nc_py_api/ex_app/integration_fastapi.py index ffb1e239..52acad47 100644 --- a/nc_py_api/ex_app/integration_fastapi.py +++ b/nc_py_api/ex_app/integration_fastapi.py @@ -75,7 +75,7 @@ def set_handlers( :param models_download_params: Parameters to pass to ``snapshot_download`` function from **huggingface_hub**. """ - def fetch_models_task(models: list[str]): + def fetch_models_task(models: list[str]) -> None: if models: from huggingface_hub import snapshot_download # noqa isort:skip pylint: disable=C0415 disable=E0401 from tqdm import tqdm # noqa isort:skip pylint: disable=C0415 disable=E0401 diff --git a/tests/_install.py b/tests/_install.py index 1cc58db1..746ca5b9 100644 --- a/tests/_install.py +++ b/tests/_install.py @@ -27,13 +27,17 @@ def enabled_handler(enabled: bool, nc: NextcloudApp) -> str: return "" +def init_handler(): + NextcloudApp().set_init_status(100) + + def heartbeat_callback(): return "ok" @APP.on_event("startup") def initialization(): - ex_app.set_handlers(APP, enabled_handler, heartbeat_callback) + ex_app.set_handlers(APP, enabled_handler, heartbeat_callback, init_handler=init_handler) if __name__ == "__main__": diff --git a/tests/_install_init_handler_models.py b/tests/_install_init_handler_models.py index ac957331..c2f2f66f 100644 --- a/tests/_install_init_handler_models.py +++ b/tests/_install_init_handler_models.py @@ -16,13 +16,9 @@ def enabled_handler(enabled: bool, _nc: NextcloudApp) -> str: return "" -def init_handler(): - NextcloudApp().set_init_status(100) - - @APP.on_event("startup") def initialization(): - ex_app.set_handlers(APP, enabled_handler, init_handler=init_handler, models_to_fetch=[MODEL_NAME]) + ex_app.set_handlers(APP, enabled_handler, models_to_fetch=[MODEL_NAME]) if __name__ == "__main__":