Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Chiara Rasi committed Oct 7, 2024
1 parent 4155309 commit 56afd0b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/chanjo2/endpoints/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async def demo_mane_overview(

return templates.TemplateResponse(
request=request,
name="mane_overview.html",
name="mane-overview.html",
context=get_mane_overview_coverage_stats(query=overview_query, session=db),
)

Expand Down Expand Up @@ -161,6 +161,6 @@ async def mane_overview(

return templates.TemplateResponse(
request=request,
name="mane_overview.html",
name="mane-overview.html",
context=get_mane_overview_coverage_stats(query=overview_query, session=db),
)
File renamed without changes.
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ class Endpoints(str):
REPORT = "/report"
GENE_OVERVIEW = "/gene_overview"
OVERVIEW = "/overview"
OVERVIEW_DEMO = "/overview/demo/"
OVERVIEW_DEMO = "/overview/demo"
MANE_OVERVIEW_DEMO = "/mane_overview/demo"
MANE_OVERVIEW = "/mane_overview"


@pytest.fixture
Expand Down
43 changes: 42 additions & 1 deletion tests/src/chanjo2/endpoints/test_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fastapi.testclient import TestClient
from requests.models import Response

from chanjo2.constants import BUILD_37, DEFAULT_COMPLETENESS_LEVELS
from chanjo2.constants import BUILD_37, BUILD_38, DEFAULT_COMPLETENESS_LEVELS
from chanjo2.demo import DEMO_COVERAGE_QUERY_FORM


Expand Down Expand Up @@ -63,3 +63,44 @@ def test_gene_overview(

# And return an HTML page
assert response.template.name == "gene-overview.html"


def test_demo_mane_overview(client: TestClient, endpoints: Type):
"""Test the endpoint that shows coverage over the MANE transcripts of a list of genes."""

# GIVEN a query to the demo genes coverage overview endpoint
response: Response = client.get(endpoints.MANE_OVERVIEW_DEMO)

# Then the request should be successful
assert response.status_code == status.HTTP_200_OK

# And return an HTML page
assert response.template.name == "mane-overview.html"


def test_mane_overview(
client: TestClient, endpoints: Type, genomic_ids_per_build: Dict[str, List]
):
"""Test the endpoint that shows coverage over the MANE transcripts for a custom list of genes."""

# GIVEN a POST request containing form data:
form_data = {
"build": BUILD_38,
"completeness_thresholds": DEFAULT_COMPLETENESS_LEVELS,
"hgnc_gene_id": genomic_ids_per_build[BUILD_38]["hgnc_ids"],
"samples": str(DEMO_COVERAGE_QUERY_FORM["samples"]),
"interval_type": "transcripts",
}

# GIVEN a query to the mane overview endpoint
response: Response = client.post(
endpoints.MANE_OVERVIEW,
data=form_data,
headers={"Content-Type": "application/x-www-form-urlencoded"},
)

# Then the request should be successful
assert response.status_code == status.HTTP_200_OK

# And return an HTML page
assert response.template.name == "mane-overview.html"

0 comments on commit 56afd0b

Please sign in to comment.