Skip to content

Commit

Permalink
G3-325 additional unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
francastell committed Aug 8, 2024
1 parent cc5df22 commit 06df4fe
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions tests/controllers/test_genesets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
from unittest.mock import patch

import pytest
from geneweaver.api.controller import message

from tests.data import test_geneset_data, test_ontology_data, test_publication_data
Expand Down Expand Up @@ -398,3 +399,71 @@ def test_delete_geneset_ontology_terms_errors(mock_delete_genenset_onto_terms, c
}
response = client.delete("/api/genesets/1234/ontologies/D001921")
assert response.status_code == 404


@pytest.mark.parametrize("score_type", ["1", "binary"])
@patch("geneweaver.api.services.geneset.get_visible_genesets")
def test_get_geneset_by_score_type(mock_get_visible_genesets, score_type, client):
"""Test get geneset data response."""
mock_get_visible_genesets.return_value = geneset_by_id_resp.get("geneset")

response = client.get("/api/genesets?score_type=" + score_type)
assert response.status_code == 200
assert response.json() == geneset_by_id_resp.get("geneset")


@patch("geneweaver.api.services.geneset.get_visible_genesets")
def test_get_geneset_by_create_date(mock_get_visible_genesets, client):
"""Test get geneset data response."""
mock_get_visible_genesets.return_value = geneset_by_id_resp.get("geneset")

response = client.get(
"/api/genesets?created_after=2023-08-01&created_before=2024-07-01"
)
assert response.status_code == 200
assert response.json() == geneset_by_id_resp.get("geneset")


@patch("geneweaver.api.services.geneset.get_visible_genesets")
def test_get_geneset_by_update_date(mock_get_visible_genesets, client):
"""Test get geneset data response."""
mock_get_visible_genesets.return_value = geneset_by_id_resp.get("geneset")

response = client.get(
"/api/genesets?updated_after=2023-08-01&updated_before=2024-07-01"
)
assert response.status_code == 200
assert response.json() == geneset_by_id_resp.get("geneset")


@pytest.mark.parametrize("score_type", ["2342", "test"])
def test_invalid_score_type(score_type, client):
"""Test general get geneset data no parameters -- default limit."""
response = client.get("/api/genesets?score_type=" + score_type)
assert response.status_code == 422


@pytest.mark.parametrize("created_before", ["20-23-20", "08-01-2023", "80/01/2022"])
@pytest.mark.parametrize("created_after", ["20-23-20", "08-01-2023", "80/01/2022"])
def test_invalid_create_date_params(created_before, created_after, client):
"""Test general get geneset data no parameters -- default limit."""
response = client.get(
"/api/genesets?created_before="
+ created_before
+ ",created_after="
+ created_after
)
assert response.status_code == 422


@pytest.mark.parametrize("updated_before", ["20-23-20", "08-01-2023", "80/01/2022"])
@pytest.mark.parametrize("updated_after", ["20-23-20", "08-01-2023", "80/01/2022"])
def test_invalid_update_date_params(updated_before, updated_after, client):
"""Test general get geneset data no parameters -- default limit."""
response = client.get(
"/api/genesets?created_before="
+ updated_before
+ ",created_after="
+ updated_after
)
assert response.status_code == 422

0 comments on commit 06df4fe

Please sign in to comment.