Skip to content

Commit

Permalink
fixing tests and adjusting variable casing
Browse files Browse the repository at this point in the history
  • Loading branch information
katiestahl committed Aug 3, 2024
1 parent aa3af6c commit d28870f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const RegulatoryElementInput: React.FC<RegulatoryElementInputProps> = ({
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 &&
Expand All @@ -84,7 +84,7 @@ const RegulatoryElementInput: React.FC<RegulatoryElementInputProps> = ({
throw new Error(nomenclatureResponse.warnings[0]);
}
const newRegElement: ClientRegulatoryElement = {
...reResponse.regulatory_element,
...reResponse.regulatoryElement,
elementId: element.elementId,
displayClass: regulatoryClassItems[elementClass][1],
nomenclature: nomenclatureResponse.nomenclature || "",
Expand Down
4 changes: 2 additions & 2 deletions client/src/services/ResponseModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -820,5 +820,5 @@ export interface TxSegmentElementResponse {
*/
export interface ValidateFusionResponse {
warnings?: string[] | null;
fusion: CategoricalFusion | AssayedFusion | null;
fusion?: CategoricalFusion | AssayedFusion | null;
}
4 changes: 1 addition & 3 deletions client/src/services/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import {
ClientCategoricalFusion,
ClientAssayedFusion,
ValidateFusionResponse,
AssayedFusion,
CategoricalFusion,
NomenclatureResponse,
RegulatoryElement,
RegulatoryClass,
Expand Down Expand Up @@ -427,7 +425,7 @@ export const getRegulatoryElement = async (
geneName: string
): Promise<RegulatoryElementResponse> => {
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;
Expand Down
2 changes: 1 addition & 1 deletion server/src/curfu/routers/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
12 changes: 6 additions & 6 deletions server/src/curfu/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -95,7 +95,7 @@ class ClientFunctionalDomain(FunctionalDomain):
class Config:
"""Configure class."""

extra = Extra.forbid
extra = "forbid"


class ClientRegulatoryElement(RegulatoryElement, ClientStructuralElement):
Expand All @@ -113,7 +113,7 @@ class Response(BaseModel):
class Config:
"""Configure class"""

extra = Extra.forbid
extra = "forbid"


class GeneElementResponse(Response):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -329,7 +329,7 @@ class NomenclatureResponse(Response):
class RegulatoryElementResponse(Response):
"""Response model for regulatory element constructor."""

regulatory_element: RegulatoryElement
regulatoryElement: RegulatoryElement


class DemoResponse(Response):
Expand Down
63 changes: 21 additions & 42 deletions server/tests/integration/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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,
)
Expand Down Expand Up @@ -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": {
Expand All @@ -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,
)

0 comments on commit d28870f

Please sign in to comment.