From f7910339edfc4d5a9992e14b09d64237f77f22b0 Mon Sep 17 00:00:00 2001 From: Michael Hanke Date: Mon, 13 Mar 2023 07:58:23 +0100 Subject: [PATCH] Remove test aspects requiring published datasets ATM we are no capable of cleaning up such datasets after a testrun, because we do not have superuser permissions on demo.dataverse.org This also removed the now obsolete test fixtures. Issue #216 tracks a suitable fix. Closes #215 --- datalad_dataverse/conftest.py | 2 -- datalad_dataverse/tests/fixtures.py | 35 --------------------- datalad_dataverse/tests/test_pydataverse.py | 25 ++------------- 3 files changed, 3 insertions(+), 59 deletions(-) diff --git a/datalad_dataverse/conftest.py b/datalad_dataverse/conftest.py index a390395..0c7f5d8 100644 --- a/datalad_dataverse/conftest.py +++ b/datalad_dataverse/conftest.py @@ -14,6 +14,4 @@ dataverse_dataset, dataverse_demoinstance_url, dataverse_instance_url, - dataverse_published_collection, - dataverse_publishable_dataset, ) diff --git a/datalad_dataverse/tests/fixtures.py b/datalad_dataverse/tests/fixtures.py index dceda34..44a7fd6 100644 --- a/datalad_dataverse/tests/fixtures.py +++ b/datalad_dataverse/tests/fixtures.py @@ -77,27 +77,6 @@ def dataverse_collection(dataverse_admin_api, dataverse_admin_api.delete_dataverse(collection_alias) -@pytest.fixture(autouse=False, scope='session') -def dataverse_published_collection(dataverse_admin_api, dataverse_collection): - # This may not work in all test setups due to lack of permissions or /root - # not being published or it being published already. Try though, since it's - # necessary to publish datasets in order to test against dataverse datasets - # with several versions. - from pyDataverse.exceptions import ( - ApiAuthorizationError, - OperationFailedError, - ) - try: - dataverse_admin_api.publish_dataverse(dataverse_collection) - except ApiAuthorizationError: - # Test setup doesn't allow for it - pass - except OperationFailedError as e: - print(str(e)) - - yield dataverse_collection - - @pytest.fixture(autouse=False, scope='function') def dataverse_dataset(dataverse_admin_api, dataverse_collection): dspid = create_test_dataverse_dataset( @@ -109,20 +88,6 @@ def dataverse_dataset(dataverse_admin_api, dataverse_collection): dataverse_admin_api.destroy_dataset(dspid) -@pytest.fixture(autouse=False, scope='function') -def dataverse_publishable_dataset(dataverse_admin_api, - dataverse_published_collection): - """Same as `dataverse_dataset` but dataset is part of a published - collection. This is required to be able to publish the dataset.""" - dspid = create_test_dataverse_dataset( - dataverse_admin_api, dataverse_published_collection, 'testds') - - yield dspid - - # cleanup - dataverse_admin_api.destroy_dataset(dspid) - - @pytest.fixture(autouse=False, scope='function') def dataverse_admin_credential_setup( dataverse_admin_token, dataverse_instance_url, credman): diff --git a/datalad_dataverse/tests/test_pydataverse.py b/datalad_dataverse/tests/test_pydataverse.py index 2a83883..382d5ff 100644 --- a/datalad_dataverse/tests/test_pydataverse.py +++ b/datalad_dataverse/tests/test_pydataverse.py @@ -174,7 +174,7 @@ def check_upload(api, dsid, fcontent, fpath, src_md5): def test_file_removal( tmp_path, dataverse_admin_api, - dataverse_publishable_dataset, + dataverse_dataset, ): # the starting point of `dataverse_dataset` is a freshly @@ -184,7 +184,7 @@ def test_file_removal( fpath = tmp_path / 'dummy.txt' fpath.write_text(fcontent) response = dataverse_admin_api.upload_datafile( - identifier=dataverse_publishable_dataset, + identifier=dataverse_dataset, filename=fpath, ) # worked @@ -207,27 +207,8 @@ def test_file_removal( # Re-upload response = dataverse_admin_api.upload_datafile( - identifier=dataverse_publishable_dataset, + identifier=dataverse_dataset, filename=fpath, ) assert response.status_code == 200, \ f"failed to upload file {response.status_code}: {response.json()}" - - fid2 = response.json()['data']['files'][0]['dataFile']['id'] - - # Publish the dataset - # Note, that "major" release is required. We can't publish a "minor" when - # there's no major yet. - response = dataverse_admin_api.publish_dataset( - dataverse_publishable_dataset, release_type="major") - assert response.status_code == 200, \ - f"publishing dataset failed with {response.status_code}: {response.json()}" - - # We can't remove a file that is part of a published dataset: - status = delete( - f'{dataverse_admin_api.base_url}/dvn/api/data-deposit/v1.1/swordv2/' - f'edit-media/file/{fid2}', - auth=HTTPBasicAuth(dataverse_admin_api.api_token, '')) - - assert status.status_code == 400, \ - f"unexpected status on deletion {status.status_code}: {status.json()}"