Skip to content

Commit

Permalink
Rework otherwise unused dataset create
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Aug 2, 2024
1 parent 5781992 commit 76aa052
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
17 changes: 0 additions & 17 deletions lib/galaxy/managers/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,6 @@ def __init__(self, app: MinimalManagerApp):
self.quota_agent = app.quota_agent
self.security_agent = app.model.security_agent

def create(self, manage_roles=None, access_roles=None, flush=True, **kwargs):
"""
Create and return a new Dataset object.
"""
# default to NEW state on new datasets
kwargs.update(dict(state=(kwargs.get("state", model.Dataset.states.NEW))))
dataset = model.Dataset(**kwargs)
self.session().add(dataset)

self.permissions.set(dataset, manage_roles, access_roles, flush=False)

if flush:
session = self.session()
with transaction(session):
session.commit()
return dataset

def copy(self, item, **kwargs):
raise exceptions.NotImplemented("Datasets cannot be copied")

Expand Down
11 changes: 8 additions & 3 deletions test/unit/app/managers/test_DatasetManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def set_up_managers(self):
super().set_up_managers()
self.dataset_manager = DatasetManager(self.app)

def create_dataset_with_permissions(self, manage_roles=None, access_roles=None) -> model.Dataset:
dataset = self.dataset_manager.create(flush=False)
self.dataset_manager.permissions.set(dataset, manage_roles, access_roles)
return dataset

def test_create(self):
self.log("should be able to create a new Dataset")
dataset1 = self.dataset_manager.create()
Expand Down Expand Up @@ -125,7 +130,7 @@ def test_create_public_dataset(self):
)
owner = self.user_manager.create(**user2_data)
owner_private_role = self.user_manager.private_role(owner)
dataset = self.dataset_manager.create(manage_roles=[owner_private_role])
dataset = self.create_dataset_with_permissions(manage_roles=[owner_private_role])

permissions = self.dataset_manager.permissions.get(dataset)
assert isinstance(permissions, tuple)
Expand Down Expand Up @@ -157,7 +162,7 @@ def test_create_private_dataset(self):
self.log("should be able to create a new Dataset and give it private permissions")
owner = self.user_manager.create(**user2_data)
owner_private_role = self.user_manager.private_role(owner)
dataset = self.dataset_manager.create(manage_roles=[owner_private_role], access_roles=[owner_private_role])
dataset = self.create_dataset_with_permissions(manage_roles=[owner_private_role], access_roles=[owner_private_role])

permissions = self.dataset_manager.permissions.get(dataset)
assert isinstance(permissions, tuple)
Expand Down Expand Up @@ -268,7 +273,7 @@ def test_serialize_permissions(self):

def test_serializers(self):
# self.user_manager.create( **user2_data )
dataset = self.dataset_manager.create()
dataset = self.dataset_manager.create(state=model.Dataset.states.NEW)
all_keys = list(self.dataset_serializer.serializable_keyset)
serialized = self.dataset_serializer.serialize(dataset, all_keys)

Expand Down

0 comments on commit 76aa052

Please sign in to comment.