File size: 2,903 Bytes
af567cf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | import pytest
from pydantic import ValidationError
from app.models.variant import (
VariantSearchRequest,
VariantInfo,
ClinVarInfo,
GnomADInfo,
ACMGInfo,
VariantResponse,
)
class TestVariantModels:
def test_variant_search_request_defaults(self):
req = VariantSearchRequest(query="test")
assert req.genome_build == "hg38"
def test_variant_search_request_custom_genome(self):
req = VariantSearchRequest(query="test", genome_build="hg19")
assert req.genome_build == "hg19"
def test_variant_info_required_fields(self):
v = VariantInfo(
id="9-135800978-A-G",
chromosome="9",
position=135800978,
ref="A",
alt="G"
)
assert v.id == "9-135800978-A-G"
assert v.chromosome == "9"
def test_variant_info_optional_fields(self):
v = VariantInfo(
id="test",
chromosome="1",
position=100,
ref="A",
alt="G",
gene="BRCA1",
protein_change="p.Arg1234Ser"
)
assert v.gene == "BRCA1"
assert v.protein_change == "p.Arg1234Ser"
def test_clinvar_info(self):
c = ClinVarInfo(
classification="Pathogenic",
disease="Breast cancer",
accession="RCV000123456"
)
assert c.classification == "Pathogenic"
assert c.disease == "Breast cancer"
def test_gnomad_info(self):
g = GnomADInfo(
exomes_af=0.001,
genomes_af=0.0005,
exomes_ac=100,
genomes_ac=50
)
assert g.exomes_af == 0.001
assert g.exomes_ac == 100
def test_acmg_info(self):
a = ACMGInfo(
classification="Pathogenic",
criteria="PS1,PM2,PP3"
)
assert a.classification == "Pathogenic"
assert "PS1" in a.criteria
def test_variant_response_full(self):
v = VariantInfo(id="test", chromosome="1", position=100, ref="A", alt="G")
c = ClinVarInfo(classification="Pathogenic")
g = GnomADInfo(exomes_af=0.001)
a = ACMGInfo(classification="Pathogenic")
response = VariantResponse(
variant=v,
clinvar=c,
gnomad=g,
acmg=a
)
assert response.variant.id == "test"
assert response.clinvar.classification == "Pathogenic"
assert response.gnomad.exomes_af == 0.001
assert response.acmg.classification == "Pathogenic"
def test_variant_response_minimal(self):
v = VariantInfo(id="test", chromosome="1", position=100, ref="A", alt="G")
response = VariantResponse(variant=v)
assert response.variant.id == "test"
assert response.clinvar is None
assert response.gnomad is None
assert response.acmg is None
|