-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add unit tests for the experiment repo (#570)
Closes #570 Signed-off-by: Dimitris Poulopoulos <dimitris@mozilla.ai>
- Loading branch information
1 parent
fbe3fab
commit bcb3538
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
lumigator/python/mzai/backend/backend/tests/unit/repositories/test_experiments.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import uuid | ||
|
||
import pytest | ||
from lumigator_schemas.jobs import JobStatus | ||
from sqlalchemy.exc import IntegrityError | ||
|
||
from backend.repositories.experiments import ExperimentRepository | ||
from backend.repositories.jobs import JobRepository | ||
|
||
|
||
@pytest.fixture | ||
def experiment_repository(db_session): | ||
return ExperimentRepository(db_session) | ||
|
||
|
||
@pytest.fixture | ||
def job_repository(db_session): | ||
return JobRepository(db_session) | ||
|
||
|
||
def test_create_and_get_experiment(experiment_repository): | ||
created_experiment = experiment_repository.create(name="test", description="") | ||
retrieved_experiment = experiment_repository.get(created_experiment.id) | ||
assert created_experiment.id == retrieved_experiment.id | ||
assert created_experiment.name == retrieved_experiment.name | ||
assert created_experiment.status == JobStatus.CREATED | ||
|
||
|
||
def test_experiment_foreign_key(job_repository): | ||
random_id = uuid.uuid4() | ||
with pytest.raises(IntegrityError): | ||
job_repository.create(name="test", description="", experiment_id=random_id) | ||
|
||
|
||
def test_duplicate_results_error(experiment_repository, job_repository): | ||
experiment = experiment_repository.create(name="test", description="") | ||
job_repository.create(name="test", description="", experiment_id=experiment.id) | ||
with pytest.raises(IntegrityError): | ||
job_repository.create(name="test", description="", experiment_id=experiment.id) |