Skip to content

Commit

Permalink
Refactor model fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Mar 4, 2024
1 parent cc1af5e commit a3bde5f
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions test/unit/data/data_access/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ def f(**kwd):
@pytest.fixture
def make_dataset_collection_element(session, make_hda):
def f(**kwd):
if "element" not in kwd:
kwd["element"] = make_hda()
kwd["element"] = kwd.get("element", make_hda())
dce = m.DatasetCollectionElement(**kwd)
with transaction(session):
session.add(dce)
Expand All @@ -123,8 +122,7 @@ def f(**kwd):
@pytest.fixture
def make_history(session, make_user):
def f(**kwd):
if "user" not in kwd:
kwd["user"] = make_user()
kwd["user"] = kwd.get("user", make_user())
history = m.History(**kwd)
with transaction(session):
session.add(history)
Expand All @@ -137,8 +135,7 @@ def f(**kwd):
@pytest.fixture
def make_hda(session, make_history):
def f(**kwd):
if "history" not in kwd:
kwd["history"] = make_history()
kwd["history"] = kwd.get("history", make_history())
hda = m.HistoryDatasetAssociation(**kwd)
with transaction(session):
session.add(hda)
Expand Down Expand Up @@ -199,9 +196,9 @@ def f(**kwd):
@pytest.fixture
def make_library_permissions(session, make_library, make_role):
def f(**kwd):
action = kwd.get("action") or random_str()
library = kwd.get("library") or make_library()
role = kwd.get("role") or make_role()
action = kwd.get("action", random_str())
library = kwd.get("library", make_library())
role = kwd.get("role", make_role())
lp = m.LibraryPermissions(action, library, role)
with transaction(session):
session.add(lp)
Expand All @@ -214,8 +211,7 @@ def f(**kwd):
@pytest.fixture
def make_page(session, make_user):
def f(**kwd):
if "user" not in kwd:
kwd["user"] = make_user()
kwd["user"] = kwd.get("user", make_user())
page = m.Page(**kwd)
with transaction(session):
session.add(page)
Expand All @@ -240,8 +236,7 @@ def f(**kwd):
@pytest.fixture
def make_stored_workflow(session, make_user):
def f(**kwd):
if "user" not in kwd:
kwd["user"] = make_user()
kwd["user"] = kwd.get("user", make_user())
sw = m.StoredWorkflow(**kwd)
with transaction(session):
session.add(sw)
Expand All @@ -254,12 +249,9 @@ def f(**kwd):
@pytest.fixture
def make_user(session):
def f(**kwd):
if "username" not in kwd:
kwd["username"] = random_email()
if "email" not in kwd:
kwd["email"] = random_email()
if "password" not in kwd:
kwd["password"] = random_str()
kwd["username"] = kwd.get("username", random_str())
kwd["email"] = kwd.get("email", random_email())
kwd["password"] = kwd.get("password", random_str())
user = m.User(**kwd)
with transaction(session):
session.add(user)
Expand Down Expand Up @@ -296,8 +288,7 @@ def f(user, role):
@pytest.fixture
def make_visualization(session, make_user):
def f(**kwd):
if "user" not in kwd:
kwd["user"] = make_user()
kwd["user"] = kwd.get("user", make_user())
vis = m.Visualization(**kwd)
with transaction(session):
session.add(vis)
Expand Down

0 comments on commit a3bde5f

Please sign in to comment.