Skip to content

Commit 7a65589

Browse files
committed
Fix tests
1 parent 7eec70e commit 7a65589

File tree

3 files changed

+37
-62
lines changed

3 files changed

+37
-62
lines changed

cg/store/crud/read.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,11 @@ def _get_related_samples_query(
16581658
SampleFilter.BY_CUSTOMER_ENTRY_IDS,
16591659
],
16601660
)
1661+
if samples.count() != 1:
1662+
samples: list[Sample] = samples.all()
1663+
raise CgDataError(
1664+
f"No unique DNA sample could be found: found {len(samples)} samples: {[sample.internal_id for sample in samples]}"
1665+
)
16611666
return samples
16621667

16631668
def get_uploaded_related_dna_cases(self, rna_case: Case) -> list[Case]:
@@ -1666,6 +1671,10 @@ def get_uploaded_related_dna_cases(self, rna_case: Case) -> list[Case]:
16661671
related_dna_cases: list[Case] = []
16671672
collaborators: set[Customer] = rna_case.customer.collaborators
16681673
for rna_sample in rna_case.samples:
1674+
if not rna_sample.subject_id:
1675+
raise CgDataError(
1676+
f"Failed to link RNA sample {rna_sample.internal_id} to DNA samples - subject_id field is empty."
1677+
)
16691678

