From bfc96f0a1f4f462ce7586ded8e0416104a0077cf Mon Sep 17 00:00:00 2001 From: Mohamed Abdel Wedoud Date: Tue, 26 Mar 2024 17:36:56 +0100 Subject: [PATCH] fix(study-search): update pagination query regarding joins on groups and tags --- antarest/study/repository.py | 23 +- .../studies_blueprint/test_get_studies.py | 148 +++-- tests/study/test_repository.py | 623 +++++++++--------- 3 files changed, 408 insertions(+), 386 deletions(-) diff --git a/antarest/study/repository.py b/antarest/study/repository.py index 93237ff850..0674f396a7 100644 --- a/antarest/study/repository.py +++ b/antarest/study/repository.py @@ -257,9 +257,17 @@ def get_all( # pagination if pagination.page_nb or pagination.page_size: - q = q.offset(pagination.page_nb * pagination.page_size).limit(pagination.page_size) - - studies: t.Sequence[Study] = q.all() + limit = pagination.page_size + offset = pagination.page_nb * pagination.page_size + end = offset + limit + if sort_by is None: + q = q.order_by(entity.name.asc()) + if study_filter.groups or study_filter.tags: + studies: t.Sequence[Study] = q.all()[offset:end] + return studies + q = q.offset(offset).limit(limit) + + studies = q.all() return studies def count_studies(self, study_filter: StudyFilter = StudyFilter()) -> int: @@ -305,12 +313,9 @@ def _search_studies( else: q = q.filter(not_(RawStudy.missing.is_(None))) - if study_filter.users is not None: - q = q.options(joinedload(entity.owner)) - if study_filter.groups is not None: - q = q.options(joinedload(entity.groups)) - if study_filter.tags is not None: - q = q.options(joinedload(entity.tags)) + q = q.options(joinedload(entity.owner)) + q = q.options(joinedload(entity.groups)) + q = q.options(joinedload(entity.tags)) q = q.options(joinedload(entity.additional_data)) if study_filter.managed is not None: diff --git a/tests/integration/studies_blueprint/test_get_studies.py b/tests/integration/studies_blueprint/test_get_studies.py index 2cff53f047..af8f790f20 100644 --- a/tests/integration/studies_blueprint/test_get_studies.py +++ b/tests/integration/studies_blueprint/test_get_studies.py @@ -926,7 +926,7 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ res = client.post( STUDIES_URL, headers={"Authorization": f"Bearer {admin_access_token}"}, - params={"name": f"dummy_{study}"}, + params={"name": f"dummy_{study[6:]}"}, ) assert res.status_code in CREATE_STATUS_CODES, res.json() study_id = res.json() @@ -953,13 +953,13 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ assert res.status_code == 200, res.json() # studies that have owner but no groups for study, study_info in { - "study_10": {"owner": "user_1"}, - "study_11": {"owner": "user_2"}, + "study_X10": {"owner": "user_1"}, + "study_X11": {"owner": "user_2"}, }.items(): res = client.post( STUDIES_URL, headers={"Authorization": f"Bearer {admin_access_token}"}, - params={"name": f"dummy_{study}"}, + params={"name": f"dummy_{study[6:]}"}, ) assert res.status_code in CREATE_STATUS_CODES, res.json() study_id = res.json() @@ -986,7 +986,7 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ res = client.post( STUDIES_URL, headers={"Authorization": f"Bearer {admin_access_token}"}, - params={"name": f"dummy_{study}"}, + params={"name": f"dummy_{study[6:]}"}, ) assert res.status_code in CREATE_STATUS_CODES, res.json() study_id = res.json() @@ -1008,16 +1008,16 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ # create variant studies with neither owner nor groups for study, study_info in { - "study_12": {"public_mode": None}, - "study_13": {"public_mode": PublicMode.READ.value}, - "study_14": {"public_mode": PublicMode.EDIT.value}, - "study_15": {"public_mode": PublicMode.EXECUTE.value}, - "study_16": {"public_mode": PublicMode.FULL.value}, + "study_X12": {"public_mode": None}, + "study_X13": {"public_mode": PublicMode.READ.value}, + "study_X14": {"public_mode": PublicMode.EDIT.value}, + "study_X15": {"public_mode": PublicMode.EXECUTE.value}, + "study_X16": {"public_mode": PublicMode.FULL.value}, }.items(): res = client.post( STUDIES_URL, headers={"Authorization": f"Bearer {admin_access_token}"}, - params={"name": f"dummy_{study}"}, + params={"name": f"dummy_{study[6:]}"}, ) assert res.status_code in CREATE_STATUS_CODES, res.json() study_id = res.json() @@ -1040,12 +1040,12 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ # create raw studies for user_1 and user_2 that are part of some groups # studies that have owner and groups for study, study_info in { - "study_17": {"owner": "user_1", "groups": ["group_1"]}, - "study_18": {"owner": "user_1", "groups": ["group_2"]}, - "study_20": {"owner": "user_2", "groups": ["group_1"]}, - "study_21": {"owner": "user_2", "groups": ["group_2"]}, - "study_23": {"owner": "user_1", "groups": ["group_1", "group_2"]}, - "study_24": {"owner": "user_2", "groups": ["group_1", "group_2"]}, + "study_X17": {"owner": "user_1", "groups": ["group_1"]}, + "study_X18": {"owner": "user_1", "groups": ["group_2"]}, + "study_X20": {"owner": "user_2", "groups": ["group_1"]}, + "study_X21": {"owner": "user_2", "groups": ["group_2"]}, + "study_X23": {"owner": "user_1", "groups": ["group_1", "group_2"]}, + "study_X24": {"owner": "user_2", "groups": ["group_1", "group_2"]}, }.items(): res = client.post( STUDIES_URL, @@ -1070,8 +1070,8 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ assert res.status_code == 200, res.json() # studies that have owner but no groups for study, study_info in { - "study_26": {"owner": "user_1"}, - "study_27": {"owner": "user_2"}, + "study_X26": {"owner": "user_1"}, + "study_X27": {"owner": "user_2"}, }.items(): res = client.post( STUDIES_URL, @@ -1089,9 +1089,9 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ assert res.status_code == 200, res.json() # studies that have groups but no owner for study, study_info in { - "study_19": {"groups": ["group_1"]}, - "study_22": {"groups": ["group_2"]}, - "study_25": {"groups": ["group_1", "group_2"]}, + "study_X19": {"groups": ["group_1"]}, + "study_X22": {"groups": ["group_2"]}, + "study_X25": {"groups": ["group_1", "group_2"]}, }.items(): res = client.post( STUDIES_URL, @@ -1111,11 +1111,11 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ # create raw studies with neither owner nor groups for study, study_info in { - "study_28": {"public_mode": None}, - "study_29": {"public_mode": PublicMode.READ.value}, - "study_30": {"public_mode": PublicMode.EDIT.value}, - "study_31": {"public_mode": PublicMode.EXECUTE.value}, - "study_32": {"public_mode": PublicMode.FULL.value}, + "study_X28": {"public_mode": None}, + "study_X29": {"public_mode": PublicMode.READ.value}, + "study_X30": {"public_mode": PublicMode.EDIT.value}, + "study_X31": {"public_mode": PublicMode.EXECUTE.value}, + "study_X32": {"public_mode": PublicMode.FULL.value}, }.items(): res = client.post( STUDIES_URL, @@ -1136,13 +1136,13 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ # create studies for user_3 that is not part of any group # variant studies for study, study_info in { - "study_33": {"groups": ["group_1"]}, - "study_35": {"groups": []}, + "study_X33": {"groups": ["group_1"]}, + "study_X35": {"groups": []}, }.items(): res = client.post( STUDIES_URL, headers={"Authorization": f"Bearer {admin_access_token}"}, - params={"name": f"dummy_{study}"}, + params={"name": f"dummy_{study[6:]}"}, ) assert res.status_code in CREATE_STATUS_CODES, res.json() study_id = res.json() @@ -1169,8 +1169,8 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ assert res.status_code == 200, res.json() # raw studies for study, study_info in { - "study_34": {"groups": ["group_2"]}, - "study_36": {"groups": []}, + "study_X34": {"groups": ["group_2"]}, + "study_X36": {"groups": []}, }.items(): res = client.post( STUDIES_URL, @@ -1198,14 +1198,14 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ res = client.post( STUDIES_URL, headers={"Authorization": f"Bearer {admin_access_token}"}, - params={"name": "dummy_study_37"}, + params={"name": "dummy_37"}, ) assert res.status_code in CREATE_STATUS_CODES, res.json() study_id = res.json() res = client.post( f"{STUDIES_URL}/{study_id}/variants", headers={"Authorization": f"Bearer {admin_access_token}"}, - params={"name": "study_37"}, + params={"name": "study_X37"}, ) assert res.status_code in CREATE_STATUS_CODES, res.json() study_id = res.json() @@ -1215,11 +1215,11 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ headers={"Authorization": f"Bearer {admin_access_token}"}, ) assert res.status_code == 200, res.json() - studies_ids_mapping["study_37"] = study_id + studies_ids_mapping["study_X37"] = study_id res = client.post( STUDIES_URL, headers={"Authorization": f"Bearer {admin_access_token}"}, - params={"name": "study_38"}, + params={"name": "study_X38"}, ) assert res.status_code in CREATE_STATUS_CODES, res.json() study_id = res.json() @@ -1228,7 +1228,7 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ headers={"Authorization": f"Bearer {admin_access_token}"}, ) assert res.status_code == 200, res.json() - studies_ids_mapping["study_38"] = study_id + studies_ids_mapping["study_X38"] = study_id # verify the studies creation was done correctly and that admin has access to all studies all_studies = set(studies_ids_mapping.values()) @@ -1277,55 +1277,55 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ "groups": ["group_1", "group_2"], "public_mode": PublicMode.NONE, }, - "study_10": {"type": "variantstudy", "owner": "user_1", "groups": None, "public_mode": PublicMode.NONE}, - "study_11": {"type": "variantstudy", "owner": "user_2", "groups": None, "public_mode": PublicMode.NONE}, - "study_12": {"type": "variantstudy", "owner": None, "groups": None, "public_mode": PublicMode.NONE}, - "study_13": {"type": "variantstudy", "owner": None, "groups": None, "public_mode": PublicMode.READ}, - "study_14": {"type": "variantstudy", "owner": None, "groups": None, "public_mode": PublicMode.EDIT}, - "study_15": {"type": "variantstudy", "owner": None, "groups": None, "public_mode": PublicMode.EXECUTE}, - "study_16": {"type": "variantstudy", "owner": None, "groups": None, "public_mode": PublicMode.FULL}, - "study_17": {"type": "rawstudy", "owner": "user_1", "groups": ["group_1"], "public_mode": PublicMode.NONE}, - "study_18": {"type": "rawstudy", "owner": "user_1", "groups": ["group_2"], "public_mode": PublicMode.NONE}, - "study_19": {"type": "rawstudy", "owner": None, "groups": ["group_1"], "public_mode": PublicMode.NONE}, - "study_20": {"type": "rawstudy", "owner": "user_2", "groups": ["group_1"], "public_mode": PublicMode.NONE}, - "study_21": {"type": "rawstudy", "owner": "user_2", "groups": ["group_2"], "public_mode": PublicMode.NONE}, - "study_22": {"type": "rawstudy", "owner": None, "groups": ["group_2"], "public_mode": PublicMode.NONE}, - "study_23": { + "study_X10": {"type": "variantstudy", "owner": "user_1", "groups": None, "public_mode": PublicMode.NONE}, + "study_X11": {"type": "variantstudy", "owner": "user_2", "groups": None, "public_mode": PublicMode.NONE}, + "study_X12": {"type": "variantstudy", "owner": None, "groups": None, "public_mode": PublicMode.NONE}, + "study_X13": {"type": "variantstudy", "owner": None, "groups": None, "public_mode": PublicMode.READ}, + "study_X14": {"type": "variantstudy", "owner": None, "groups": None, "public_mode": PublicMode.EDIT}, + "study_X15": {"type": "variantstudy", "owner": None, "groups": None, "public_mode": PublicMode.EXECUTE}, + "study_X16": {"type": "variantstudy", "owner": None, "groups": None, "public_mode": PublicMode.FULL}, + "study_X17": {"type": "rawstudy", "owner": "user_1", "groups": ["group_1"], "public_mode": PublicMode.NONE}, + "study_X18": {"type": "rawstudy", "owner": "user_1", "groups": ["group_2"], "public_mode": PublicMode.NONE}, + "study_X19": {"type": "rawstudy", "owner": None, "groups": ["group_1"], "public_mode": PublicMode.NONE}, + "study_X20": {"type": "rawstudy", "owner": "user_2", "groups": ["group_1"], "public_mode": PublicMode.NONE}, + "study_X21": {"type": "rawstudy", "owner": "user_2", "groups": ["group_2"], "public_mode": PublicMode.NONE}, + "study_X22": {"type": "rawstudy", "owner": None, "groups": ["group_2"], "public_mode": PublicMode.NONE}, + "study_X23": { "type": "rawstudy", "owner": "user_1", "groups": ["group_1", "group_2"], "public_mode": PublicMode.NONE, }, - "study_24": { + "study_X24": { "type": "rawstudy", "owner": "user_2", "groups": ["group_1", "group_2"], "public_mode": PublicMode.NONE, }, - "study_25": { + "study_X25": { "type": "rawstudy", "owner": None, "groups": ["group_1", "group_2"], "public_mode": PublicMode.NONE, }, - "study_26": {"type": "rawstudy", "owner": "user_1", "groups": None, "public_mode": PublicMode.NONE}, - "study_27": {"type": "rawstudy", "owner": "user_2", "groups": None, "public_mode": PublicMode.NONE}, - "study_28": {"type": "rawstudy", "owner": None, "groups": None, "public_mode": PublicMode.NONE}, - "study_29": {"type": "rawstudy", "owner": None, "groups": None, "public_mode": PublicMode.READ}, - "study_30": {"type": "rawstudy", "owner": None, "groups": None, "public_mode": PublicMode.EDIT}, - "study_31": {"type": "rawstudy", "owner": None, "groups": None, "public_mode": PublicMode.EXECUTE}, - "study_32": {"type": "rawstudy", "owner": None, "groups": None, "public_mode": PublicMode.FULL}, - "study_33": { + "study_X26": {"type": "rawstudy", "owner": "user_1", "groups": None, "public_mode": PublicMode.NONE}, + "study_X27": {"type": "rawstudy", "owner": "user_2", "groups": None, "public_mode": PublicMode.NONE}, + "study_X28": {"type": "rawstudy", "owner": None, "groups": None, "public_mode": PublicMode.NONE}, + "study_X29": {"type": "rawstudy", "owner": None, "groups": None, "public_mode": PublicMode.READ}, + "study_X30": {"type": "rawstudy", "owner": None, "groups": None, "public_mode": PublicMode.EDIT}, + "study_X31": {"type": "rawstudy", "owner": None, "groups": None, "public_mode": PublicMode.EXECUTE}, + "study_X32": {"type": "rawstudy", "owner": None, "groups": None, "public_mode": PublicMode.FULL}, + "study_X33": { "type": "variantstudy", "owner": "user_3", "groups": ["group_1"], "public_mode": PublicMode.NONE, }, - "study_34": {"type": "rawstudy", "owner": "user_3", "groups": ["group_2"], "public_mode": PublicMode.NONE}, - "study_35": {"type": "variantstudy", "owner": "user_3", "groups": None, "public_mode": PublicMode.NONE}, - "study_36": {"type": "rawstudy", "owner": "user_3", "groups": None, "public_mode": PublicMode.NONE}, - "study_37": {"type": "variantstudy", "owner": None, "groups": ["group_3"], "public_mode": PublicMode.NONE}, - "study_38": {"type": "rawstudy", "owner": None, "groups": ["group_3"], "public_mode": PublicMode.NONE}, + "study_X34": {"type": "rawstudy", "owner": "user_3", "groups": ["group_2"], "public_mode": PublicMode.NONE}, + "study_X35": {"type": "variantstudy", "owner": "user_3", "groups": None, "public_mode": PublicMode.NONE}, + "study_X36": {"type": "rawstudy", "owner": "user_3", "groups": None, "public_mode": PublicMode.NONE}, + "study_X37": {"type": "variantstudy", "owner": None, "groups": ["group_3"], "public_mode": PublicMode.NONE}, + "study_X38": {"type": "rawstudy", "owner": None, "groups": ["group_3"], "public_mode": PublicMode.NONE}, } res = client.get(STUDIES_URL, headers={"Authorization": f"Bearer {admin_access_token}"}) assert res.status_code == LIST_STATUS_CODE, res.json() @@ -1375,9 +1375,10 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ ] for request_groups_numbers, expected_studies_numbers in requests_params_expected_studies: request_groups_ids = [groups_ids[f"group_{group_number}"] for group_number in request_groups_numbers] - expected_studies = { - studies_ids_mapping[f"study_{study_number}"] for study_number in expected_studies_numbers - } + expected_studies = [ + studies_ids_mapping[f"study_{(study_number if int(study_number) <= 9 else 'X'+study_number)}"] + for study_number in expected_studies_numbers + ] res = client.get( STUDIES_URL, headers={"Authorization": f"Bearer {users_tokens['user_1']}"}, @@ -1385,7 +1386,7 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ ) assert res.status_code == LIST_STATUS_CODE, res.json() study_map = res.json() - assert not expected_studies.difference(set(study_map)) + assert not set(expected_studies).difference(set(study_map)) assert not all_studies.difference(expected_studies).intersection(set(study_map)) # test pagination res = client.get( @@ -1397,6 +1398,7 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ ) assert res.status_code == LIST_STATUS_CODE, res.json() assert len(res.json()) == max(0, min(2, len(expected_studies) - 2)) + # assert list(res.json()) == expected_studies[2:4] # user_2 access requests_params_expected_studies = [ @@ -1418,7 +1420,8 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ for request_groups_numbers, expected_studies_numbers in requests_params_expected_studies: request_groups_ids = [groups_ids[f"group_{group_number}"] for group_number in request_groups_numbers] expected_studies = { - studies_ids_mapping[f"study_{study_number}"] for study_number in expected_studies_numbers + studies_ids_mapping[f"study_{(study_number if int(study_number) <= 9 else 'X'+study_number)}"] + for study_number in expected_studies_numbers } res = client.get( STUDIES_URL, @@ -1444,7 +1447,8 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ for request_groups_numbers, expected_studies_numbers in requests_params_expected_studies: request_groups_ids = [groups_ids[f"group_{group_number}"] for group_number in request_groups_numbers] expected_studies = { - studies_ids_mapping[f"study_{study_number}"] for study_number in expected_studies_numbers + studies_ids_mapping[f"study_{(study_number if int(study_number) <= 9 else 'X'+study_number)}"] + for study_number in expected_studies_numbers } res = client.get( STUDIES_URL, diff --git a/tests/study/test_repository.py b/tests/study/test_repository.py index e6becac349..f7314cdaaa 100644 --- a/tests/study/test_repository.py +++ b/tests/study/test_repository.py @@ -128,14 +128,14 @@ def test_get_all__incompatible_case( icache: Mock = Mock(spec=ICache) repository = StudyMetadataRepository(cache_service=icache, session=db_session) - study_1 = VariantStudy(id=1) - study_2 = VariantStudy(id=2) - study_3 = VariantStudy(id=3) - study_4 = VariantStudy(id=4) - study_5 = RawStudy(id=5, missing=datetime.datetime.now(), workspace=DEFAULT_WORKSPACE_NAME) - study_6 = RawStudy(id=6, missing=datetime.datetime.now(), workspace=test_workspace) - study_7 = RawStudy(id=7, missing=None, workspace=test_workspace) - study_8 = RawStudy(id=8, missing=None, workspace=DEFAULT_WORKSPACE_NAME) + study_1 = VariantStudy(id=1, name="study-1") + study_2 = VariantStudy(id=2, name="study-2") + study_3 = VariantStudy(id=3, name="study-3") + study_4 = VariantStudy(id=4, name="study-4") + study_5 = RawStudy(id=5, name="study-5", missing=datetime.datetime.now(), workspace=DEFAULT_WORKSPACE_NAME) + study_6 = RawStudy(id=6, name="study-6", missing=datetime.datetime.now(), workspace=test_workspace) + study_7 = RawStudy(id=7, name="study-7", missing=None, workspace=test_workspace) + study_8 = RawStudy(id=8, name="study-8", missing=None, workspace=DEFAULT_WORKSPACE_NAME) db_session.add_all([study_1, study_2, study_3, study_4, study_5, study_6, study_7, study_8]) db_session.commit() @@ -179,21 +179,21 @@ def test_get_all__incompatible_case( @pytest.mark.parametrize( "name, expected_ids", [ - ("", {"1", "2", "3", "4", "5", "6", "7", "8"}), - ("specie", {"1", "2", "3", "4", "5", "6", "7", "8"}), - ("prefix-specie", {"2", "3", "6", "7"}), - ("variant", {"1", "2", "3", "4"}), - ("variant-suffix", {"3", "4"}), - ("raw", {"5", "6", "7", "8"}), - ("raw-suffix", {"7", "8"}), - ("prefix-variant", set()), - ("specie-suffix", set()), + ("", ["1", "2", "3", "4", "5", "6", "7", "8"]), + ("specie", ["1", "2", "3", "4", "5", "6", "7", "8"]), + ("prefix-specie", ["2", "3", "6", "7"]), + ("variant", ["1", "2", "3", "4"]), + ("variant-suffix", ["3", "4"]), + ("raw", ["5", "6", "7", "8"]), + ("raw-suffix", ["7", "8"]), + ("prefix-variant", []), + ("specie-suffix", []), ], ) def test_get_all__study_name_filter( db_session: Session, name: str, - expected_ids: t.Set[str], + expected_ids: t.List[str], ) -> None: icache: Mock = Mock(spec=ICache) repository = StudyMetadataRepository(cache_service=icache, session=db_session) @@ -207,6 +207,10 @@ def test_get_all__study_name_filter( study_7 = RawStudy(id=7, name="prefix-specie-raw-suffix") study_8 = RawStudy(id=8, name="specie-raw-suffix") + mapping_ids_names = { + str(s.id): s.name for s in [study_1, study_2, study_3, study_4, study_5, study_6, study_7, study_8] + } + db_session.add_all([study_1, study_2, study_3, study_4, study_5, study_6, study_7, study_8]) db_session.commit() @@ -225,7 +229,7 @@ def test_get_all__study_name_filter( assert len(db_recorder.sql_statements) == 1, str(db_recorder) if expected_ids is not None: - assert {s.id for s in all_studies} == expected_ids + assert sorted(s.id for s in all_studies) == expected_ids # test pagination with DBStatementRecorder(db_session.bind) as db_recorder: @@ -234,34 +238,36 @@ def test_get_all__study_name_filter( pagination=StudyPagination(page_nb=1, page_size=2), ) assert len(all_studies) == max(0, min(len(expected_ids) - 2, 2)) + name_sorted_expected_studies = sorted(expected_ids, key=lambda s_id: mapping_ids_names[s_id]) + assert sorted(s.id for s in all_studies) == name_sorted_expected_studies[2:4] assert len(db_recorder.sql_statements) == 1, str(db_recorder) @pytest.mark.parametrize( "managed, expected_ids", [ - (None, {"1", "2", "3", "4", "5", "6", "7", "8"}), - (True, {"1", "2", "3", "4", "5", "8"}), - (False, {"6", "7"}), + (None, ["1", "2", "3", "4", "5", "6", "7", "8"]), + (True, ["1", "2", "3", "4", "5", "8"]), + (False, ["6", "7"]), ], ) def test_get_all__managed_study_filter( db_session: Session, managed: t.Optional[bool], - expected_ids: t.Set[str], + expected_ids: t.List[str], ) -> None: test_workspace = "test-workspace" icache: Mock = Mock(spec=ICache) repository = StudyMetadataRepository(cache_service=icache, session=db_session) - study_1 = VariantStudy(id=1) - study_2 = VariantStudy(id=2) - study_3 = VariantStudy(id=3) - study_4 = VariantStudy(id=4) - study_5 = RawStudy(id=5, workspace=DEFAULT_WORKSPACE_NAME) - study_6 = RawStudy(id=6, workspace=test_workspace) - study_7 = RawStudy(id=7, workspace=test_workspace) - study_8 = RawStudy(id=8, workspace=DEFAULT_WORKSPACE_NAME) + study_1 = VariantStudy(id=1, name="study-1") + study_2 = VariantStudy(id=2, name="study-2") + study_3 = VariantStudy(id=3, name="study-3") + study_4 = VariantStudy(id=4, name="study-4") + study_5 = RawStudy(id=5, name="study-5", workspace=DEFAULT_WORKSPACE_NAME) + study_6 = RawStudy(id=6, name="study-6", workspace=test_workspace) + study_7 = RawStudy(id=7, name="study-7", workspace=test_workspace) + study_8 = RawStudy(id=8, name="study-8", workspace=DEFAULT_WORKSPACE_NAME) db_session.add_all([study_1, study_2, study_3, study_4, study_5, study_6, study_7, study_8]) db_session.commit() @@ -281,7 +287,7 @@ def test_get_all__managed_study_filter( assert len(db_recorder.sql_statements) == 1, str(db_recorder) if expected_ids is not None: - assert {s.id for s in all_studies} == expected_ids + assert sorted(s.id for s in all_studies) == expected_ids # test pagination with DBStatementRecorder(db_session.bind) as db_recorder: @@ -290,29 +296,30 @@ def test_get_all__managed_study_filter( pagination=StudyPagination(page_nb=1, page_size=2), ) assert len(all_studies) == max(0, min(len(expected_ids) - 2, 2)) + assert sorted(s.id for s in all_studies) == expected_ids[2:4] assert len(db_recorder.sql_statements) == 1, str(db_recorder) @pytest.mark.parametrize( "archived, expected_ids", [ - (None, {"1", "2", "3", "4"}), - (True, {"1", "3"}), - (False, {"2", "4"}), + (None, ["1", "2", "3", "4"]), + (True, ["1", "3"]), + (False, ["2", "4"]), ], ) def test_get_all__archived_study_filter( db_session: Session, archived: t.Optional[bool], - expected_ids: t.Set[str], + expected_ids: t.List[str], ) -> None: icache: Mock = Mock(spec=ICache) repository = StudyMetadataRepository(cache_service=icache, session=db_session) - study_1 = VariantStudy(id=1, archived=True) - study_2 = VariantStudy(id=2, archived=False) - study_3 = RawStudy(id=3, archived=True) - study_4 = RawStudy(id=4, archived=False) + study_1 = VariantStudy(id=1, name="study-1", archived=True) + study_2 = VariantStudy(id=2, name="study-2", archived=False) + study_3 = RawStudy(id=3, name="study-3", archived=True) + study_4 = RawStudy(id=4, name="study-4", archived=False) db_session.add_all([study_1, study_2, study_3, study_4]) db_session.commit() @@ -331,7 +338,7 @@ def test_get_all__archived_study_filter( assert len(db_recorder.sql_statements) == 1, str(db_recorder) if expected_ids is not None: - assert {s.id for s in all_studies} == expected_ids + assert sorted(s.id for s in all_studies) == expected_ids # test pagination with DBStatementRecorder(db_session.bind) as db_recorder: @@ -346,23 +353,23 @@ def test_get_all__archived_study_filter( @pytest.mark.parametrize( "variant, expected_ids", [ - (None, {"1", "2", "3", "4"}), - (True, {"1", "2"}), - (False, {"3", "4"}), + (None, ["1", "2", "3", "4"]), + (True, ["1", "2"]), + (False, ["3", "4"]), ], ) def test_get_all__variant_study_filter( db_session: Session, variant: t.Optional[bool], - expected_ids: t.Set[str], + expected_ids: t.List[str], ) -> None: icache: Mock = Mock(spec=ICache) repository = StudyMetadataRepository(cache_service=icache, session=db_session) - study_1 = VariantStudy(id=1) - study_2 = VariantStudy(id=2) - study_3 = RawStudy(id=3) - study_4 = RawStudy(id=4) + study_1 = VariantStudy(id=1, name="study-1") + study_2 = VariantStudy(id=2, name="study-2") + study_3 = RawStudy(id=3, name="study-3") + study_4 = RawStudy(id=4, name="study-4") db_session.add_all([study_1, study_2, study_3, study_4]) db_session.commit() @@ -381,7 +388,7 @@ def test_get_all__variant_study_filter( assert len(db_recorder.sql_statements) == 1, str(db_recorder) if expected_ids is not None: - assert {s.id for s in all_studies} == expected_ids + assert sorted(s.id for s in all_studies) == expected_ids # test pagination with DBStatementRecorder(db_session.bind) as db_recorder: @@ -396,25 +403,25 @@ def test_get_all__variant_study_filter( @pytest.mark.parametrize( "versions, expected_ids", [ - ([], {"1", "2", "3", "4"}), - (["1", "2"], {"1", "2", "3", "4"}), - (["1"], {"1", "3"}), - (["2"], {"2", "4"}), - (["3"], set()), + ([], ["1", "2", "3", "4"]), + (["1", "2"], ["1", "2", "3", "4"]), + (["1"], ["1", "3"]), + (["2"], ["2", "4"]), + (["3"], []), ], ) def test_get_all__study_version_filter( db_session: Session, versions: t.Sequence[str], - expected_ids: t.Set[str], + expected_ids: t.List[str], ) -> None: icache: Mock = Mock(spec=ICache) repository = StudyMetadataRepository(cache_service=icache, session=db_session) - study_1 = VariantStudy(id=1, version="1") - study_2 = VariantStudy(id=2, version="2") - study_3 = RawStudy(id=3, version="1") - study_4 = RawStudy(id=4, version="2") + study_1 = VariantStudy(id=1, name="study-1", version="1") + study_2 = VariantStudy(id=2, name="study-2", version="2") + study_3 = RawStudy(id=3, name="study-3", version="1") + study_4 = RawStudy(id=4, name="study-4", version="2") db_session.add_all([study_1, study_2, study_3, study_4]) db_session.commit() @@ -433,7 +440,7 @@ def test_get_all__study_version_filter( assert len(db_recorder.sql_statements) == 1, str(db_recorder) if expected_ids is not None: - assert {s.id for s in all_studies} == expected_ids + assert sorted(s.id for s in all_studies) == expected_ids # test pagination with DBStatementRecorder(db_session.bind) as db_recorder: @@ -448,17 +455,17 @@ def test_get_all__study_version_filter( @pytest.mark.parametrize( "users, expected_ids", [ - ([], {"1", "2", "3", "4"}), - (["1000", "2000"], {"1", "2", "3", "4"}), - (["1000"], {"1", "3"}), - (["2000"], {"2", "4"}), - (["3000"], set()), + ([], ["1", "2", "3", "4"]), + (["1000", "2000"], ["1", "2", "3", "4"]), + (["1000"], ["1", "3"]), + (["2000"], ["2", "4"]), + (["3000"], []), ], ) def test_get_all__study_users_filter( db_session: Session, users: t.Sequence["int"], - expected_ids: t.Set[str], + expected_ids: t.List[str], ) -> None: icache: Mock = Mock(spec=ICache) repository = StudyMetadataRepository(cache_service=icache, session=db_session) @@ -466,10 +473,10 @@ def test_get_all__study_users_filter( test_user_1 = User(id=1000) test_user_2 = User(id=2000) - study_1 = VariantStudy(id=1, owner=test_user_1) - study_2 = VariantStudy(id=2, owner=test_user_2) - study_3 = RawStudy(id=3, owner=test_user_1) - study_4 = RawStudy(id=4, owner=test_user_2) + study_1 = VariantStudy(id=1, name="study-1", owner=test_user_1) + study_2 = VariantStudy(id=2, name="study-2", owner=test_user_2) + study_3 = RawStudy(id=3, name="study-3", owner=test_user_1) + study_4 = RawStudy(id=4, name="study-4", owner=test_user_2) db_session.add_all([test_user_1, test_user_2]) db_session.commit() @@ -492,7 +499,7 @@ def test_get_all__study_users_filter( assert len(db_recorder.sql_statements) == 1, str(db_recorder) if expected_ids is not None: - assert {s.id for s in all_studies} == expected_ids + assert sorted(s.id for s in all_studies) == expected_ids # test pagination with DBStatementRecorder(db_session.bind) as db_recorder: @@ -501,23 +508,24 @@ def test_get_all__study_users_filter( pagination=StudyPagination(page_nb=1, page_size=2), ) assert len(all_studies) == max(0, min(len(expected_ids) - 2, 2)) + assert sorted(s.id for s in all_studies) == expected_ids[2:4] assert len(db_recorder.sql_statements) == 1, str(db_recorder) @pytest.mark.parametrize( "groups, expected_ids", [ - ([], {"1", "2", "3", "4"}), - (["1000", "2000"], {"1", "2", "3", "4"}), - (["1000"], {"1", "2", "4"}), - (["2000"], {"2", "3"}), - (["3000"], set()), + ([], ["1", "2", "3", "4"]), + (["1000", "2000"], ["1", "2", "3", "4"]), + (["1000"], ["1", "2", "4"]), + (["2000"], ["2", "3"]), + (["3000"], []), ], ) def test_get_all__study_groups_filter( db_session: Session, groups: t.Sequence[str], - expected_ids: t.Set[str], + expected_ids: t.List[str], ) -> None: icache: Mock = Mock(spec=ICache) repository = StudyMetadataRepository(cache_service=icache, session=db_session) @@ -525,10 +533,10 @@ def test_get_all__study_groups_filter( test_group_1 = Group(id=1000) test_group_2 = Group(id=2000) - study_1 = VariantStudy(id=1, groups=[test_group_1]) - study_2 = VariantStudy(id=2, groups=[test_group_1, test_group_2]) - study_3 = RawStudy(id=3, groups=[test_group_2]) - study_4 = RawStudy(id=4, groups=[test_group_1]) + study_1 = VariantStudy(id=1, name="study-1", groups=[test_group_1]) + study_2 = VariantStudy(id=2, name="study-2", groups=[test_group_1, test_group_2]) + study_3 = RawStudy(id=3, name="study-3", groups=[test_group_2]) + study_4 = RawStudy(id=4, name="study-4", groups=[test_group_1]) db_session.add_all([test_group_1, test_group_2]) db_session.commit() @@ -551,7 +559,7 @@ def test_get_all__study_groups_filter( assert len(db_recorder.sql_statements) == 1, str(db_recorder) if expected_ids is not None: - assert {s.id for s in all_studies} == expected_ids + assert sorted(s.id for s in all_studies) == expected_ids # test pagination with DBStatementRecorder(db_session.bind) as db_recorder: @@ -560,32 +568,33 @@ def test_get_all__study_groups_filter( pagination=StudyPagination(page_nb=1, page_size=2), ) assert len(all_studies) == max(0, min(len(expected_ids) - 2, 2)) + assert sorted(s.id for s in all_studies) == expected_ids[2:4] assert len(db_recorder.sql_statements) == 1, str(db_recorder) @pytest.mark.parametrize( "study_ids, expected_ids", [ - ([], {"1", "2", "3", "4"}), - (["1", "2", "3", "4"], {"1", "2", "3", "4"}), - (["1", "2", "4"], {"1", "2", "4"}), - (["2", "3"], {"2", "3"}), - (["2"], {"2"}), - (["3000"], set()), + ([], ["1", "2", "3", "4"]), + (["1", "2", "3", "4"], ["1", "2", "3", "4"]), + (["1", "2", "4"], ["1", "2", "4"]), + (["2", "3"], ["2", "3"]), + (["2"], ["2"]), + (["3000"], []), ], ) def test_get_all__study_ids_filter( db_session: Session, study_ids: t.Sequence[str], - expected_ids: t.Set[str], + expected_ids: t.List[str], ) -> None: icache: Mock = Mock(spec=ICache) repository = StudyMetadataRepository(cache_service=icache, session=db_session) - study_1 = VariantStudy(id=1) - study_2 = VariantStudy(id=2) - study_3 = RawStudy(id=3) - study_4 = RawStudy(id=4) + study_1 = VariantStudy(id=1, name="study-1") + study_2 = VariantStudy(id=2, name="study-2") + study_3 = RawStudy(id=3, name="study-3") + study_4 = RawStudy(id=4, name="study-4") db_session.add_all([study_1, study_2, study_3, study_4]) db_session.commit() @@ -605,7 +614,7 @@ def test_get_all__study_ids_filter( assert len(db_recorder.sql_statements) == 1, str(db_recorder) if expected_ids is not None: - assert {s.id for s in all_studies} == expected_ids + assert sorted(s.id for s in all_studies) == expected_ids # test pagination with DBStatementRecorder(db_session.bind) as db_recorder: @@ -614,29 +623,30 @@ def test_get_all__study_ids_filter( pagination=StudyPagination(page_nb=1, page_size=2), ) assert len(all_studies) == max(0, min(len(expected_ids) - 2, 2)) + assert sorted(s.id for s in all_studies) == expected_ids[2:4] assert len(db_recorder.sql_statements) == 1, str(db_recorder) @pytest.mark.parametrize( "exists, expected_ids", [ - (None, {"1", "2", "3", "4"}), - (True, {"1", "2", "4"}), - (False, {"3"}), + (None, ["1", "2", "3", "4"]), + (True, ["1", "2", "4"]), + (False, ["3"]), ], ) def test_get_all__study_existence_filter( db_session: Session, exists: t.Optional[bool], - expected_ids: t.Set[str], + expected_ids: t.List[str], ) -> None: icache: Mock = Mock(spec=ICache) repository = StudyMetadataRepository(cache_service=icache, session=db_session) - study_1 = VariantStudy(id=1) - study_2 = VariantStudy(id=2) - study_3 = RawStudy(id=3, missing=datetime.datetime.now()) - study_4 = RawStudy(id=4) + study_1 = VariantStudy(id=1, name="study-1") + study_2 = VariantStudy(id=2, name="study-2") + study_3 = RawStudy(id=3, name="study-3", missing=datetime.datetime.now()) + study_4 = RawStudy(id=4, name="study-4") db_session.add_all([study_1, study_2, study_3, study_4]) db_session.commit() @@ -656,7 +666,7 @@ def test_get_all__study_existence_filter( assert len(db_recorder.sql_statements) == 1, str(db_recorder) if expected_ids is not None: - assert {s.id for s in all_studies} == expected_ids + assert sorted(s.id for s in all_studies) == expected_ids # test pagination with DBStatementRecorder(db_session.bind) as db_recorder: @@ -665,30 +675,31 @@ def test_get_all__study_existence_filter( pagination=StudyPagination(page_nb=1, page_size=2), ) assert len(all_studies) == max(0, min(len(expected_ids) - 2, 2)) + assert sorted(s.id for s in all_studies) == expected_ids[2:4] assert len(db_recorder.sql_statements) == 1, str(db_recorder) @pytest.mark.parametrize( "workspace, expected_ids", [ - ("", {"1", "2", "3", "4"}), - ("workspace-1", {"3"}), - ("workspace-2", {"4"}), - ("workspace-3", set()), + ("", ["1", "2", "3", "4"]), + ("workspace-1", ["3"]), + ("workspace-2", ["4"]), + ("workspace-3", []), ], ) def test_get_all__study_workspace_filter( db_session: Session, workspace: str, - expected_ids: t.Set[str], + expected_ids: t.List[str], ) -> None: icache: Mock = Mock(spec=ICache) repository = StudyMetadataRepository(cache_service=icache, session=db_session) - study_1 = VariantStudy(id=1) - study_2 = VariantStudy(id=2) - study_3 = RawStudy(id=3, workspace="workspace-1") - study_4 = RawStudy(id=4, workspace="workspace-2") + study_1 = VariantStudy(id=1, name="study-1") + study_2 = VariantStudy(id=2, name="study-2") + study_3 = RawStudy(id=3, name="study-3", workspace="workspace-1") + study_4 = RawStudy(id=4, name="study-4", workspace="workspace-2") db_session.add_all([study_1, study_2, study_3, study_4]) db_session.commit() @@ -708,7 +719,7 @@ def test_get_all__study_workspace_filter( assert len(db_recorder.sql_statements) == 1, str(db_recorder) if expected_ids is not None: - assert {s.id for s in all_studies} == expected_ids + assert sorted(s.id for s in all_studies) == expected_ids # test pagination with DBStatementRecorder(db_session.bind) as db_recorder: @@ -717,32 +728,33 @@ def test_get_all__study_workspace_filter( pagination=StudyPagination(page_nb=1, page_size=2), ) assert len(all_studies) == max(0, min(len(expected_ids) - 2, 2)) + assert sorted(s.id for s in all_studies) == expected_ids[2:4] assert len(db_recorder.sql_statements) == 1, str(db_recorder) @pytest.mark.parametrize( "folder, expected_ids", [ - ("", {"1", "2", "3", "4"}), - ("/home/folder-", {"1", "2", "3", "4"}), - ("/home/folder-1", {"1", "3"}), - ("/home/folder-2", {"2", "4"}), - ("/home/folder-3", set()), - ("folder-1", set()), + ("", ["1", "2", "3", "4"]), + ("/home/folder-", ["1", "2", "3", "4"]), + ("/home/folder-1", ["1", "3"]), + ("/home/folder-2", ["2", "4"]), + ("/home/folder-3", []), + ("folder-1", []), ], ) def test_get_all__study_folder_filter( db_session: Session, folder: str, - expected_ids: t.Set[str], + expected_ids: t.List[str], ) -> None: icache: Mock = Mock(spec=ICache) repository = StudyMetadataRepository(cache_service=icache, session=db_session) - study_1 = VariantStudy(id=1, folder="/home/folder-1") - study_2 = VariantStudy(id=2, folder="/home/folder-2") - study_3 = RawStudy(id=3, folder="/home/folder-1") - study_4 = RawStudy(id=4, folder="/home/folder-2") + study_1 = VariantStudy(id=1, name="study-1", folder="/home/folder-1") + study_2 = VariantStudy(id=2, name="study-2", folder="/home/folder-2") + study_3 = RawStudy(id=3, name="study-3", folder="/home/folder-1") + study_4 = RawStudy(id=4, name="study-4", folder="/home/folder-2") db_session.add_all([study_1, study_2, study_3, study_4]) db_session.commit() @@ -762,7 +774,7 @@ def test_get_all__study_folder_filter( assert len(db_recorder.sql_statements) == 1, str(db_recorder) if expected_ids is not None: - assert {s.id for s in all_studies} == expected_ids + assert sorted(s.id for s in all_studies) == expected_ids # test pagination with DBStatementRecorder(db_session.bind) as db_recorder: @@ -774,22 +786,20 @@ def test_get_all__study_folder_filter( assert len(db_recorder.sql_statements) == 1, str(db_recorder) -# TODO fix this test and all the others -@pytest.mark.skip(reason="This bug is to be fixed asap, the sql query is not working as expected") @pytest.mark.parametrize( "tags, expected_ids", [ - ([], {"1", "2", "3", "4", "5", "6", "7", "8"}), - (["decennial"], {"2", "4", "6", "8"}), - (["winter_transition"], {"3", "4", "7", "8"}), - (["decennial", "winter_transition"], {"2", "3", "4", "6", "7", "8"}), - (["no-study-tag"], set()), + ([], ["1", "2", "3", "4", "5", "6", "7", "8"]), + (["decennial"], ["2", "4", "6", "8"]), + (["winter_transition"], ["3", "4", "7", "8"]), + (["decennial", "winter_transition"], ["2", "3", "4", "6", "7", "8"]), + (["no-study-tag"], []), ], ) def test_get_all__study_tags_filter( db_session: Session, tags: t.Sequence[str], - expected_ids: t.Set[str], + expected_ids: t.List[str], ) -> None: icache: Mock = Mock(spec=ICache) repository = StudyMetadataRepository(cache_service=icache, session=db_session) @@ -798,14 +808,14 @@ def test_get_all__study_tags_filter( test_tag_2 = Tag(label="decennial") test_tag_3 = Tag(label="Winter_Transition") # note the different case - study_1 = VariantStudy(id=1, tags=[test_tag_1]) - study_2 = VariantStudy(id=2, tags=[test_tag_2]) - study_3 = VariantStudy(id=3, tags=[test_tag_3]) - study_4 = VariantStudy(id=4, tags=[test_tag_2, test_tag_3]) - study_5 = RawStudy(id=5, tags=[test_tag_1]) - study_6 = RawStudy(id=6, tags=[test_tag_2]) - study_7 = RawStudy(id=7, tags=[test_tag_3]) - study_8 = RawStudy(id=8, tags=[test_tag_2, test_tag_3]) + study_1 = VariantStudy(id=1, name="study-1", tags=[test_tag_1]) + study_2 = VariantStudy(id=2, name="study-2", tags=[test_tag_2]) + study_3 = VariantStudy(id=3, name="study-3", tags=[test_tag_3]) + study_4 = VariantStudy(id=4, name="study-4", tags=[test_tag_2, test_tag_3]) + study_5 = RawStudy(id=5, name="study-5", tags=[test_tag_1]) + study_6 = RawStudy(id=6, name="study-6", tags=[test_tag_2]) + study_7 = RawStudy(id=7, name="study-7", tags=[test_tag_3]) + study_8 = RawStudy(id=8, name="study-8", tags=[test_tag_2, test_tag_3]) db_session.add_all([study_1, study_2, study_3, study_4, study_5, study_6, study_7, study_8]) db_session.commit() @@ -826,7 +836,7 @@ def test_get_all__study_tags_filter( assert len(db_recorder.sql_statements) == 1, str(db_recorder) if expected_ids is not None: - assert {s.id for s in all_studies} == expected_ids + assert sorted(s.id for s in all_studies) == expected_ids # test pagination with DBStatementRecorder(db_session.bind) as db_recorder: @@ -835,6 +845,7 @@ def test_get_all__study_tags_filter( pagination=StudyPagination(page_nb=1, page_size=2), ) assert len(all_studies) == max(0, min(len(expected_ids) - 2, 2)) + assert sorted(s.id for s in all_studies) == expected_ids[2:4] assert len(db_recorder.sql_statements) == 1, str(db_recorder) @@ -842,42 +853,42 @@ def test_get_all__study_tags_filter( "user_id, study_groups, expected_ids", [ # fmt: off - (101, [], {"1", "2", "5", "6", "7", "8", "9", "10", "13", "14", "15", "16", "17", "18", - "21", "22", "23", "24", "25", "26", "29", "30", "31", "32", "34"}), - (101, ["101"], {"1", "7", "8", "9", "17", "23", "24", "25"}), - (101, ["102"], {"2", "5", "6", "7", "8", "9", "18", "21", "22", "23", "24", "25", "34"}), - (101, ["103"], set()), - (101, ["101", "102"], {"1", "2", "5", "6", "7", "8", "9", "17", "18", "21", "22", "23", "24", "25", "34"}), - (101, ["101", "103"], {"1", "7", "8", "9", "17", "23", "24", "25"}), - (101, ["102", "103"], {"2", "5", "6", "7", "8", "9", "18", "21", "22", "23", "24", "25", "34"}), - (101, ["101", "102", "103"], {"1", "2", "5", "6", "7", "8", "9", "17", "18", "21", "22", - "23", "24", "25", "34"}), - (102, [], {"1", "3", "4", "5", "7", "8", "9", "11", "13", "14", "15", "16", "17", "19", - "20", "21", "23", "24", "25", "27", "29", "30", "31", "32", "33"}), - (102, ["101"], {"1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33"}), - (102, ["102"], {"5", "7", "8", "9", "21", "23", "24", "25"}), - (102, ["103"], set()), - (102, ["101", "102"], {"1", "3", "4", "5", "7", "8", "9", "17", "19", "20", "21", "23", "24", "25", "33"}), - (102, ["101", "103"], {"1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33"}), - (102, ["102", "103"], {"5", "7", "8", "9", "21", "23", "24", "25"}), - (102, ["101", "102", "103"], {"1", "3", "4", "5", "7", "8", "9", "17", "19", "20", "21", - "23", "24", "25", "33"}), - (103, [], {"13", "14", "15", "16", "29", "30", "31", "32", "33", "34", "35", "36"}), - (103, ["101"], {"33"}), - (103, ["102"], {"34"}), - (103, ["103"], set()), - (103, ["101", "102"], {"33", "34"}), - (103, ["101", "103"], {"33"}), - (103, ["102", "103"], {"34"}), - (103, ["101", "102", "103"], {"33", "34"}), - (None, [], set()), - (None, ["101"], set()), - (None, ["102"], set()), - (None, ["103"], set()), - (None, ["101", "102"], set()), - (None, ["101", "103"], set()), - (None, ["102", "103"], set()), - (None, ["101", "102", "103"], set()), + (101, [], ["1", "2", "5", "6", "7", "8", "9", "10", "13", "14", "15", "16", "17", "18", + "21", "22", "23", "24", "25", "26", "29", "30", "31", "32", "34"]), + (101, ["101"], ["1", "7", "8", "9", "17", "23", "24", "25"]), + (101, ["102"], ["2", "5", "6", "7", "8", "9", "18", "21", "22", "23", "24", "25", "34"]), + (101, ["103"], []), + (101, ["101", "102"], ["1", "2", "5", "6", "7", "8", "9", "17", "18", "21", "22", "23", "24", "25", "34"]), + (101, ["101", "103"], ["1", "7", "8", "9", "17", "23", "24", "25"]), + (101, ["102", "103"], ["2", "5", "6", "7", "8", "9", "18", "21", "22", "23", "24", "25", "34"]), + (101, ["101", "102", "103"], ["1", "2", "5", "6", "7", "8", "9", "17", "18", "21", "22", + "23", "24", "25", "34"]), + (102, [], ["1", "3", "4", "5", "7", "8", "9", "11", "13", "14", "15", "16", "17", "19", + "20", "21", "23", "24", "25", "27", "29", "30", "31", "32", "33"]), + (102, ["101"], ["1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33"]), + (102, ["102"], ["5", "7", "8", "9", "21", "23", "24", "25"]), + (102, ["103"], []), + (102, ["101", "102"], ["1", "3", "4", "5", "7", "8", "9", "17", "19", "20", "21", "23", "24", "25", "33"]), + (102, ["101", "103"], ["1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33"]), + (102, ["102", "103"], ["5", "7", "8", "9", "21", "23", "24", "25"]), + (102, ["101", "102", "103"], ["1", "3", "4", "5", "7", "8", "9", "17", "19", "20", "21", + "23", "24", "25", "33"]), + (103, [], ["13", "14", "15", "16", "29", "30", "31", "32", "33", "34", "35", "36"]), + (103, ["101"], ["33"]), + (103, ["102"], ["34"]), + (103, ["103"], []), + (103, ["101", "102"], ["33", "34"]), + (103, ["101", "103"], ["33"]), + (103, ["102", "103"], ["34"]), + (103, ["101", "102", "103"], ["33", "34"]), + (None, [], []), + (None, ["101"], []), + (None, ["102"], []), + (None, ["103"], []), + (None, ["101", "102"], []), + (None, ["101", "103"], []), + (None, ["102", "103"], []), + (None, ["101", "102", "103"], []), # fmt: on ], ) @@ -885,7 +896,7 @@ def test_get_all__non_admin_permissions_filter( db_session: Session, user_id: t.Optional[int], study_groups: t.Sequence[str], - expected_ids: t.Set[str], + expected_ids: t.List[str], ) -> None: icache: Mock = Mock(spec=ICache) repository = StudyMetadataRepository(cache_service=icache, session=db_session) @@ -901,54 +912,54 @@ def test_get_all__non_admin_permissions_filter( user_groups_mapping = {101: [group_2.id], 102: [group_1.id], 103: []} # create variant studies for user_1 and user_2 that are part of some groups - study_1 = VariantStudy(id=1, owner=user_1, groups=[group_1]) - study_2 = VariantStudy(id=2, owner=user_1, groups=[group_2]) - study_3 = VariantStudy(id=3, groups=[group_1]) - study_4 = VariantStudy(id=4, owner=user_2, groups=[group_1]) - study_5 = VariantStudy(id=5, owner=user_2, groups=[group_2]) - study_6 = VariantStudy(id=6, groups=[group_2]) - study_7 = VariantStudy(id=7, owner=user_1, groups=[group_1, group_2]) - study_8 = VariantStudy(id=8, owner=user_2, groups=[group_1, group_2]) - study_9 = VariantStudy(id=9, groups=[group_1, group_2]) - study_10 = VariantStudy(id=10, owner=user_1) - study_11 = VariantStudy(id=11, owner=user_2) + study_1 = VariantStudy(id=1, name="study-1", owner=user_1, groups=[group_1]) + study_2 = VariantStudy(id=2, name="study-2", owner=user_1, groups=[group_2]) + study_3 = VariantStudy(id=3, name="study-3", groups=[group_1]) + study_4 = VariantStudy(id=4, name="study-4", owner=user_2, groups=[group_1]) + study_5 = VariantStudy(id=5, name="study-5", owner=user_2, groups=[group_2]) + study_6 = VariantStudy(id=6, name="study-6", groups=[group_2]) + study_7 = VariantStudy(id=7, name="study-7", owner=user_1, groups=[group_1, group_2]) + study_8 = VariantStudy(id=8, name="study-8", owner=user_2, groups=[group_1, group_2]) + study_9 = VariantStudy(id=9, name="study-9", groups=[group_1, group_2]) + study_10 = VariantStudy(id=10, name="study-X10", owner=user_1) + study_11 = VariantStudy(id=11, name="study-X11", owner=user_2) # create variant studies with neither owner nor groups - study_12 = VariantStudy(id=12) - study_13 = VariantStudy(id=13, public_mode=PublicMode.READ) - study_14 = VariantStudy(id=14, public_mode=PublicMode.EDIT) - study_15 = VariantStudy(id=15, public_mode=PublicMode.EXECUTE) - study_16 = VariantStudy(id=16, public_mode=PublicMode.FULL) + study_12 = VariantStudy(id=12, name="study-X12") + study_13 = VariantStudy(id=13, name="study-X13", public_mode=PublicMode.READ) + study_14 = VariantStudy(id=14, name="study-X14", public_mode=PublicMode.EDIT) + study_15 = VariantStudy(id=15, name="study-X15", public_mode=PublicMode.EXECUTE) + study_16 = VariantStudy(id=16, name="study-X16", public_mode=PublicMode.FULL) # create raw studies for user_1 and user_2 that are part of some groups - study_17 = RawStudy(id=17, owner=user_1, groups=[group_1]) - study_18 = RawStudy(id=18, owner=user_1, groups=[group_2]) - study_19 = RawStudy(id=19, groups=[group_1]) - study_20 = RawStudy(id=20, owner=user_2, groups=[group_1]) - study_21 = RawStudy(id=21, owner=user_2, groups=[group_2]) - study_22 = RawStudy(id=22, groups=[group_2]) - study_23 = RawStudy(id=23, owner=user_1, groups=[group_1, group_2]) - study_24 = RawStudy(id=24, owner=user_2, groups=[group_1, group_2]) - study_25 = RawStudy(id=25, groups=[group_1, group_2]) - study_26 = RawStudy(id=26, owner=user_1) - study_27 = RawStudy(id=27, owner=user_2) + study_17 = RawStudy(id=17, name="study-X17", owner=user_1, groups=[group_1]) + study_18 = RawStudy(id=18, name="study-X18", owner=user_1, groups=[group_2]) + study_19 = RawStudy(id=19, name="study-X19", groups=[group_1]) + study_20 = RawStudy(id=20, name="study-X20", owner=user_2, groups=[group_1]) + study_21 = RawStudy(id=21, name="study-X21", owner=user_2, groups=[group_2]) + study_22 = RawStudy(id=22, name="study-X22", groups=[group_2]) + study_23 = RawStudy(id=23, name="study-X23", owner=user_1, groups=[group_1, group_2]) + study_24 = RawStudy(id=24, name="study-X24", owner=user_2, groups=[group_1, group_2]) + study_25 = RawStudy(id=25, name="study-X25", groups=[group_1, group_2]) + study_26 = RawStudy(id=26, name="study-X26", owner=user_1) + study_27 = RawStudy(id=27, name="study-X27", owner=user_2) # create raw studies with neither owner nor groups - study_28 = RawStudy(id=28) - study_29 = RawStudy(id=29, public_mode=PublicMode.READ) - study_30 = RawStudy(id=30, public_mode=PublicMode.EDIT) - study_31 = RawStudy(id=31, public_mode=PublicMode.EXECUTE) - study_32 = RawStudy(id=32, public_mode=PublicMode.FULL) + study_28 = RawStudy(id=28, name="study-X28") + study_29 = RawStudy(id=29, name="study-X29", public_mode=PublicMode.READ) + study_30 = RawStudy(id=30, name="study-X30", public_mode=PublicMode.EDIT) + study_31 = RawStudy(id=31, name="study-X31", public_mode=PublicMode.EXECUTE) + study_32 = RawStudy(id=32, name="study-X32", public_mode=PublicMode.FULL) # create studies for user_3 that is not part of any group - study_33 = VariantStudy(id=33, owner=user_3, groups=[group_1]) - study_34 = RawStudy(id=34, owner=user_3, groups=[group_2]) - study_35 = VariantStudy(id=35, owner=user_3) - study_36 = RawStudy(id=36, owner=user_3) + study_33 = VariantStudy(id=33, name="study-X33", owner=user_3, groups=[group_1]) + study_34 = RawStudy(id=34, name="study-X34", owner=user_3, groups=[group_2]) + study_35 = VariantStudy(id=35, name="study-X35", owner=user_3) + study_36 = RawStudy(id=36, name="study-X36", owner=user_3) # create studies for group_3 that has no user - study_37 = VariantStudy(id=37, groups=[group_3]) - study_38 = RawStudy(id=38, groups=[group_3]) + study_37 = VariantStudy(id=37, name="study-X37", groups=[group_3]) + study_38 = RawStudy(id=38, name="study-X38", groups=[group_3]) db_session.add_all([user_1, user_2, user_3, group_1, group_2, group_3]) db_session.add_all( @@ -987,12 +998,13 @@ def test_get_all__non_admin_permissions_filter( assert len(db_recorder.sql_statements) == 1, str(db_recorder) if expected_ids is not None: - assert {s.id for s in all_studies} == expected_ids + assert sorted((s.id for s in all_studies), key=int) == expected_ids # test pagination with DBStatementRecorder(db_session.bind) as db_recorder: all_studies = repository.get_all(study_filter=study_filter, pagination=StudyPagination(page_nb=1, page_size=2)) assert len(all_studies) == max(0, min(len(expected_ids) - 2, 2)) + assert sorted((s.id for s in all_studies), key=int) == expected_ids[2:4] assert len(db_recorder.sql_statements) == 1, str(db_recorder) @@ -1000,22 +1012,22 @@ def test_get_all__non_admin_permissions_filter( "is_admin, study_groups, expected_ids", [ # fmt: off - (True, [], {str(e) for e in range(1, 39)}), - (True, ["101"], {"1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33"}), - (True, ["102"], {"2", "5", "6", "7", "8", "9", "18", "21", "22", "23", "24", "25", "34"}), - (True, ["103"], {"37", "38"}), - (True, ["101", "102"], {"1", "2", "3", "4", "5", "6", "7", "8", "9", "17", "18", "19", - "20", "21", "22", "23", "24", "25", "33", "34"}), - (True, ["101", "103"], {"1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33", "37", "38"}), - (True, ["101", "102", "103"], {"1", "2", "3", "4", "5", "6", "7", "8", "9", "17", "18", - "19", "20", "21", "22", "23", "24", "25", "33", "34", "37", "38"}), - (False, [], set()), - (False, ["101"], set()), - (False, ["102"], set()), - (False, ["103"], set()), - (False, ["101", "102"], set()), - (False, ["101", "103"], set()), - (False, ["101", "102", "103"], set()), + (True, [], [str(e) for e in range(1, 39)]), + (True, ["101"], ["1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33"]), + (True, ["102"], ["2", "5", "6", "7", "8", "9", "18", "21", "22", "23", "24", "25", "34"]), + (True, ["103"], ["37", "38"]), + (True, ["101", "102"], ["1", "2", "3", "4", "5", "6", "7", "8", "9", "17", "18", "19", + "20", "21", "22", "23", "24", "25", "33", "34"]), + (True, ["101", "103"], ["1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33", "37", "38"]), + (True, ["101", "102", "103"], ["1", "2", "3", "4", "5", "6", "7", "8", "9", "17", "18", + "19", "20", "21", "22", "23", "24", "25", "33", "34", "37", "38"]), + (False, [], []), + (False, ["101"], []), + (False, ["102"], []), + (False, ["103"], []), + (False, ["101", "102"], []), + (False, ["101", "103"], []), + (False, ["101", "102", "103"], []), # fmt: on ], ) @@ -1023,7 +1035,7 @@ def test_get_all__admin_permissions_filter( db_session: Session, is_admin: bool, study_groups: t.Sequence[str], - expected_ids: t.Set[str], + expected_ids: t.List[str], ) -> None: icache: Mock = Mock(spec=ICache) repository = StudyMetadataRepository(cache_service=icache, session=db_session) @@ -1036,54 +1048,54 @@ def test_get_all__admin_permissions_filter( group_3 = Group(id=103, name="group3") # create variant studies for user_1 and user_2 that are part of some groups - study_1 = VariantStudy(id=1, owner=user_1, groups=[group_1]) - study_2 = VariantStudy(id=2, owner=user_1, groups=[group_2]) - study_3 = VariantStudy(id=3, groups=[group_1]) - study_4 = VariantStudy(id=4, owner=user_2, groups=[group_1]) - study_5 = VariantStudy(id=5, owner=user_2, groups=[group_2]) - study_6 = VariantStudy(id=6, groups=[group_2]) - study_7 = VariantStudy(id=7, owner=user_1, groups=[group_1, group_2]) - study_8 = VariantStudy(id=8, owner=user_2, groups=[group_1, group_2]) - study_9 = VariantStudy(id=9, groups=[group_1, group_2]) - study_10 = VariantStudy(id=10, owner=user_1) - study_11 = VariantStudy(id=11, owner=user_2) + study_1 = VariantStudy(id=1, name="study-1", owner=user_1, groups=[group_1]) + study_2 = VariantStudy(id=2, name="study-2", owner=user_1, groups=[group_2]) + study_3 = VariantStudy(id=3, name="study-3", groups=[group_1]) + study_4 = VariantStudy(id=4, name="study-4", owner=user_2, groups=[group_1]) + study_5 = VariantStudy(id=5, name="study-5", owner=user_2, groups=[group_2]) + study_6 = VariantStudy(id=6, name="study-6", groups=[group_2]) + study_7 = VariantStudy(id=7, name="study-7", owner=user_1, groups=[group_1, group_2]) + study_8 = VariantStudy(id=8, name="study-8", owner=user_2, groups=[group_1, group_2]) + study_9 = VariantStudy(id=9, name="study-9", groups=[group_1, group_2]) + study_10 = VariantStudy(id=10, name="study-X10", owner=user_1) + study_11 = VariantStudy(id=11, name="study-X11", owner=user_2) # create variant studies with neither owner nor groups - study_12 = VariantStudy(id=12) - study_13 = VariantStudy(id=13, public_mode=PublicMode.READ) - study_14 = VariantStudy(id=14, public_mode=PublicMode.EDIT) - study_15 = VariantStudy(id=15, public_mode=PublicMode.EXECUTE) - study_16 = VariantStudy(id=16, public_mode=PublicMode.FULL) + study_12 = VariantStudy(id=12, name="study-X12") + study_13 = VariantStudy(id=13, name="study-X13", public_mode=PublicMode.READ) + study_14 = VariantStudy(id=14, name="study-X14", public_mode=PublicMode.EDIT) + study_15 = VariantStudy(id=15, name="study-X15", public_mode=PublicMode.EXECUTE) + study_16 = VariantStudy(id=16, name="study-X16", public_mode=PublicMode.FULL) # create raw studies for user_1 and user_2 that are part of some groups - study_17 = RawStudy(id=17, owner=user_1, groups=[group_1]) - study_18 = RawStudy(id=18, owner=user_1, groups=[group_2]) - study_19 = RawStudy(id=19, groups=[group_1]) - study_20 = RawStudy(id=20, owner=user_2, groups=[group_1]) - study_21 = RawStudy(id=21, owner=user_2, groups=[group_2]) - study_22 = RawStudy(id=22, groups=[group_2]) - study_23 = RawStudy(id=23, owner=user_1, groups=[group_1, group_2]) - study_24 = RawStudy(id=24, owner=user_2, groups=[group_1, group_2]) - study_25 = RawStudy(id=25, groups=[group_1, group_2]) - study_26 = RawStudy(id=26, owner=user_1) - study_27 = RawStudy(id=27, owner=user_2) + study_17 = RawStudy(id=17, name="study-X17", owner=user_1, groups=[group_1]) + study_18 = RawStudy(id=18, name="study-X18", owner=user_1, groups=[group_2]) + study_19 = RawStudy(id=19, name="study-X19", groups=[group_1]) + study_20 = RawStudy(id=20, name="study-X20", owner=user_2, groups=[group_1]) + study_21 = RawStudy(id=21, name="study-X21", owner=user_2, groups=[group_2]) + study_22 = RawStudy(id=22, name="study-X22", groups=[group_2]) + study_23 = RawStudy(id=23, name="study-X23", owner=user_1, groups=[group_1, group_2]) + study_24 = RawStudy(id=24, name="study-X24", owner=user_2, groups=[group_1, group_2]) + study_25 = RawStudy(id=25, name="study-X25", groups=[group_1, group_2]) + study_26 = RawStudy(id=26, name="study-X26", owner=user_1) + study_27 = RawStudy(id=27, name="study-X27", owner=user_2) # create raw studies with neither owner nor groups - study_28 = RawStudy(id=28) - study_29 = RawStudy(id=29, public_mode=PublicMode.READ) - study_30 = RawStudy(id=30, public_mode=PublicMode.EDIT) - study_31 = RawStudy(id=31, public_mode=PublicMode.EXECUTE) - study_32 = RawStudy(id=32, public_mode=PublicMode.FULL) + study_28 = RawStudy(id=28, name="study-X28") + study_29 = RawStudy(id=29, name="study-X29", public_mode=PublicMode.READ) + study_30 = RawStudy(id=30, name="study-X30", public_mode=PublicMode.EDIT) + study_31 = RawStudy(id=31, name="study-X31", public_mode=PublicMode.EXECUTE) + study_32 = RawStudy(id=32, name="study-X32", public_mode=PublicMode.FULL) # create studies for user_3 that is not part of any group - study_33 = VariantStudy(id=33, owner=user_3, groups=[group_1]) - study_34 = RawStudy(id=34, owner=user_3, groups=[group_2]) - study_35 = VariantStudy(id=35, owner=user_3) - study_36 = RawStudy(id=36, owner=user_3) + study_33 = VariantStudy(id=33, name="study-X33", owner=user_3, groups=[group_1]) + study_34 = RawStudy(id=34, name="study-X34", owner=user_3, groups=[group_2]) + study_35 = VariantStudy(id=35, name="study-X35", owner=user_3) + study_36 = RawStudy(id=36, name="study-X36", owner=user_3) # create studies for group_3 that has no user - study_37 = VariantStudy(id=37, groups=[group_3]) - study_38 = RawStudy(id=38, groups=[group_3]) + study_37 = VariantStudy(id=37, name="study-X37", groups=[group_3]) + study_38 = RawStudy(id=38, name="study-X38", groups=[group_3]) db_session.add_all([user_1, user_2, user_3, group_1, group_2, group_3]) db_session.add_all( @@ -1118,12 +1130,13 @@ def test_get_all__admin_permissions_filter( assert len(db_recorder.sql_statements) == 1, str(db_recorder) if expected_ids is not None: - assert {s.id for s in all_studies} == expected_ids + assert sorted((s.id for s in all_studies), key=int) == expected_ids # test pagination with DBStatementRecorder(db_session.bind) as db_recorder: all_studies = repository.get_all(study_filter=study_filter, pagination=StudyPagination(page_nb=1, page_size=2)) assert len(all_studies) == max(0, min(len(expected_ids) - 2, 2)) + assert sorted((s.id for s in all_studies), key=int) == expected_ids[2:4] assert len(db_recorder.sql_statements) == 1, str(db_recorder) @@ -1134,7 +1147,7 @@ def test_update_tags( repository = StudyMetadataRepository(cache_service=icache, session=db_session) study_id = 1 - study = RawStudy(id=study_id, tags=[]) + study = RawStudy(id=study_id, name=f"study-{study_id}", tags=[]) db_session.add(study) db_session.commit() @@ -1163,26 +1176,26 @@ def test_update_tags( @pytest.mark.parametrize( "managed, study_ids, exists, expected_ids", [ - (None, [], False, {"5", "6"}), - (None, [], True, {"1", "2", "3", "4", "7", "8"}), - (None, [], None, {"1", "2", "3", "4", "5", "6", "7", "8"}), - (None, [1, 3, 5, 7], False, {"5"}), - (None, [1, 3, 5, 7], True, {"1", "3", "7"}), - (None, [1, 3, 5, 7], None, {"1", "3", "5", "7"}), - (True, [], False, {"5"}), - (True, [], True, {"1", "2", "3", "4", "8"}), - (True, [], None, {"1", "2", "3", "4", "5", "8"}), - (True, [1, 3, 5, 7], False, {"5"}), - (True, [1, 3, 5, 7], True, {"1", "3"}), - (True, [1, 3, 5, 7], None, {"1", "3", "5"}), - (True, [2, 4, 6, 8], True, {"2", "4", "8"}), - (True, [2, 4, 6, 8], None, {"2", "4", "8"}), - (False, [], False, {"6"}), - (False, [], True, {"7"}), - (False, [], None, {"6", "7"}), - (False, [1, 3, 5, 7], False, set()), - (False, [1, 3, 5, 7], True, {"7"}), - (False, [1, 3, 5, 7], None, {"7"}), + (None, [], False, ["5", "6"]), + (None, [], True, ["1", "2", "3", "4", "7", "8"]), + (None, [], None, ["1", "2", "3", "4", "5", "6", "7", "8"]), + (None, [1, 3, 5, 7], False, ["5"]), + (None, [1, 3, 5, 7], True, ["1", "3", "7"]), + (None, [1, 3, 5, 7], None, ["1", "3", "5", "7"]), + (True, [], False, ["5"]), + (True, [], True, ["1", "2", "3", "4", "8"]), + (True, [], None, ["1", "2", "3", "4", "5", "8"]), + (True, [1, 3, 5, 7], False, ["5"]), + (True, [1, 3, 5, 7], True, ["1", "3"]), + (True, [1, 3, 5, 7], None, ["1", "3", "5"]), + (True, [2, 4, 6, 8], True, ["2", "4", "8"]), + (True, [2, 4, 6, 8], None, ["2", "4", "8"]), + (False, [], False, ["6"]), + (False, [], True, ["7"]), + (False, [], None, ["6", "7"]), + (False, [1, 3, 5, 7], False, []), + (False, [1, 3, 5, 7], True, ["7"]), + (False, [1, 3, 5, 7], None, ["7"]), ], ) def test_count_studies__general_case( @@ -1190,20 +1203,20 @@ def test_count_studies__general_case( managed: t.Union[bool, None], study_ids: t.Sequence[str], exists: t.Union[bool, None], - expected_ids: t.Set[str], + expected_ids: t.List[str], ) -> None: test_workspace = "test-repository" icache: Mock = Mock(spec=ICache) repository = StudyMetadataRepository(cache_service=icache, session=db_session) - study_1 = VariantStudy(id=1) - study_2 = VariantStudy(id=2) - study_3 = VariantStudy(id=3) - study_4 = VariantStudy(id=4) - study_5 = RawStudy(id=5, missing=datetime.datetime.now(), workspace=DEFAULT_WORKSPACE_NAME) - study_6 = RawStudy(id=6, missing=datetime.datetime.now(), workspace=test_workspace) - study_7 = RawStudy(id=7, missing=None, workspace=test_workspace) - study_8 = RawStudy(id=8, missing=None, workspace=DEFAULT_WORKSPACE_NAME) + study_1 = VariantStudy(id=1, name="study-1") + study_2 = VariantStudy(id=2, name="study-2") + study_3 = VariantStudy(id=3, name="study-3") + study_4 = VariantStudy(id=4, name="study-4") + study_5 = RawStudy(id=5, name="study-5", missing=datetime.datetime.now(), workspace=DEFAULT_WORKSPACE_NAME) + study_6 = RawStudy(id=6, name="study-6", missing=datetime.datetime.now(), workspace=test_workspace) + study_7 = RawStudy(id=7, name="study-7", missing=None, workspace=test_workspace) + study_8 = RawStudy(id=8, name="study-8", missing=None, workspace=DEFAULT_WORKSPACE_NAME) db_session.add_all([study_1, study_2, study_3, study_4, study_5, study_6, study_7, study_8]) db_session.commit()