Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixture for creating a published collection #216

Open
mih opened this issue Mar 13, 2023 · 0 comments
Open

Fixture for creating a published collection #216

mih opened this issue Mar 13, 2023 · 0 comments
Milestone

Comments

@mih
Copy link
Member

mih commented Mar 13, 2023

This was first introduced in #212, but used the dataverse_collection, hence turned all collections into published collections. The following patch is a sketch of a fixture that creates a dedicated/separate published collection.

diff --git a/datalad_dataverse/tests/fixtures.py b/datalad_dataverse/tests/fixtures.py
index dceda34..6c554f4 100644
--- a/datalad_dataverse/tests/fixtures.py
+++ b/datalad_dataverse/tests/fixtures.py
@@ -78,24 +78,32 @@ def dataverse_collection(dataverse_admin_api,
 
 
 @pytest.fixture(autouse=False, scope='session')
-def dataverse_published_collection(dataverse_admin_api, dataverse_collection):
+def dataverse_published_collection(dataverse_admin_api,
+                                   dataverse_demoinstance_url,
+                                   dataverse_instance_url):
     # 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,
+    # not being published or it being published already.
+    from uuid import uuid1
+    # very much like a non-published collection
+    base_collection = 'demo' \
+        if dataverse_instance_url == dataverse_demoinstance_url else 'root'
+
+    collection_alias = f'dvpub-{uuid1()}'
+
+    create_test_dataverse_collection(
+        dataverse_admin_api,
+        collection_alias,
+        collection=base_collection,
     )
+
     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))
+        dataverse_admin_api.publish_dataverse(collection_alias)
+    except Exception as e:
+        pytest.skip(f'Could not publish a dataverse collection: {str(e)}')
 
-    yield dataverse_collection
+    yield collection_alias
+
+    dataverse_admin_api.delete_dataverse(collection_alias)

Given that a cleanup of such test artifacts requires superuser permissions, the fixture must also test/ensure the availability of such permissions, or skip a test.

mih added a commit to mih/datalad-dataverse that referenced this issue Mar 13, 2023
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 datalad#216 tracks a suitable fix.

Closes datalad#215
mih added a commit to mih/datalad-dataverse that referenced this issue Mar 13, 2023
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 datalad#216 tracks a suitable fix.

Closes datalad#215
@mih mih added this to the 1.1 release milestone Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant