Skip to content

Commit

Permalink
Add test for graphql phenotypes
Browse files Browse the repository at this point in the history
  • Loading branch information
illusional committed Sep 13, 2023
1 parent 6592b21 commit b18e3c3
Showing 1 changed file with 48 additions and 23 deletions.
71 changes: 48 additions & 23 deletions test/test_graphql.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
from test.testbase import DbIsolatedTest, run_as_sync

from graphql.error import GraphQLError, GraphQLSyntaxError

import api.graphql.schema
from db.python.layers import ParticipantLayer, AnalysisLayer
from db.python.layers import AnalysisLayer, ParticipantLayer
from metamist.graphql import configure_sync_client, gql, validate
from models.enums import AnalysisStatus
from models.models import (
SampleUpsertInternal,
AnalysisInternal,
AssayUpsertInternal,
ParticipantUpsertInternal,
SampleUpsertInternal,
SequencingGroupUpsertInternal,
AssayUpsertInternal,
AnalysisInternal,
)
from models.utils.sequencing_group_id_format import sequencing_group_id_format
from models.enums import AnalysisStatus

from metamist.graphql import gql, validate, configure_sync_client


default_assay_meta = {
'sequencing_type': 'genome',
Expand All @@ -24,7 +23,6 @@


def _get_single_participant_upsert():

return ParticipantUpsertInternal(
external_id='Demeter',
meta={},
Expand All @@ -43,20 +41,20 @@ def _get_single_participant_upsert():
type='sequencing',
meta={
'reads': [
{
'basename': 'sample_id001.filename-R1.fastq.gz',
'checksum': None,
'class': 'File',
'location': '/path/to/sample_id001.filename-R1.fastq.gz',
'size': 111,
},
{
'basename': 'sample_id001.filename-R2.fastq.gz',
'checksum': None,
'class': 'File',
'location': '/path/to/sample_id001.filename-R2.fastq.gz',
'size': 111,
},
{
'basename': 'sample_id001.filename-R1.fastq.gz',
'checksum': None,
'class': 'File',
'location': '/path/to/sample_id001.filename-R1.fastq.gz',
'size': 111,
},
{
'basename': 'sample_id001.filename-R2.fastq.gz',
'checksum': None,
'class': 'File',
'location': '/path/to/sample_id001.filename-R2.fastq.gz',
'size': 111,
},
],
'reads_type': 'fastq',
'batch': 'M001',
Expand Down Expand Up @@ -231,3 +229,30 @@ async def test_sg_analyses_query(self):
self.assertIn('id', analyses[0])
self.assertIn('meta', analyses[0])
self.assertIn('output', analyses[0])

@run_as_sync
async def test_participant_phenotypes(self):
"""
Test getting participant phentypes in graphql
"""
# insert participant
p = await self.player.upsert_participant(
ParticipantUpsertInternal(external_id='Demeter', meta={}, samples=[])
)

phenotypes = {'phenotype1': 'value1', 'phenotype2': {'number': 123}}
# insert participant_phenotypes
await self.player.insert_participant_phenotypes({p.id: phenotypes})

q = """
query MyQuery($pid: Int!) {
participant(id: $pid) {
phenotypes
}
}"""

resp = await self.run_graphql_query_async(q, {'pid': p.id})

self.assertIn('participant', resp)
self.assertIn('phenotypes', resp['participant'])
self.assertDictEqual(phenotypes, resp['participant']['phenotypes'])

0 comments on commit b18e3c3

Please sign in to comment.