From a3bde5f70d810cbdb6d41fcf2d7b375cededb563 Mon Sep 17 00:00:00 2001 From: John Davis Date: Mon, 4 Mar 2024 17:47:36 -0500 Subject: [PATCH] Refactor model fixtures --- test/unit/data/data_access/conftest.py | 33 ++++++++++---------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/test/unit/data/data_access/conftest.py b/test/unit/data/data_access/conftest.py index ad6840e8bfa9..2a38757c65ec 100644 --- a/test/unit/data/data_access/conftest.py +++ b/test/unit/data/data_access/conftest.py @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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)