diff --git a/tests/controllers/test_genesets.py b/tests/controllers/test_genesets.py index df0cfc5..4e1b21b 100644 --- a/tests/controllers/test_genesets.py +++ b/tests/controllers/test_genesets.py @@ -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 @@ -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