Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some basic tests. #279

Merged
merged 7 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions tests/routers/test_score_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,41 @@ def test_search_score_sets_match(session, data_provider, client, setup_router_db
assert response.json()[0]["title"] == score_set_1_1["title"]


def test_search_score_sets_urn_match(session, data_provider, client, setup_router_db, data_files):
experiment_1 = create_experiment(client)
score_set_1_1 = create_seq_score_set_with_variants(
client,
session,
data_provider,
experiment_1["urn"],
data_files / "scores.csv"
)

search_payload = {"urn": score_set_1_1['urn']}
response = client.post("/api/v1/score-sets/search", json=search_payload)
assert response.status_code == 200
assert len(response.json()) == 1
assert response.json()[0]["urn"] == score_set_1_1["urn"]


# There is space in the end of test urn. The search result returned nothing before.
def test_search_score_sets_urn_with_space_match(session, data_provider, client, setup_router_db, data_files):
experiment_1 = create_experiment(client)
score_set_1_1 = create_seq_score_set_with_variants(
client,
session,
data_provider,
experiment_1["urn"],
data_files / "scores.csv"
)
urn_with_space = score_set_1_1['urn'] + " "
search_payload = {"urn": urn_with_space}
response = client.post("/api/v1/score-sets/search", json=search_payload)
assert response.status_code == 200
assert len(response.json()) == 1
assert response.json()[0]["urn"] == score_set_1_1["urn"]


def test_anonymous_cannot_delete_other_users_private_scoreset(
session, data_provider, client, setup_router_db, data_files, anonymous_app_overrides
):
Expand Down
153 changes: 153 additions & 0 deletions tests/view_models/test_experiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import pytest
from fastapi.encoders import jsonable_encoder

from mavedb.view_models.experiment import ExperimentCreate
from tests.helpers.constants import TEST_MINIMAL_EXPERIMENT


# Test valid experiment
def test_create_experiment():
experiment = ExperimentCreate(**jsonable_encoder(TEST_MINIMAL_EXPERIMENT))
assert experiment.title == "Test Experiment Title"
assert experiment.short_description == "Test experiment"
assert experiment.abstract_text == "Abstract"
assert experiment.method_text == "Methods"


def test_cannot_create_experiment_without_a_title():
experiment = TEST_MINIMAL_EXPERIMENT.copy()
invalid_experiment = jsonable_encoder(experiment, exclude={"title"})
with pytest.raises(ValueError) as exc_info:
ExperimentCreate(**invalid_experiment)

assert "field required" in str(exc_info.value)
assert "title" in str(exc_info.value)


def test_cannot_create_experiment_with_a_space_title():
experiment = TEST_MINIMAL_EXPERIMENT.copy()
invalid_experiment = jsonable_encoder(experiment, exclude={"title"})
invalid_experiment["title"] = " "

with pytest.raises(ValueError) as exc_info:
ExperimentCreate(**invalid_experiment)

assert "This field is required and cannot be empty." in str(exc_info.value)
assert "title" in str(exc_info.value)


def test_cannot_create_experiment_with_an_empty_title():
experiment = TEST_MINIMAL_EXPERIMENT.copy()
invalid_experiment = jsonable_encoder(experiment, exclude={"title"})
invalid_experiment["title"] = ""

with pytest.raises(ValueError) as exc_info:
ExperimentCreate(**invalid_experiment)

assert "none is not an allowed value" in str(exc_info.value)
assert "title" in str(exc_info.value)


def test_cannot_create_experiment_without_a_short_description():
experiment = TEST_MINIMAL_EXPERIMENT.copy()
invalid_experiment = jsonable_encoder(experiment, exclude={"shortDescription"})

with pytest.raises(ValueError) as exc_info:
ExperimentCreate(**invalid_experiment)

assert "field required" in str(exc_info.value)
assert "shortDescription" in str(exc_info.value)


def test_cannot_create_experiment_with_a_space_short_description():
experiment = TEST_MINIMAL_EXPERIMENT.copy()
invalid_experiment = jsonable_encoder(experiment, exclude={"shortDescription"})
invalid_experiment["shortDescription"] = " "

with pytest.raises(ValueError) as exc_info:
ExperimentCreate(**invalid_experiment)

assert "This field is required and cannot be empty." in str(exc_info.value)
assert "shortDescription" in str(exc_info.value)


def test_cannot_create_experiment_with_an_empty_short_description():
experiment = TEST_MINIMAL_EXPERIMENT.copy()
invalid_experiment = jsonable_encoder(experiment, exclude={"shortDescription"})
invalid_experiment["shortDescription"] = ""

with pytest.raises(ValueError) as exc_info:
ExperimentCreate(**invalid_experiment)

assert "none is not an allowed value" in str(exc_info.value)
assert "shortDescription" in str(exc_info.value)


def test_cannot_create_experiment_without_an_abstract():
experiment = TEST_MINIMAL_EXPERIMENT.copy()
invalid_experiment = jsonable_encoder(experiment, exclude={"abstractText"})

with pytest.raises(ValueError) as exc_info:
ExperimentCreate(**invalid_experiment)

assert "field required" in str(exc_info.value)
assert "abstractText" in str(exc_info.value)


def test_cannot_create_experiment_with_a_space_abstract():
experiment = TEST_MINIMAL_EXPERIMENT.copy()
invalid_experiment = jsonable_encoder(experiment, exclude={"abstractText"})
invalid_experiment["abstractText"] = " "

with pytest.raises(ValueError) as exc_info:
ExperimentCreate(**invalid_experiment)

assert "This field is required and cannot be empty." in str(exc_info.value)
assert "abstractText" in str(exc_info.value)


def test_cannot_create_experiment_with_an_empty_abstract():
experiment = TEST_MINIMAL_EXPERIMENT.copy()
invalid_experiment = jsonable_encoder(experiment, exclude={"abstractText"})
invalid_experiment["abstractText"] = ""

with pytest.raises(ValueError) as exc_info:
ExperimentCreate(**invalid_experiment)

assert "none is not an allowed value" in str(exc_info.value)
assert "abstractText" in str(exc_info.value)


def test_cannot_create_experiment_without_a_method():
experiment = TEST_MINIMAL_EXPERIMENT.copy()
invalid_experiment = jsonable_encoder(experiment, exclude={"methodText"})

with pytest.raises(ValueError) as exc_info:
ExperimentCreate(**invalid_experiment)

assert "field required" in str(exc_info.value)
assert "methodText" in str(exc_info.value)


def test_cannot_create_experiment_with_a_space_method():
experiment = TEST_MINIMAL_EXPERIMENT.copy()
invalid_experiment = jsonable_encoder(experiment, exclude={"methodText"})
invalid_experiment["methodText"] = " "

with pytest.raises(ValueError) as exc_info:
ExperimentCreate(**invalid_experiment)

assert "This field is required and cannot be empty." in str(exc_info.value)
assert "methodText" in str(exc_info.value)


def test_cannot_create_experiment_with_an_empty_method():
experiment = TEST_MINIMAL_EXPERIMENT.copy()
invalid_experiment = jsonable_encoder(experiment, exclude={"methodText"})
invalid_experiment["methodText"] = ""

with pytest.raises(ValueError) as exc_info:
ExperimentCreate(**invalid_experiment)

assert "none is not an allowed value" in str(exc_info.value)
assert "methodText" in str(exc_info.value)
143 changes: 140 additions & 3 deletions tests/view_models/test_score_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

from fastapi.encoders import jsonable_encoder

from mavedb.view_models.score_set import ScoreSetModify
from mavedb.view_models.score_set import ScoreSetCreate, ScoreSetModify
from mavedb.view_models.target_gene import TargetGeneCreate
from mavedb.view_models.publication_identifier import PublicationIdentifierCreate

from tests.helpers.constants import TEST_MINIMAL_SEQ_SCORESET

import datetime


def test_cannot_create_score_set_without_a_target():
score_set_test = TEST_MINIMAL_SEQ_SCORESET.copy()
Expand Down Expand Up @@ -67,3 +65,142 @@ def test_cannot_create_score_set_with_non_unique_target_labels():
)

