Skip to content

Commit

Permalink
Rework otherwise unused dataset create.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Aug 1, 2024
1 parent 89107c9 commit 894970e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/managers/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ 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):
def create_for_unit_testing(self, manage_roles=None, access_roles=None, flush=True, **kwargs):
"""
Create and return a new Dataset object.
"""
Expand Down
26 changes: 13 additions & 13 deletions test/unit/app/managers/test_DatasetManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def set_up_managers(self):

def test_create(self):
self.log("should be able to create a new Dataset")
dataset1 = self.dataset_manager.create()
dataset1 = self.dataset_manager.create_for_unit_testing()
assert isinstance(dataset1, model.Dataset)
assert dataset1 == self.trans.sa_session.get(model.Dataset, dataset1.id)

def test_base(self):
dataset1 = self.dataset_manager.create()
dataset2 = self.dataset_manager.create()
dataset1 = self.dataset_manager.create_for_unit_testing()
dataset2 = self.dataset_manager.create_for_unit_testing()

self.log("should be able to query")
datasets = self.trans.sa_session.scalars(select(model.Dataset)).all()
Expand All @@ -60,7 +60,7 @@ def test_base(self):
assert self.dataset_manager.list(order_by=sqlalchemy.desc(model.Dataset.create_time)) == [dataset2, dataset1]

def test_delete(self):
item1 = self.dataset_manager.create()
item1 = self.dataset_manager.create_for_unit_testing()

self.log("should be able to delete and undelete a dataset")
assert not item1.deleted
Expand All @@ -71,7 +71,7 @@ def test_delete(self):

def test_purge_allowed(self):
self.trans.app.config.allow_user_dataset_purge = True
item1 = self.dataset_manager.create()
item1 = self.dataset_manager.create_for_unit_testing()

self.log("should purge a dataset if config does allow")
assert not item1.purged
Expand All @@ -83,7 +83,7 @@ def test_purge_allowed(self):

def test_purge_not_allowed(self):
self.trans.app.config.allow_user_dataset_purge = False
item1 = self.dataset_manager.create()
item1 = self.dataset_manager.create_for_unit_testing()

self.log("should raise an error when purging a dataset if config does not allow")
assert not item1.purged
Expand All @@ -93,7 +93,7 @@ def test_purge_not_allowed(self):

def test_create_with_no_permissions(self):
self.log("should be able to create a new Dataset without any permissions")
dataset = self.dataset_manager.create()
dataset = self.dataset_manager.create_for_unit_testing()

permissions = self.dataset_manager.permissions.get(dataset)
assert isinstance(permissions, tuple)
Expand Down Expand Up @@ -125,7 +125,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.dataset_manager.create_for_unit_testing(manage_roles=[owner_private_role])

permissions = self.dataset_manager.permissions.get(dataset)
assert isinstance(permissions, tuple)
Expand Down Expand Up @@ -157,7 +157,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.dataset_manager.create_for_unit_testing(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 @@ -199,7 +199,7 @@ def set_up_managers(self):
self.role_manager = RoleManager(self.app)

def test_views(self):
dataset = self.dataset_manager.create()
dataset = self.dataset_manager.create_for_unit_testing()

self.log("should have a summary view")
summary_view = self.dataset_serializer.serialize_to_view(dataset, view="summary")
Expand All @@ -217,7 +217,7 @@ def test_views(self):
), f"No serializer for: {key} ({instantiated_attribute})"

def test_views_and_keys(self):
dataset = self.dataset_manager.create()
dataset = self.dataset_manager.create_for_unit_testing()

self.log("should be able to use keys with views")
serialized = self.dataset_serializer.serialize_to_view(
Expand All @@ -233,7 +233,7 @@ def test_views_and_keys(self):
self.assertKeys(serialized, ["purgable", "file_size"])

def test_serialize_permissions(self):
dataset = self.dataset_manager.create()
dataset = self.dataset_manager.create_for_unit_testing()
who_manages = self.user_manager.create(**user2_data)
self.dataset_manager.permissions.manage.grant(dataset, who_manages)

Expand Down Expand Up @@ -268,7 +268,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_for_unit_testing()
all_keys = list(self.dataset_serializer.serializable_keyset)
serialized = self.dataset_serializer.serialize(dataset, all_keys)

Expand Down

0 comments on commit 894970e

Please sign in to comment.