From ddce6bf8f9d580737b8b6157d9d39ba83c50dc1b Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Tue, 21 May 2024 12:57:21 +0300 Subject: [PATCH] restore old file_version tests, skip them on PGSQL (#256) Restored the old tests for the file versions, because that commit with optimization of working with file versions in the Nextcloud server repository was backported on the NC 27, 28 versions of the server - I simply disabled this test on the PGSQL database, where these tests fails. Signed-off-by: Alexander Piskun --- .github/workflows/analysis-coverage.yml | 2 + Makefile | 10 ++++ tests/actual_tests/files_test.py | 75 +++++++++++++------------ 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/.github/workflows/analysis-coverage.yml b/.github/workflows/analysis-coverage.yml index 9e4f9844..37f16595 100644 --- a/.github/workflows/analysis-coverage.yml +++ b/.github/workflows/analysis-coverage.yml @@ -200,6 +200,7 @@ jobs: php-version: "8.2" env: NC_dbname: nextcloud_abz + DATABASE_PGSQL: 1 timeout-minutes: 60 services: @@ -637,6 +638,7 @@ jobs: nextcloud: [ 'stable27', 'stable28', 'master' ] env: NC_dbname: nextcloud_abz + DATABASE_PGSQL: 1 timeout-minutes: 60 services: diff --git a/Makefile b/Makefile index a699b766..95fcd2cc 100644 --- a/Makefile +++ b/Makefile @@ -21,10 +21,12 @@ help: @echo " " @echo " register27 register nc_py_api for Nextcloud 27" @echo " register28 register nc_py_api for Nextcloud 28" + @echo " register29 register nc_py_api for Nextcloud 29" @echo " register register nc_py_api for Nextcloud Last" @echo " " @echo " tests27 run nc_py_api tests for Nextcloud 27" @echo " tests28 run nc_py_api tests for Nextcloud 28" + @echo " tests29 run nc_py_api tests for Nextcloud 29" @echo " tests run nc_py_api tests for Nextcloud Last" .PHONY: register27 @@ -35,6 +37,10 @@ register27: register28: /bin/sh scripts/dev_register.sh master-stable28-1 stable28.local +.PHONY: register29 +register29: + /bin/sh scripts/dev_register.sh master-stable29-1 stable28.local + .PHONY: register register: /bin/sh scripts/dev_register.sh master-nextcloud-1 nextcloud.local @@ -47,6 +53,10 @@ tests27: tests28: NEXTCLOUD_URL=http://stable28.local python3 -m pytest +.PHONY: tests29 +tests29: + NEXTCLOUD_URL=http://stable29.local python3 -m pytest + .PHONY: tests tests: NEXTCLOUD_URL=http://nextcloud.local python3 -m pytest diff --git a/tests/actual_tests/files_test.py b/tests/actual_tests/files_test.py index 1ee4b3da..6d477dfc 100644 --- a/tests/actual_tests/files_test.py +++ b/tests/actual_tests/files_test.py @@ -1,7 +1,6 @@ import contextlib import math import os -import time import zipfile from datetime import datetime from io import BytesIO @@ -1055,45 +1054,51 @@ async def test_trashbin_async(anc_any, file_path): assert not r -def test_file_versions(nc_any): +@pytest.mark.skipif(os.environ.get("DATABASE_PGSQL", "0") == "1", reason="Fails on the PGSQL") +@pytest.mark.parametrize( + "dest_path", + ("/test_dir_tmp/file_versions.txt", "/test_dir_tmp/file_versions-ä.txt", "test_dir_tmp/file_versions-1##3"), +) +def test_file_versions(nc_any, dest_path): if nc_any.check_capabilities("files.versioning"): pytest.skip("Need 'Versions' App to be enabled.") - dest_path = "/test_dir_tmp/file_versions-ä.txt" - nc_any.files.delete(dest_path, not_fail=True) - nc_any.files.upload(dest_path, content=b"22") - time.sleep(2.0) - new_file = nc_any.files.upload(dest_path, content=b"333") - time.sleep(2.0) - versions = nc_any.files.get_versions(new_file) - assert versions - version_str = str(versions[0]) - assert version_str.find("File version") != -1 - assert version_str.find("bytes size") != -1 - time.sleep(2.0) - nc_any.files.restore_version(versions[0]) - time.sleep(2.0) - assert nc_any.files.download(new_file) == b"22" - - + for i in (0, 1): + nc_any.files.delete(dest_path, not_fail=True) + nc_any.files.upload(dest_path, content=b"22") + new_file = nc_any.files.upload(dest_path, content=b"333") + if i: + new_file = nc_any.files.by_id(new_file) + versions = nc_any.files.get_versions(new_file) + assert versions + version_str = str(versions[0]) + assert version_str.find("File version") != -1 + assert version_str.find("bytes size") != -1 + nc_any.files.restore_version(versions[0]) + assert nc_any.files.download(new_file) == b"22" + + +@pytest.mark.skipif(os.environ.get("DATABASE_PGSQL", "0") == "1", reason="Fails on the PGSQL") @pytest.mark.asyncio(scope="session") -async def test_file_versions_async(anc_any): +@pytest.mark.parametrize( + "dest_path", + ("/test_dir_tmp/file_versions.txt", "/test_dir_tmp/file_versions-ä.txt", "test_dir_tmp/file_versions-1##3"), +) +async def test_file_versions_async(anc_any, dest_path): if await anc_any.check_capabilities("files.versioning"): pytest.skip("Need 'Versions' App to be enabled.") - dest_path = "/test_dir_tmp/file_versions-ä-async.txt" - await anc_any.files.delete(dest_path, not_fail=True) - await anc_any.files.upload(dest_path, content=b"22") - time.sleep(2.0) - new_file = await anc_any.files.upload(dest_path, content=b"333") - time.sleep(2.0) - versions = await anc_any.files.get_versions(new_file) - assert versions - version_str = str(versions[0]) - assert version_str.find("File version") != -1 - assert version_str.find("bytes size") != -1 - time.sleep(2.0) - await anc_any.files.restore_version(versions[0]) - time.sleep(2.0) - assert await anc_any.files.download(new_file) == b"22" + for i in (0, 1): + await anc_any.files.delete(dest_path, not_fail=True) + await anc_any.files.upload(dest_path, content=b"22") + new_file = await anc_any.files.upload(dest_path, content=b"333") + if i: + new_file = await anc_any.files.by_id(new_file) + versions = await anc_any.files.get_versions(new_file) + assert versions + version_str = str(versions[0]) + assert version_str.find("File version") != -1 + assert version_str.find("bytes size") != -1 + await anc_any.files.restore_version(versions[0]) + assert await anc_any.files.download(new_file) == b"22" def test_create_update_delete_tag(nc_any):