diff --git a/tests/cli/upload/test_cli_upload_observations.py b/tests/cli/upload/test_cli_upload_observations.py index cfff25a747..3f8aabd487 100644 --- a/tests/cli/upload/test_cli_upload_observations.py +++ b/tests/cli/upload/test_cli_upload_observations.py @@ -21,7 +21,7 @@ from cg.meta.observations.mip_dna_observations_api import MipDNAObservationsAPI from cg.models.cg_config import CGConfig from cg.store import Store -from cg.store.models import Family, Sample +from cg.store.models import Family, FamilySample, Sample from tests.store_helpers import StoreHelpers @@ -143,8 +143,12 @@ def test_get_sequencing_method_exception( sample_wes: Sample = helpers.add_sample( store, application_tag=external_wes_application_tag, application_type=SequencingMethod.WES ) - link_1 = store.relate_sample(family=case, sample=sample_wgs, status=PhenotypeStatus.UNKNOWN) - link_2 = store.relate_sample(family=case, sample=sample_wes, status=PhenotypeStatus.UNKNOWN) + link_1: FamilySample = store.relate_sample( + family=case, sample=sample_wgs, status=PhenotypeStatus.UNKNOWN + ) + link_2: FamilySample = store.relate_sample( + family=case, sample=sample_wes, status=PhenotypeStatus.UNKNOWN + ) store.session.add_all([link_1, link_2]) # WHEN getting the sequencing method diff --git a/tests/store/api/conftest.py b/tests/store/api/conftest.py index 0a7639f181..c284aa8235 100644 --- a/tests/store/api/conftest.py +++ b/tests/store/api/conftest.py @@ -9,6 +9,7 @@ from cg.constants.subject import PhenotypeStatus from cg.meta.orders.pool_submitter import PoolSubmitter from cg.store import Store +from cg.store.models import FamilySample from tests.meta.demultiplex.conftest import populated_flow_cell_store from tests.store_helpers import StoreHelpers @@ -478,9 +479,10 @@ def store_with_analyses_for_cases( completed_at=timestamp_now, ) sample = helpers.add_sample(analysis_store, delivered_at=timestamp_now) - analysis_store.relate_sample( + link: FamilySample = analysis_store.relate_sample( family=oldest_analysis.family, sample=sample, status=PhenotypeStatus.UNKNOWN ) + analysis_store.session.add(link) return analysis_store @@ -517,9 +519,10 @@ def store_with_analyses_for_cases_not_uploaded_fluffy( pipeline=Pipeline.FLUFFY, ) sample = helpers.add_sample(analysis_store, delivered_at=timestamp_now) - analysis_store.relate_sample( + link: FamilySample = analysis_store.relate_sample( family=oldest_analysis.family, sample=sample, status=PhenotypeStatus.UNKNOWN ) + analysis_store.session.add(link) return analysis_store @@ -556,9 +559,10 @@ def store_with_analyses_for_cases_not_uploaded_microsalt( pipeline=Pipeline.MICROSALT, ) sample = helpers.add_sample(analysis_store, delivered_at=timestamp_now) - analysis_store.relate_sample( + link: FamilySample = analysis_store.relate_sample( family=oldest_analysis.family, sample=sample, status=PhenotypeStatus.UNKNOWN ) + analysis_store.session.add(link) return analysis_store @@ -596,8 +600,9 @@ def store_with_analyses_for_cases_to_deliver( pipeline=Pipeline.MIP_DNA, ) sample = helpers.add_sample(analysis_store, delivered_at=None) - analysis_store.relate_sample( + link: FamilySample = analysis_store.relate_sample( family=oldest_analysis.family, sample=sample, status=PhenotypeStatus.UNKNOWN ) + analysis_store.session.add(link) return analysis_store diff --git a/tests/store/api/status/test_analyses_to_clean.py b/tests/store/api/status/test_analyses_to_clean.py index 30240061ca..ba91cde0d6 100644 --- a/tests/store/api/status/test_analyses_to_clean.py +++ b/tests/store/api/status/test_analyses_to_clean.py @@ -3,6 +3,7 @@ from cg.constants import Pipeline from cg.store import Store +from cg.store.models import FamilySample def test_analysis_included( @@ -18,7 +19,10 @@ def test_analysis_included( cleaned_at=None, ) sample = helpers.add_sample(analysis_store, delivered_at=timestamp_yesterday) - analysis_store.relate_sample(family=analysis.family, sample=sample, status="unknown") + link: FamilySample = analysis_store.relate_sample( + family=analysis.family, sample=sample, status="unknown" + ) + analysis_store.session.add(link) # WHEN calling the analyses_to_clean analyses_to_clean = analysis_store.get_analyses_to_clean(before=timestamp_now) @@ -35,7 +39,9 @@ def test_analysis_excluded(analysis_store: Store, helpers, timestamp_now: dateti analysis_store, started_at=timestamp_now, uploaded_at=None, cleaned_at=None ) sample = helpers.add_sample(analysis_store, delivered_at=timestamp_now) - link = analysis_store.relate_sample(family=analysis.family, sample=sample, status="unknown") + link: FamilySample = analysis_store.relate_sample( + family=analysis.family, sample=sample, status="unknown" + ) analysis_store.session.add(link) # WHEN calling the analyses_to_clean @@ -60,7 +66,9 @@ def test_pipeline_included( cleaned_at=None, ) sample = helpers.add_sample(analysis_store, delivered_at=timestamp_yesterday) - link = analysis_store.relate_sample(family=analysis.family, sample=sample, status="unknown") + link: FamilySample = analysis_store.relate_sample( + family=analysis.family, sample=sample, status="unknown" + ) analysis_store.session.add(link) # WHEN calling the analyses_to_clean specifying the used pipeline @@ -87,7 +95,9 @@ def test_pipeline_excluded(analysis_store: Store, helpers, timestamp_now: dateti cleaned_at=None, ) sample = helpers.add_sample(analysis_store, delivered_at=timestamp_now) - link = analysis_store.relate_sample(family=analysis.family, sample=sample, status="unknown") + link: FamilySample = analysis_store.relate_sample( + family=analysis.family, sample=sample, status="unknown" + ) analysis_store.session.add(link) # WHEN calling the analyses_to_clean specifying another pipeline @@ -110,7 +120,9 @@ def test_non_cleaned_included( cleaned_at=None, ) sample = helpers.add_sample(analysis_store, delivered_at=timestamp_yesterday) - link = analysis_store.relate_sample(family=analysis.family, sample=sample, status="unknown") + link: FamilySample = analysis_store.relate_sample( + family=analysis.family, sample=sample, status="unknown" + ) analysis_store.session.add(link) # WHEN calling the analyses_to_clean @@ -131,7 +143,9 @@ def test_cleaned_excluded(analysis_store: Store, helpers, timestamp_now: datetim cleaned_at=timestamp_now, ) sample = helpers.add_sample(analysis_store, delivered_at=timestamp_now) - link = analysis_store.relate_sample(family=analysis.family, sample=sample, status="unknown") + link: FamilySample = analysis_store.relate_sample( + family=analysis.family, sample=sample, status="unknown" + ) analysis_store.session.add(link) # WHEN calling the analyses_to_clean diff --git a/tests/store/api/status/test_analyses_to_delivery_report.py b/tests/store/api/status/test_analyses_to_delivery_report.py index ae1f074072..97059b82be 100644 --- a/tests/store/api/status/test_analyses_to_delivery_report.py +++ b/tests/store/api/status/test_analyses_to_delivery_report.py @@ -3,6 +3,7 @@ from cg.constants import DataDelivery, Pipeline from cg.constants.subject import PhenotypeStatus from cg.store import Store +from cg.store.models import FamilySample from cg.utils.date import get_date @@ -20,7 +21,7 @@ def test_missing(analysis_store: Store, helpers, timestamp_now): data_delivery=DataDelivery.SCOUT, ) sample = helpers.add_sample(analysis_store, delivered_at=timestamp_now) - link = analysis_store.relate_sample( + link: FamilySample = analysis_store.relate_sample( family=analysis.family, sample=sample, status=PhenotypeStatus.UNKNOWN ) analysis_store.session.add(link) @@ -56,9 +57,10 @@ def test_outdated_analysis(analysis_store, helpers, timestamp_now, timestamp_yes sample = helpers.add_sample(analysis_store, delivered_at=timestamp_now) # GIVEN a store sample case relation - analysis_store.relate_sample( + link: FamilySample = analysis_store.relate_sample( family=analysis.family, sample=sample, status=PhenotypeStatus.UNKNOWN ) + analysis_store.session.add(link) # WHEN calling the analyses_to_delivery_report analyses = analysis_store.analyses_to_delivery_report(pipeline=pipeline).all() diff --git a/tests/store/api/status/test_store_api_status_analysis.py b/tests/store/api/status/test_store_api_status_analysis.py index 8cbdf9742d..8dc01e748d 100644 --- a/tests/store/api/status/test_store_api_status_analysis.py +++ b/tests/store/api/status/test_store_api_status_analysis.py @@ -8,7 +8,7 @@ from cg.constants.constants import CaseActions from cg.constants.subject import PhenotypeStatus from cg.store import Store -from cg.store.models import Analysis, Family, Sample +from cg.store.models import Analysis, Family, FamilySample, Sample from tests.store_helpers import StoreHelpers @@ -301,8 +301,13 @@ def test_one_of_two_sequenced_samples( not_sequenced_sample: Sample = helpers.add_sample(base_store, reads_updated_at=None) # GIVEN a database with a case with one of one sequenced samples and no analysis - base_store.relate_sample(test_case, sequenced_sample, PhenotypeStatus.UNKNOWN) - base_store.relate_sample(test_case, not_sequenced_sample, PhenotypeStatus.UNKNOWN) + link_1: FamilySample = base_store.relate_sample( + test_case, sequenced_sample, PhenotypeStatus.UNKNOWN + ) + link_2: FamilySample = base_store.relate_sample( + test_case, not_sequenced_sample, PhenotypeStatus.UNKNOWN + ) + base_store.session.add_all([link_1, link_2]) # WHEN getting cases to analyse cases: list[Family] = base_store.cases_to_analyze(pipeline=Pipeline.MIP_DNA, threshold=True) diff --git a/tests/store/api/status/test_store_api_status_cases.py b/tests/store/api/status/test_store_api_status_cases.py index 1a707c2667..0b7b4ea884 100644 --- a/tests/store/api/status/test_store_api_status_cases.py +++ b/tests/store/api/status/test_store_api_status_cases.py @@ -2,7 +2,7 @@ from cg.constants import CASE_ACTIONS, DataDelivery, Pipeline, Priority from cg.store import Store -from cg.store.models import Analysis, Family +from cg.store.models import Analysis, Family, FamilySample def test_delivered_at_affects_tat(base_store: Store, helpers): @@ -113,10 +113,10 @@ def test_samples_flowcell(base_store: Store, helpers): new_case = add_case(helpers, base_store) sample_on_flowcell = helpers.add_sample(base_store) flowcell = helpers.add_flow_cell(base_store, samples=[sample_on_flowcell], status="ondisk") - link_1 = base_store.relate_sample(new_case, sample_on_flowcell, "unknown") + link_1: FamilySample = base_store.relate_sample(new_case, sample_on_flowcell, "unknown") base_store.session.add(link_1) sample_not_on_flowcell = helpers.add_sample(base_store) - link_2 = base_store.relate_sample(new_case, sample_not_on_flowcell, "unknown") + link_2: FamilySample = base_store.relate_sample(new_case, sample_not_on_flowcell, "unknown") base_store.session.add(link_2) # WHEN getting active cases @@ -198,8 +198,8 @@ def test_received_at_is_newest_date(base_store: Store, helpers): yesteryear = datetime.now() - timedelta(days=365) newest_sample = helpers.add_sample(base_store, received_at=yesterday) oldest_sample = helpers.add_sample(base_store, received_at=yesteryear) - link_1 = base_store.relate_sample(new_case, newest_sample, "unknown") - link_2 = base_store.relate_sample(new_case, oldest_sample, "unknown") + link_1: FamilySample = base_store.relate_sample(new_case, newest_sample, "unknown") + link_2: FamilySample = base_store.relate_sample(new_case, oldest_sample, "unknown") base_store.session.add_all([link_1, link_2]) # WHEN getting active cases @@ -220,8 +220,8 @@ def test_prepared_at_is_newest_date(base_store: Store, helpers): yesteryear = datetime.now() - timedelta(days=365) newest_sample = helpers.add_sample(base_store, prepared_at=yesterday) oldest_sample = helpers.add_sample(base_store, prepared_at=yesteryear) - link_1 = base_store.relate_sample(new_case, newest_sample, "unknown") - link_2 = base_store.relate_sample(new_case, oldest_sample, "unknown") + link_1: FamilySample = base_store.relate_sample(new_case, newest_sample, "unknown") + link_2: FamilySample = base_store.relate_sample(new_case, oldest_sample, "unknown") base_store.session.add_all([link_1, link_2]) # WHEN getting active cases @@ -242,8 +242,8 @@ def test_sequenced_at_is_newest_date(base_store: Store, helpers): yesteryear = datetime.now() - timedelta(days=365) newest_sample = helpers.add_sample(base_store, reads_updated_at=yesterday) oldest_sample = helpers.add_sample(base_store, reads_updated_at=yesteryear) - link_1 = base_store.relate_sample(new_case, newest_sample, "unknown") - link_2 = base_store.relate_sample(new_case, oldest_sample, "unknown") + link_1: FamilySample = base_store.relate_sample(new_case, newest_sample, "unknown") + link_2: FamilySample = base_store.relate_sample(new_case, oldest_sample, "unknown") base_store.session.add_all([link_1, link_2]) # WHEN getting active cases @@ -264,8 +264,8 @@ def test_delivered_at_is_newest_date(base_store: Store, helpers): yesteryear = datetime.now() - timedelta(days=365) newest_sample = helpers.add_sample(base_store, delivered_at=yesterday) oldest_sample = helpers.add_sample(base_store, delivered_at=yesteryear) - link_1 = base_store.relate_sample(new_case, newest_sample, "unknown") - link_2 = base_store.relate_sample(new_case, oldest_sample, "unknown") + link_1: FamilySample = base_store.relate_sample(new_case, newest_sample, "unknown") + link_2: FamilySample = base_store.relate_sample(new_case, oldest_sample, "unknown") base_store.session.add_all([link_1, link_2]) # WHEN getting active cases @@ -292,8 +292,8 @@ def test_invoiced_at_is_newest_invoice_date(base_store: Store, helpers): invoice = base_store.add_invoice(helpers.ensure_customer(base_store)) oldest_sample.invoice = invoice oldest_sample.invoice.invoiced_at = yesteryear - link_1 = base_store.relate_sample(new_case, newest_sample, "unknown") - link_2 = base_store.relate_sample(new_case, oldest_sample, "unknown") + link_1: FamilySample = base_store.relate_sample(new_case, newest_sample, "unknown") + link_2: FamilySample = base_store.relate_sample(new_case, oldest_sample, "unknown") base_store.session.add_all([link_1, link_2]) # WHEN getting active cases @@ -598,11 +598,14 @@ def test_show_multiple_data_analysis(base_store: Store, helpers): data_analysis = Pipeline.BALSAMIC new_case = add_case(helpers, base_store, data_analysis=data_analysis) sample1 = helpers.add_sample(base_store) - base_store.relate_sample(new_case, sample1, "unknown") + link_1: FamilySample = base_store.relate_sample(new_case, sample1, "unknown") + base_store.session.add(link_1) new_case2 = add_case(helpers, base_store, case_id="new_case2", data_analysis=data_analysis) sample2 = helpers.add_sample(base_store) - base_store.relate_sample(new_case, sample2, "unknown") - base_store.relate_sample(new_case2, sample2, "unknown") + link_2: FamilySample = base_store.relate_sample(new_case, sample2, "unknown") + link_3: FamilySample = base_store.relate_sample(new_case2, sample2, "unknown") + base_store.session.add_all([link_2, link_3]) + base_store.session.commit() # WHEN getting active cases by data_analysis cases = base_store.cases(data_analysis=str(data_analysis)[:-1]) @@ -826,7 +829,8 @@ def test_only_prepared_cases(base_store: Store, helpers): base_store.session.add(link) neg_new_case = add_case(helpers, base_store, "neg_new_case") neg_sample = helpers.add_sample(base_store, name="neg_sample") - base_store.relate_sample(neg_new_case, neg_sample, "unknown") + link = base_store.relate_sample(neg_new_case, neg_sample, "unknown") + base_store.session.add(link) # WHEN getting active cases excluding prepared cases = base_store.cases(only_prepared=True) @@ -847,7 +851,8 @@ def test_only_received_cases(base_store: Store, helpers): base_store.session.add(link) neg_new_case = add_case(helpers, base_store, "neg_new_case") neg_sample = helpers.add_sample(base_store, name="neg_sample") - base_store.relate_sample(neg_new_case, neg_sample, "unknown") + link = base_store.relate_sample(neg_new_case, neg_sample, "unknown") + base_store.session.add(link) # WHEN getting active cases excluding received cases = base_store.cases(only_received=True) @@ -868,7 +873,8 @@ def test_only_sequenced_cases(base_store: Store, helpers): base_store.session.add(link) neg_new_case = add_case(helpers, base_store, "neg_new_case") neg_sample = helpers.add_sample(base_store, name="neg_sample") - base_store.relate_sample(neg_new_case, neg_sample, "unknown") + link = base_store.relate_sample(neg_new_case, neg_sample, "unknown") + base_store.session.add(link) # WHEN getting active cases excluding sequenced cases = base_store.cases(only_sequenced=True) @@ -889,7 +895,8 @@ def test_only_delivered_cases(base_store: Store, helpers): base_store.session.add(link) neg_new_case = add_case(helpers, base_store, "neg_new_case") neg_sample = helpers.add_sample(base_store, name="neg_sample") - base_store.relate_sample(neg_new_case, neg_sample, "unknown") + link = base_store.relate_sample(neg_new_case, neg_sample, "unknown") + base_store.session.add(link) # WHEN getting active cases excluding delivered cases = base_store.cases(only_delivered=True) @@ -907,7 +914,8 @@ def test_only_uploaded_cases(base_store: Store, helpers): helpers.add_analysis(base_store, uploaded_at=datetime.now()) neg_new_case = add_case(helpers, base_store, "neg_new_case") neg_sample = helpers.add_sample(base_store, name="neg_sample") - base_store.relate_sample(neg_new_case, neg_sample, "unknown") + link = base_store.relate_sample(neg_new_case, neg_sample, "unknown") + base_store.session.add(link) # WHEN getting active cases excluding uploaded cases = base_store.cases(only_uploaded=True) @@ -925,7 +933,8 @@ def test_only_delivery_reported_cases(base_store: Store, helpers): helpers.add_analysis(base_store, delivery_reported_at=datetime.now()) neg_new_case = add_case(helpers, base_store, "neg_new_case") neg_sample = helpers.add_sample(base_store, name="neg_sample") - base_store.relate_sample(neg_new_case, neg_sample, "unknown") + link = base_store.relate_sample(neg_new_case, neg_sample, "unknown") + base_store.session.add(link) # WHEN getting active cases excluding delivery_reported cases = base_store.cases(only_delivery_reported=True) @@ -948,7 +957,8 @@ def test_only_invoiced_cases(base_store: Store, helpers): base_store.session.add(link) neg_new_case = add_case(helpers, base_store, "neg_new_case") neg_sample = helpers.add_sample(base_store, name="neg_sample") - base_store.relate_sample(neg_new_case, neg_sample, "unknown") + link = base_store.relate_sample(neg_new_case, neg_sample, "unknown") + base_store.session.add(link) # WHEN getting active cases excluding invoiced cases = base_store.cases(only_invoiced=True) @@ -966,7 +976,8 @@ def test_only_analysed_cases(base_store: Store, helpers): helpers.add_analysis(base_store, completed_at=datetime.now()) neg_new_case = add_case(helpers, base_store, "neg_new_case") neg_sample = helpers.add_sample(base_store, name="neg_sample") - base_store.relate_sample(neg_new_case, neg_sample, "unknown") + link = base_store.relate_sample(neg_new_case, neg_sample, "unknown") + base_store.session.add(link) # WHEN getting active cases excluding not analysed cases = base_store.cases(only_analysed=True) @@ -1331,8 +1342,8 @@ def test_one_of_two_samples_received(base_store: Store, helpers): new_case = add_case(helpers, base_store) sample_received = helpers.add_sample(base_store, "sample_received", received_at=datetime.now()) sample_not_received = helpers.add_sample(base_store, "sample_not_received", received_at=None) - link_1 = base_store.relate_sample(new_case, sample_received, "unknown") - link_2 = base_store.relate_sample(new_case, sample_not_received, "unknown") + link_1: FamilySample = base_store.relate_sample(new_case, sample_received, "unknown") + link_2: FamilySample = base_store.relate_sample(new_case, sample_not_received, "unknown") base_store.session.add_all([link_1, link_2]) assert sample_received.received_at is not None assert sample_not_received.received_at is None diff --git a/tests/store/api/test_base.py b/tests/store/api/test_base.py index e0b8654033..14ed8d5d6e 100644 --- a/tests/store/api/test_base.py +++ b/tests/store/api/test_base.py @@ -2,6 +2,7 @@ from sqlalchemy.orm import Query from cg.constants.subject import PhenotypeStatus +from cg.store.models import FamilySample def test_get_latest_analyses_for_cases_query( @@ -28,9 +29,10 @@ def test_get_latest_analyses_for_cases_query( delivery_reported_at=None, ) sample = helpers.add_sample(analysis_store, delivered_at=timestamp_now) - analysis_store.relate_sample( + link: FamilySample = analysis_store.relate_sample( family=analysis_oldest.family, sample=sample, status=PhenotypeStatus.UNKNOWN ) + analysis_store.session.add(link) # WHEN calling the analyses_to_delivery_report analyses: Query = analysis_store._get_latest_analyses_for_cases_query() diff --git a/tests/store/conftest.py b/tests/store/conftest.py index 5544ce2453..3c3e00cab7 100644 --- a/tests/store/conftest.py +++ b/tests/store/conftest.py @@ -8,7 +8,7 @@ from cg.constants import Pipeline from cg.constants.subject import Gender, PhenotypeStatus from cg.store import Store -from cg.store.models import Analysis, Application, Customer, Family, Organism, Sample +from cg.store.models import Analysis, Application, Customer, Family, FamilySample, Organism, Sample from tests.store_helpers import StoreHelpers @@ -445,7 +445,7 @@ def store_with_analyses_for_cases( uploaded_to_vogue_at=timestamp_now, ) sample = helpers.add_sample(analysis_store, delivered_at=timestamp_now) - link = analysis_store.relate_sample( + link: FamilySample = analysis_store.relate_sample( family=oldest_analysis.family, sample=sample, status=PhenotypeStatus.UNKNOWN ) analysis_store.session.add(link) diff --git a/tests/store/filters/test_status_cases_filters.py b/tests/store/filters/test_status_cases_filters.py index 8acfaba9f8..51ab0cbf03 100644 --- a/tests/store/filters/test_status_cases_filters.py +++ b/tests/store/filters/test_status_cases_filters.py @@ -29,7 +29,7 @@ filter_report_supported_data_delivery_cases, filter_running_cases, ) -from cg.store.models import Analysis, Family, Sample +from cg.store.models import Analysis, Family, FamilySample, Sample from tests.store_helpers import StoreHelpers @@ -45,7 +45,8 @@ def test_filter_cases_has_sequence( test_case = helpers.add_case(base_store) # GIVEN a database with a case with one sequenced samples for specified analysis - base_store.relate_sample(test_case, test_sample, PhenotypeStatus.UNKNOWN) + link = base_store.relate_sample(test_case, test_sample, PhenotypeStatus.UNKNOWN) + base_store.session.add(link) # GIVEN a cases Query cases: Query = base_store._get_outer_join_cases_with_analyses_query() @@ -70,7 +71,8 @@ def test_filter_cases_has_sequence_when_external(base_store: Store, helpers: Sto test_case = helpers.add_case(base_store) # GIVEN a database with a case with one sequenced samples for specified analysis - base_store.relate_sample(test_case, test_sample, PhenotypeStatus.UNKNOWN) + link = base_store.relate_sample(test_case, test_sample, PhenotypeStatus.UNKNOWN) + base_store.session.add(link) # GIVEN a cases Query cases: Query = base_store._get_outer_join_cases_with_analyses_query() @@ -95,7 +97,8 @@ def test_filter_cases_has_sequence_when_not_sequenced(base_store: Store, helpers test_case = helpers.add_case(base_store) # GIVEN a database with a case with one sequenced samples for specified analysis - base_store.relate_sample(test_case, test_sample, PhenotypeStatus.UNKNOWN) + link = base_store.relate_sample(test_case, test_sample, PhenotypeStatus.UNKNOWN) + base_store.session.add(link) # GIVEN a cases Query cases: Query = base_store._get_outer_join_cases_with_analyses_query() @@ -122,7 +125,8 @@ def test_filter_cases_has_sequence_when_not_external_nor_sequenced( test_case = helpers.add_case(base_store) # GIVEN a database with a case with one sequenced samples for specified analysis - base_store.relate_sample(test_case, test_sample, PhenotypeStatus.UNKNOWN) + link = base_store.relate_sample(test_case, test_sample, PhenotypeStatus.UNKNOWN) + base_store.session.add(link) # GIVEN a cases Query cases: Query = base_store._get_outer_join_cases_with_analyses_query() @@ -174,7 +178,8 @@ def test_filter_cases_with_pipeline_when_incorrect_pipline( test_case: Family = helpers.add_case(base_store, data_analysis=Pipeline.BALSAMIC) # GIVEN a database with a case with one sequenced samples for specified analysis - base_store.relate_sample(test_case, test_sample, PhenotypeStatus.UNKNOWN) + link = base_store.relate_sample(test_case, test_sample, PhenotypeStatus.UNKNOWN) + base_store.session.add(link) # GIVEN a cases Query cases: Query = base_store._get_outer_join_cases_with_analyses_query() @@ -203,8 +208,12 @@ def test_filter_cases_with_loqusdb_supported_pipeline( test_fluffy_case.customer.loqus_upload = True # GIVEN a database with a case with one sequenced samples for specified analysis - link_1 = base_store.relate_sample(test_mip_case, test_sample, PhenotypeStatus.UNKNOWN) - link_2 = base_store.relate_sample(test_fluffy_case, test_sample, PhenotypeStatus.UNKNOWN) + link_1: FamilySample = base_store.relate_sample( + test_mip_case, test_sample, PhenotypeStatus.UNKNOWN + ) + link_2: FamilySample = base_store.relate_sample( + test_fluffy_case, test_sample, PhenotypeStatus.UNKNOWN + ) base_store.session.add_all([link_1, link_2]) # GIVEN a cases Query @@ -260,7 +269,8 @@ def test_filter_cases_with_loqusdb_supported_sequencing_method_empty( # GIVEN a MIP-DNA associated test case test_case_wts: Family = helpers.add_case(base_store, data_analysis=Pipeline.MIP_DNA) - base_store.relate_sample(test_case_wts, test_sample_wts, PhenotypeStatus.UNKNOWN) + link = base_store.relate_sample(test_case_wts, test_sample_wts, PhenotypeStatus.UNKNOWN) + base_store.session.add(link) # GIVEN a cases Query cases: Query = base_store._get_outer_join_cases_with_analyses_query() @@ -294,7 +304,8 @@ def test_filter_cases_for_analysis( test_analysis.family.action: str = CaseActions.ANALYZE # GIVEN a database with a case with one sequenced samples for specified analysis - base_store.relate_sample(test_analysis.family, test_sample, PhenotypeStatus.UNKNOWN) + link = base_store.relate_sample(test_analysis.family, test_sample, PhenotypeStatus.UNKNOWN) + base_store.session.add(link) # GIVEN a cases Query cases: Query = base_store._get_outer_join_cases_with_analyses_query() @@ -323,7 +334,8 @@ def test_filter_cases_for_analysis_when_sequenced_sample_and_no_analysis( test_case = helpers.add_case(base_store) # GIVEN a database with a case with one sequenced samples for specified analysis - base_store.relate_sample(test_case, test_sample, PhenotypeStatus.UNKNOWN) + link = base_store.relate_sample(test_case, test_sample, PhenotypeStatus.UNKNOWN) + base_store.session.add(link) # GIVEN a cases Query cases: Query = base_store._get_outer_join_cases_with_analyses_query() @@ -358,7 +370,8 @@ def test_filter_cases_for_analysis_when_cases_with_no_action_and_new_sequence_da test_analysis.family.action: Union[None, str] = None # GIVEN a database with a case with one sequenced samples for specified analysis - base_store.relate_sample(test_analysis.family, test_sample, PhenotypeStatus.UNKNOWN) + link = base_store.relate_sample(test_analysis.family, test_sample, PhenotypeStatus.UNKNOWN) + base_store.session.add(link) # GIVEN an old analysis test_analysis.created_at = timestamp_yesterday @@ -393,7 +406,8 @@ def test_filter_cases_for_analysis_when_cases_with_no_action_and_old_sequence_da test_analysis.family.action: Union[None, str] = None # GIVEN a database with a case with one sequenced samples for specified analysis - base_store.relate_sample(test_analysis.family, test_sample, PhenotypeStatus.UNKNOWN) + link = base_store.relate_sample(test_analysis.family, test_sample, PhenotypeStatus.UNKNOWN) + base_store.session.add(link) # GIVEN a cases Query cases: Query = base_store._get_outer_join_cases_with_analyses_query() @@ -420,7 +434,8 @@ def test_filter_cases_with_scout_data_delivery( test_case = helpers.add_case(base_store, data_delivery=DataDelivery.FASTQ_ANALYSIS_SCOUT) # GIVEN a database with a case with one sequenced samples for specified analysis - base_store.relate_sample(test_case, test_sample, PhenotypeStatus.UNKNOWN) + link = base_store.relate_sample(test_case, test_sample, PhenotypeStatus.UNKNOWN) + base_store.session.add(link) # GIVEN a cases Query cases: Query = base_store._get_outer_join_cases_with_analyses_query() @@ -448,8 +463,10 @@ def test_filter_report_supported_data_delivery_cases( test_invalid_case = helpers.add_case(base_store, name="test", data_delivery=DataDelivery.FASTQ) # GIVEN a database with the test cases - link_1 = base_store.relate_sample(test_case, test_sample, PhenotypeStatus.UNKNOWN) - link_2 = base_store.relate_sample(test_invalid_case, test_sample, PhenotypeStatus.UNKNOWN) + link_1: FamilySample = base_store.relate_sample(test_case, test_sample, PhenotypeStatus.UNKNOWN) + link_2: FamilySample = base_store.relate_sample( + test_invalid_case, test_sample, PhenotypeStatus.UNKNOWN + ) base_store.session.add_all([link_1, link_2]) # GIVEN a cases Query diff --git a/tests/store/filters/test_status_samples_filters.py b/tests/store/filters/test_status_samples_filters.py index 384837e355..4f0d884ce4 100644 --- a/tests/store/filters/test_status_samples_filters.py +++ b/tests/store/filters/test_status_samples_filters.py @@ -29,7 +29,7 @@ filter_samples_without_invoice_id, filter_samples_without_loqusdb_id, ) -from cg.store.models import Sample +from cg.store.models import FamilySample, Sample from tests.store.conftest import StoreConstants @@ -40,10 +40,13 @@ def test_get_samples_with_loqusdb_id(helpers, store, sample_store, sample_id, lo case = helpers.add_case(store) sample = helpers.add_sample(store, loqusdb_id=loqusdb_id) sample_not_uploaded = helpers.add_sample(store, internal_id=sample_id) - sample_store.relate_sample(family=case, sample=sample, status=PhenotypeStatus.UNKNOWN) - sample_store.relate_sample( + link_1: FamilySample = sample_store.relate_sample( + family=case, sample=sample, status=PhenotypeStatus.UNKNOWN + ) + link_2: FamilySample = sample_store.relate_sample( family=case, sample=sample_not_uploaded, status=PhenotypeStatus.UNKNOWN ) + sample_store.session.add_all([link_1, link_2]) # GIVEN a sample query samples: Query = store._get_query(table=Sample) @@ -63,8 +66,13 @@ def test_get_samples_without_loqusdb_id(helpers, store, sample_store, sample_id, case = helpers.add_case(store) sample = helpers.add_sample(store) sample_uploaded = helpers.add_sample(store, internal_id=sample_id, loqusdb_id=loqusdb_id) - sample_store.relate_sample(family=case, sample=sample, status=PhenotypeStatus.UNKNOWN) - sample_store.relate_sample(family=case, sample=sample_uploaded, status=PhenotypeStatus.UNKNOWN) + link_1: FamilySample = sample_store.relate_sample( + family=case, sample=sample, status=PhenotypeStatus.UNKNOWN + ) + link_2: FamilySample = sample_store.relate_sample( + family=case, sample=sample_uploaded, status=PhenotypeStatus.UNKNOWN + ) + sample_store.session.add_all([link_1, link_2]) # GIVEN a sample query samples: Query = store._get_query(table=Sample)