From d28870fbc03d216314210b16fb425a836255938e Mon Sep 17 00:00:00 2001 From: Katie Stahl Date: Sat, 3 Aug 2024 15:13:03 -0500 Subject: [PATCH] fixing tests and adjusting variable casing --- .../RegulatoryElementInput.tsx | 4 +- client/src/services/ResponseModels.ts | 4 +- client/src/services/main.tsx | 4 +- server/src/curfu/routers/constructors.py | 2 +- server/src/curfu/schemas.py | 12 ++-- server/tests/integration/test_constructors.py | 63 +++++++------------ 6 files changed, 33 insertions(+), 56 deletions(-) diff --git a/client/src/components/Pages/Structure/Input/RegulatoryElementInput/RegulatoryElementInput.tsx b/client/src/components/Pages/Structure/Input/RegulatoryElementInput/RegulatoryElementInput.tsx index 1589220b..fa52cce7 100644 --- a/client/src/components/Pages/Structure/Input/RegulatoryElementInput/RegulatoryElementInput.tsx +++ b/client/src/components/Pages/Structure/Input/RegulatoryElementInput/RegulatoryElementInput.tsx @@ -75,7 +75,7 @@ const RegulatoryElementInput: React.FC = ({ if (reResponse.warnings && reResponse.warnings.length > 0) { throw new Error(reResponse.warnings[0]); } - getRegElementNomenclature(reResponse.regulatory_element).then( + getRegElementNomenclature(reResponse.regulatoryElement).then( (nomenclatureResponse) => { if ( nomenclatureResponse.warnings && @@ -84,7 +84,7 @@ const RegulatoryElementInput: React.FC = ({ throw new Error(nomenclatureResponse.warnings[0]); } const newRegElement: ClientRegulatoryElement = { - ...reResponse.regulatory_element, + ...reResponse.regulatoryElement, elementId: element.elementId, displayClass: regulatoryClassItems[elementClass][1], nomenclature: nomenclatureResponse.nomenclature || "", diff --git a/client/src/services/ResponseModels.ts b/client/src/services/ResponseModels.ts index 6b2fde11..9aaeb169 100644 --- a/client/src/services/ResponseModels.ts +++ b/client/src/services/ResponseModels.ts @@ -762,7 +762,7 @@ export interface NormalizeGeneResponse { */ export interface RegulatoryElementResponse { warnings?: string[] | null; - regulatory_element: RegulatoryElement; + regulatoryElement: RegulatoryElement; } /** * Abstract Response class for defining API response structures. @@ -820,5 +820,5 @@ export interface TxSegmentElementResponse { */ export interface ValidateFusionResponse { warnings?: string[] | null; - fusion: CategoricalFusion | AssayedFusion | null; + fusion?: CategoricalFusion | AssayedFusion | null; } diff --git a/client/src/services/main.tsx b/client/src/services/main.tsx index edd2d99e..1b9d9587 100644 --- a/client/src/services/main.tsx +++ b/client/src/services/main.tsx @@ -30,8 +30,6 @@ import { ClientCategoricalFusion, ClientAssayedFusion, ValidateFusionResponse, - AssayedFusion, - CategoricalFusion, NomenclatureResponse, RegulatoryElement, RegulatoryClass, @@ -427,7 +425,7 @@ export const getRegulatoryElement = async ( geneName: string ): Promise => { const response = await fetch( - `/api/construct/regulatoryElement?element_class=${regulatoryClass}&gene_name=${geneName}` + `/api/construct/regulatory_element?element_class=${regulatoryClass}&gene_name=${geneName}` ); const responseJson = await response.json(); return responseJson; diff --git a/server/src/curfu/routers/constructors.py b/server/src/curfu/routers/constructors.py index 1846d1f6..13366249 100644 --- a/server/src/curfu/routers/constructors.py +++ b/server/src/curfu/routers/constructors.py @@ -283,4 +283,4 @@ def build_regulatory_element( element, warnings = request.app.state.fusor.regulatory_element( normalized_class, gene_name ) - return {"regulatory_element": element, "warnings": warnings} + return {"regulatoryElement": element, "warnings": warnings} diff --git a/server/src/curfu/schemas.py b/server/src/curfu/schemas.py index b36631ef..736cee73 100644 --- a/server/src/curfu/schemas.py +++ b/server/src/curfu/schemas.py @@ -23,7 +23,7 @@ TranscriptSegmentElement, UnknownGeneElement, ) -from pydantic import BaseModel, Extra, Field, StrictInt, StrictStr, validator +from pydantic import BaseModel, Field, StrictInt, StrictStr, field_validator ResponseWarnings = list[StrictStr] | None @@ -95,7 +95,7 @@ class ClientFunctionalDomain(FunctionalDomain): class Config: """Configure class.""" - extra = Extra.forbid + extra = "forbid" class ClientRegulatoryElement(RegulatoryElement, ClientStructuralElement): @@ -113,7 +113,7 @@ class Response(BaseModel): class Config: """Configure class""" - extra = Extra.forbid + extra = "forbid" class GeneElementResponse(Response): @@ -194,14 +194,14 @@ class ExonCoordsRequest(BaseModel): exonEnd: StrictInt | None = 0 exonEndOffset: StrictInt | None = 0 - @validator("gene") + @field_validator("gene") def validate_gene(cls, v) -> str: """Replace None with empty string.""" if v is None: return "" return v - @validator("exonStart", "exonStartOffset", "exonEnd", "exonEndOffset") + @field_validator("exonStart", "exonStartOffset", "exonEnd", "exonEndOffset") def validate_number(cls, v) -> int: """Replace None with 0 for numeric fields.""" if v is None: @@ -329,7 +329,7 @@ class NomenclatureResponse(Response): class RegulatoryElementResponse(Response): """Response model for regulatory element constructor.""" - regulatory_element: RegulatoryElement + regulatoryElement: RegulatoryElement class DemoResponse(Response): diff --git a/server/tests/integration/test_constructors.py b/server/tests/integration/test_constructors.py index c9f1fb3a..36e5ba0d 100644 --- a/server/tests/integration/test_constructors.py +++ b/server/tests/integration/test_constructors.py @@ -135,7 +135,7 @@ async def test_build_tx_segment_ect( coordinates and transcript. """ await check_response( - "/api/construct/structural_element/tx_segment_ect?transcript=NM_002529.3&exonStart=2&exonStartOffset=1", + "/api/construct/structural_element/tx_segment_ect?transcript=NM_002529.3&exon_start=2&exon_start_offset=1", {"element": ntrk1_tx_element_start}, check_tx_element_response, ) @@ -149,7 +149,7 @@ async def test_build_tx_segment_ect( # test handle invalid transcript await check_response( - "/api/construct/structural_element/tx_segment_ect?transcript=NM_0012529.3&exonStart=3", + "/api/construct/structural_element/tx_segment_ect?transcript=NM_0012529.3&exon_start=3", {"warnings": ["Unable to get exons for NM_0012529.3"]}, check_tx_element_response, ) @@ -192,7 +192,7 @@ async def test_build_segment_gcg( async def test_build_reg_element(check_response, check_reg_element_response): """Test correctness of regulatory element constructor endpoint.""" await check_response( - "/api/construct/regulatoryElement?element_class=promoter&gene_name=braf", + "/api/construct/regulatory_element?element_class=promoter&gene_name=braf", { "regulatoryElement": { "associatedGene": { @@ -213,52 +213,31 @@ async def test_build_templated_sequence( check_response, check_templated_sequence_response ): """Test correct functioning of templated sequence constructor""" - await check_response( - "/api/construct/structural_element/templated_sequence?start=154171415&end=154171417&sequence_id=NC_000001.11&strand=-", - { - "element": { - "type": "TemplatedSequenceElement", - "region": { - "id": "fusor.location_descriptor:NC_000001.11", - "type": "SequenceLocation", - "location_id": "ga4gh:VSL.K_suWpotWJZL0EFYUqoZckNq4bqEjH-z", - "location": { - "type": "SequenceLocation", - "sequence_id": "refseq:NC_000001.11", - "interval": { - "type": "SequenceInterval", - "start": {"type": "Number", "value": 154171414}, - "end": {"type": "Number", "value": 154171417}, - }, - }, + expected = { + "element": { + "type": "TemplatedSequenceElement", + "region": { + "id": "ga4gh:SL.thjDCmA1u2mB0vLGjgQbCOEg81eP5hdO", + "type": "SequenceLocation", + "sequenceReference": { + "id": "refseq:NC_000001.11", + "refgetAccession": "", + "type": "SequenceReference", }, - "strand": "-", + "start": 154171414, + "end": 154171417, }, + "strand": -1, }, + } + await check_response( + "/api/construct/structural_element/templated_sequence?start=154171415&end=154171417&sequence_id=NC_000001.11&strand=-", + expected, check_templated_sequence_response, ) await check_response( "/api/construct/structural_element/templated_sequence?start=154171415&end=154171417&sequence_id=refseq%3ANC_000001.11&strand=-", - { - "element": { - "type": "TemplatedSequenceElement", - "region": { - "id": "fusor.location_descriptor:NC_000001.11", - "type": "SequenceLocation", - "location_id": "ga4gh:VSL.K_suWpotWJZL0EFYUqoZckNq4bqEjH-z", - "location": { - "type": "SequenceLocation", - "sequence_id": "refseq:NC_000001.11", - "interval": { - "type": "SequenceInterval", - "start": {"type": "Number", "value": 154171414}, - "end": {"type": "Number", "value": 154171417}, - }, - }, - }, - "strand": "-", - }, - }, + expected, check_templated_sequence_response, )