assert "Target sequence labels cannot be duplicated." in str(exc_info.value)


def test_cannot_create_score_set_without_a_title():
score_set = TEST_MINIMAL_SEQ_SCORESET.copy()
invalid_score_set = jsonable_encoder(score_set, exclude={"title"})
with pytest.raises(ValueError) as exc_info:
ScoreSetCreate(**invalid_score_set)

assert "field required" in str(exc_info.value)
assert "title" in str(exc_info.value)


def test_cannot_create_score_set_with_a_space_title():
score_set = TEST_MINIMAL_SEQ_SCORESET.copy()
invalid_score_set = jsonable_encoder(score_set, exclude={"title"})
invalid_score_set["title"] = " "

with pytest.raises(ValueError) as exc_info:
ScoreSetCreate(**invalid_score_set)

assert "This field is required and cannot be empty." in str(exc_info.value)
assert "title" in str(exc_info.value)


def test_cannot_create_score_set_with_an_empty_title():
score_set = TEST_MINIMAL_SEQ_SCORESET.copy()
invalid_score_set = jsonable_encoder(score_set, exclude={"title"})
invalid_score_set["title"] = ""

with pytest.raises(ValueError) as exc_info:
ScoreSetCreate(**invalid_score_set)

assert "none is not an allowed value" in str(exc_info.value)
assert "title" in str(exc_info.value)