16701679
related_dna_samples_query: Query = self._get_related_samples_query(
16711680
sample=rna_sample,
@@ -1678,7 +1687,7 @@ def get_uploaded_related_dna_cases(self, rna_case: Case) -> list[Case]:
16781687
)
16791688
related_dna_cases.extend(uploaded_dna_cases)
16801689
if not related_dna_cases:
1681-
raise CaseNotFoundError(
1690+
raise CgDataError(
16821691
f"No matching uploaded DNA cases for case {rna_case.internal_id} ({rna_case.name})."
16831692
)
16841693
return related_dna_cases

tests/meta/upload/scout/test_meta_upload_scoutapi_rna.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,8 @@ def test_create_rna_dna_collections(
559559

560560
# WHEN running the method to create a list of RNADNACollections
561561
# with the relationships between RNA/DNA samples and DNA cases
562-
rna_dna_collections: list[RNADNACollection] = upload_scout_api.create_rna_dna_collections(
563-
rna_case
562+
rna_dna_collections: list[RNADNACollection] = (
563+
upload_scout_api.status_db.get_related_dna_cases_with_samples(rna_case)
564564
)
565565

566566
# THEN the output should be a list of RNADNACollections
@@ -585,15 +585,15 @@ def test_add_rna_sample(
585585

586586
# WHEN running the method to create a list of RNADNACollections
587587
# with the relationships between RNA/DNA samples and DNA cases
588-
rna_dna_collections: list[RNADNACollection] = upload_scout_api.create_rna_dna_collections(
588+
rna_dna_collections: list[RNADNACollection] = rna_store.get_related_dna_cases_with_samples(
589589
rna_case
590590
)
591591

592592
# THEN the resulting RNADNACollections should contain all RNA samples in the case
593593
assert rna_sample_list
594594
for sample in rna_sample_list:
595595
assert sample.internal_id in [
596-
rna_dna_collection.rna_sample_internal_id for rna_dna_collection in rna_dna_collections
596+
rna_dna_collection.rna_sample_id for rna_dna_collection in rna_dna_collections
597597
]
598598

599599

@@ -609,13 +609,15 @@ def test_link_rna_sample_to_dna_sample(
609609
rna_sample: Sample = rna_store.get_sample_by_internal_id(rna_sample_son_id)
610610

611611
# WHEN creating an RNADNACollection for an RNA sample
612-
rna_dna_collection: RNADNACollection = upload_scout_api.create_rna_dna_collection(rna_sample)
612+
rna_dna_collection: list[RNADNACollection] = rna_store.get_related_dna_cases_with_samples(
613+
rna_sample.links[0].case
614+
)
613615

614616
# THEN the RNADNACollection should contain the RNA sample
615-
assert rna_sample_son_id == rna_dna_collection.rna_sample_internal_id
617+
assert rna_sample_son_id == rna_dna_collection[0].rna_sample_id
616618

617619
# THEN the RNADNACollection should have its dna_sample_id set to the related dna_sample_id
618-
assert dna_sample_son_id == rna_dna_collection.dna_sample_name
620+
assert dna_sample_son_id == rna_dna_collection[0].dna_sample_name
619621

620622

621623
def test_add_dna_cases_to_dna_sample(
@@ -632,10 +634,12 @@ def test_add_dna_cases_to_dna_sample(
632634
dna_case: Case = rna_store.get_case_by_internal_id(internal_id=dna_case_id)
633635

634636
# WHEN adding creating the RNADNACollection
635-
rna_dna_collection: RNADNACollection = upload_scout_api.create_rna_dna_collection(rna_sample)
637+
rna_dna_collection: list[RNADNACollection] = rna_store.get_related_dna_cases_with_samples(
638+
rna_sample.links[0].case
639+
)
636640

637641
# THEN the DNA cases should contain the DNA_case name associated with the DNA sample
638-
assert dna_case.internal_id in rna_dna_collection.dna_case_ids
642+
assert dna_case.internal_id in rna_dna_collection[0].dna_case_ids
639643

640644

641645
def test_map_dna_cases_to_dna_sample_incorrect_workflow(
@@ -776,8 +780,8 @@ def test_upload_rna_multiqc_report_to_successful_dna_case_in_scout(
776780
)
777781

778782
# WHEN finding the related DNA case
779-
dna_case_ids: Set[str] = upload_mip_analysis_scout_api.get_unique_dna_cases_related_to_rna_case(
780-
case_id=rna_case_id
783+
dna_case_ids: Set[str] = upload_mip_analysis_scout_api.get_related_uploaded_dna_cases(
784+
rna_case_id
781785
)
782786

783787
# THEN the api should know that it should find related DNA cases
@@ -802,7 +806,7 @@ def test_upload_tomte_rna_multiqc_report_to_successful_dna_case_in_scout(
802806

803807
caplog.set_level(logging.INFO)
804808

805-
# GIVEN an RNA case, and an store with an rna connected to it
809+
# GIVEN an RNA case, and a store with an rna connected to it
806810
upload_mip_analysis_scout_api.status_db: Store = rna_store
807811

808812
# GIVEN an RNA case with a multiqc-htlml report
@@ -819,8 +823,8 @@ def test_upload_tomte_rna_multiqc_report_to_successful_dna_case_in_scout(
819823
)
820824

821825
# WHEN finding the related DNA case
822-
dna_case_ids: Set[str] = upload_mip_analysis_scout_api.get_unique_dna_cases_related_to_rna_case(
823-
case_id=rna_case_id
826+
dna_case_ids: Set[str] = upload_mip_analysis_scout_api.get_related_uploaded_dna_cases(
827+
rna_case_id
824828
)
825829

826830
# THEN the api should know that it should find related DNA cases
@@ -862,8 +866,8 @@ def test_upload_rna_delivery_report_to_successful_dna_case_in_scout(
862866
)
863867

864868
# WHEN finding the related DNA case
865-
dna_case_ids: Set[str] = upload_mip_analysis_scout_api.get_unique_dna_cases_related_to_rna_case(
866-
case_id=rna_case_id
869+
dna_case_ids: Set[str] = upload_mip_analysis_scout_api.get_related_uploaded_dna_cases(
870+
rna_case_id
867871
)
868872

869873
# THEN the api should know that it should find related DNA cases
@@ -905,16 +909,12 @@ def test_upload_tomte_rna_delivery_report_to_successful_dna_case_in_scout(
905909
)
906910

907911
# WHEN finding the related DNA case
908-
dna_case_ids: Set[str] = (
909-
upload_tomte_analysis_scout_api.get_unique_dna_cases_related_to_rna_case(
910-
case_id=rna_case_id
911-
)
912+
dna_case_ids: Set[str] = upload_tomte_analysis_scout_api.get_related_uploaded_dna_cases(
913+
rna_case_id
912914
)
913915

914-
dna_case_ids: Set[str] = (
915-
upload_tomte_analysis_scout_api.get_unique_dna_cases_related_to_rna_case(
916-
case_id=rna_case_id
917-
)
916+
dna_case_ids: Set[str] = upload_tomte_analysis_scout_api.get_related_uploaded_dna_cases(
917+
rna_case_id
918918
)
919919
# THEN the dna case id should have been mentioned in the logging (and used in the upload)
920920

@@ -956,8 +956,8 @@ def test_upload_rna_report_to_not_yet_uploaded_dna_case_in_scout(
956956
)[0]
957957

958958
# WHEN finding the related DNA case with no successful upload
959-
dna_case_ids: Set[str] = upload_mip_analysis_scout_api.get_unique_dna_cases_related_to_rna_case(
960-
case_id=rna_case_id
959+
dna_case_ids: Set[str] = upload_mip_analysis_scout_api.get_related_uploaded_dna_cases(
960+
rna_case_id
961961
)
962962
dna_case: Case = rna_store.get_case_by_internal_id(internal_id=list(dna_case_ids)[0])
963963
dna_case.analyses[0].uploaded_at = None

tests/store/crud/conftest.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -146,25 +146,6 @@ def store_with_rna_and_dna_samples_and_cases(store: Store, helpers: StoreHelpers
146146
customer_id="cust001",
147147
)
148148

149-
helpers.add_sample(
150-
store=store,
151-
internal_id="related_dna_sample_2",
152-
application_tag=SeqLibraryPrepCategory.TARGETED_GENOME_SEQUENCING.value,
153-
application_type=SeqLibraryPrepCategory.TARGETED_GENOME_SEQUENCING.value,
154-
subject_id="subject_1",
155-
is_tumour=True,
156-
customer_id="cust000",
157-
)
158-
helpers.add_sample(
159-
store=store,
160-
internal_id="related_dna_sample_3",
161-
application_tag=SeqLibraryPrepCategory.WHOLE_EXOME_SEQUENCING.value,
162-
application_type=SeqLibraryPrepCategory.WHOLE_EXOME_SEQUENCING.value,
163-
subject_id="subject_1",
164-
is_tumour=True,
165-
customer_id="cust000",
166-
)
167-
168149
helpers.add_sample(
169150
store=store,
170151
internal_id="not_related_dna_sample",
@@ -238,22 +219,7 @@ def related_dna_samples(store_with_rna_and_dna_samples_and_cases: Store) -> list
238219
)
239220
)
240221

241-
related_dna_sample_2: Sample = (
242-
store_with_rna_and_dna_samples_and_cases.get_sample_by_internal_id(
243-
internal_id="related_dna_sample_2"
244-
)
245-
)
246-
related_dna_sample_3: Sample = (
247-
store_with_rna_and_dna_samples_and_cases.get_sample_by_internal_id(
248-
internal_id="related_dna_sample_3"
249-
)
250-
)
251-
252-
return [
253-
related_dna_sample_1,
254-
related_dna_sample_2,
255-
related_dna_sample_3,
256-
]
222+
return [related_dna_sample_1]
257223

258224

259225
@pytest.fixture

0 commit comments

Comments
 (0)