Skip to content

Commit

Permalink
tests: Add unit tests for the experiment repo (#570)
Browse files Browse the repository at this point in the history
Refs #570

Signed-off-by: Dimitris Poulopoulos <dimitris@mozilla.ai>
  • Loading branch information
dpoulopoulos committed Jan 10, 2025
1 parent aff629f commit 4b65a85
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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)

0 comments on commit 4b65a85

Please sign in to comment.