def test_cannot_create_score_set_without_a_short_description():
score_set = TEST_MINIMAL_SEQ_SCORESET.copy()
invalid_score_set = jsonable_encoder(score_set, exclude={"shortDescription"})

with pytest.raises(ValueError) as exc_info:
ScoreSetCreate(**invalid_score_set)

assert "field required" in str(exc_info.value)
assert "shortDescription" in str(exc_info.value)


def test_cannot_create_score_set_with_a_space_short_description():
score_set = TEST_MINIMAL_SEQ_SCORESET.copy()
invalid_score_set = jsonable_encoder(score_set, exclude={"shortDescription"})
invalid_score_set["shortDescription"] = " "

with pytest.raises(ValueError) as exc_info:
ScoreSetCreate(**invalid_score_set)

assert "This field is required and cannot be empty." in str(exc_info.value)
assert "shortDescription" in str(exc_info.value)


def test_cannot_create_score_set_with_an_empty_short_description():
score_set = TEST_MINIMAL_SEQ_SCORESET.copy()
invalid_score_set = jsonable_encoder(score_set, exclude={"shortDescription"})
invalid_score_set["shortDescription"] = ""

with pytest.raises(ValueError) as exc_info:
ScoreSetCreate(**invalid_score_set)

assert "none is not an allowed value" in str(exc_info.value)
assert "shortDescription" in str(exc_info.value)


def test_cannot_create_score_set_without_an_abstract():
score_set = TEST_MINIMAL_SEQ_SCORESET.copy()
invalid_score_set = jsonable_encoder(score_set, exclude={"abstractText"})

with pytest.raises(ValueError) as exc_info:
ScoreSetCreate(**invalid_score_set)

assert "field required" in str(exc_info.value)
assert "abstractText" in str(exc_info.value)


def test_cannot_create_score_set_with_a_space_abstract():
score_set = TEST_MINIMAL_SEQ_SCORESET.copy()
invalid_score_set = jsonable_encoder(score_set, exclude={"abstractText"})
invalid_score_set["abstractText"] = " "

with pytest.raises(ValueError) as exc_info:
ScoreSetCreate(**invalid_score_set)

assert "This field is required and cannot be empty." in str(exc_info.value)
assert "abstractText" in str(exc_info.value)


def test_cannot_create_score_set_with_an_empty_abstract():
score_set = TEST_MINIMAL_SEQ_SCORESET.copy()
invalid_score_set = jsonable_encoder(score_set, exclude={"abstractText"})
invalid_score_set["abstractText"] = ""

with pytest.raises(ValueError) as exc_info:
ScoreSetCreate(**invalid_score_set)

assert "none is not an allowed value" in str(exc_info.value)
assert "abstractText" in str(exc_info.value)


def test_cannot_create_score_set_without_a_method():
score_set = TEST_MINIMAL_SEQ_SCORESET.copy()
invalid_score_set = jsonable_encoder(score_set, exclude={"methodText"})

with pytest.raises(ValueError) as exc_info:
ScoreSetCreate(**invalid_score_set)

assert "field required" in str(exc_info.value)
assert "methodText" in str(exc_info.value)


def test_cannot_create_score_set_with_a_space_method():
score_set = TEST_MINIMAL_SEQ_SCORESET.copy()
invalid_score_set = jsonable_encoder(score_set, exclude={"methodText"})
invalid_score_set["methodText"] = " "

with pytest.raises(ValueError) as exc_info:
ScoreSetCreate(**invalid_score_set)

assert "This field is required and cannot be empty." in str(exc_info.value)
assert "methodText" in str(exc_info.value)


def test_cannot_create_score_set_with_an_empty_method():
score_set = TEST_MINIMAL_SEQ_SCORESET.copy()
invalid_score_set = jsonable_encoder(score_set, exclude={"methodText"})
invalid_score_set["methodText"] = ""

with pytest.raises(ValueError) as exc_info:
ScoreSetCreate(**invalid_score_set)

assert "none is not an allowed value" in str(exc_info.value)
assert "methodText" in str(exc_info.value)
Loading