Skip to content

Commit

Permalink
✅ Test filter params, error handling, pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
znatty22 committed May 22, 2024
1 parent e1ec30d commit 9fa7fdd
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from dataservice.api.family_relationship.models import FamilyRelationship
from dataservice.api.biospecimen.models import Biospecimen
from dataservice.api.sample.models import Sample
from dataservice.api.sample_relationship.models import SampleRelationship
from dataservice.api.diagnosis.models import Diagnosis
from dataservice.api.outcome.models import Outcome
from dataservice.api.phenotype.models import Phenotype
Expand Down Expand Up @@ -57,6 +58,7 @@
Phenotype: '/phenotypes',
Outcome: '/outcomes',
Sample: '/samples',
SampleRelationship: '/sample-relationships',
Biospecimen: '/biospecimens',
GenomicFile: '/genomic-files',
BiospecimenGenomicFile: '/biospecimen-genomic-files',
Expand Down Expand Up @@ -162,6 +164,7 @@ def make_entities(client):
BiospecimenDiagnosis,
ReadGroupGenomicFile,
SequencingExperimentGenomicFile,
SampleRelationship,
Sample}:
continue
for i in range(ENTITY_TOTAL):
Expand Down Expand Up @@ -302,6 +305,20 @@ def make_entities(client):
)
db.session.add(s)
_entities[Sample].append(s)

# Sample relationships
for parent, child in iterate_pairwise(_entities[Sample]):
r = SampleRelationship(
parent=parent,
child=child,
external_parent_id=parent.external_id,
external_child_id=child.external_id,
)
if model not in _entities:
_entities[SampleRelationship] = []
_entities[SampleRelationship].append(r)
db.session.add(r)

db.session.commit()

return _entities
Expand Down
11 changes: 11 additions & 0 deletions tests/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
"preservation_method": "Fresh",
"visible": true
},
"/sample-relationships": {
"external_parent_id": "SA-parent",
"external_child_id": "SA-child"
},
"/diagnoses": {
"external_id": "d0",
"diagnosis_category": "Structural Birth Defect",
Expand Down Expand Up @@ -227,6 +231,13 @@
},
"invalid": []
},
"/sample-relationships": {
"valid": {
"external_parent_id": "sa-001",
"external_child_id": "sa-002"
},
"invalid": []
},
"/diagnoses": {
"valid": {
"diagnosis_category": "Cancer",
Expand Down
5 changes: 5 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def test_status_format(self, client, endpoint, method):
('/investigators', []),
('/participants', ['study', 'family']),
('/family-relationships', ['participant1', 'participant2']),
('/sample-relationships', ['parent', 'child']),
('/phenotypes', ['participant']),
('/outcomes', ['participant']),
('/diagnoses', ['participant', 'biospecimens']),
Expand Down Expand Up @@ -353,6 +354,8 @@ def test_bad_visibility_reason(self, client, entities, endpoint):
('/genomic-files', 'hashes'),
('/diagnoses', 'participant_id'),
('/samples', 'participant_id'),
('/sample-relationships', 'parent_id'),
('/sample-relationships', 'child_id'),
('/biospecimens', 'analyte_type'),
('/sequencing-centers', 'name')
])
Expand Down Expand Up @@ -392,6 +395,8 @@ def test_missing_required_params(self, client, entities, endpoint,
('/biospecimens', 'participant_id'),
('/biospecimens', 'sample_id'),
('/samples', 'participant_id'),
('/sample-relationships', 'parent_id'),
('/sample-relationships', 'child_id'),
('/tasks', 'cavatica_app_id'),
('/task-genomic-files',
'task_id'),
Expand Down
13 changes: 13 additions & 0 deletions tests/test_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ def participants(client):
participant1_to_participant2_relation=rel)
db.session.add(r)

# Sample relationships
for p1, p2 in iterate_pairwise(participants):
# Biologically incorrect, but done for testing only
parent = p1.samples[0]
child = p2.samples[0]
r = SampleRelationship(
parent=parent,
child=child,
external_parent_id=parent.external_id,
external_child_id=child.external_id,
)
db.session.add(r)

db.session.commit()

@pytest.mark.parametrize('endpoint, expected_total', [
Expand Down

0 comments on commit 9fa7fdd

Please sign in to comment.