-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add unit tests for task management functions and implement task…
… model tests
- Loading branch information
1 parent
dfe1fda
commit ae9746e
Showing
3 changed files
with
173 additions
and
16 deletions.
There are no files selected for viewing
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
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,37 @@ | ||
import pytest | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
from src.tasks.models import Base, Task | ||
|
||
DATABASE_URL = "sqlite:///:memory:" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def engine(): | ||
return create_engine(DATABASE_URL) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def tables(engine): | ||
Base.metadata.create_all(engine) | ||
yield | ||
Base.metadata.drop_all(engine) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def session(engine, tables): | ||
Session = sessionmaker(bind=engine) | ||
session = Session() | ||
yield session | ||
session.close() | ||
|
||
|
||
def test_task_model(session): | ||
new_task = Task(task="Test Task") | ||
session.add(new_task) | ||
session.commit() | ||
|
||
retrieved_task = session.query(Task).filter_by(task="Test Task").first() | ||
assert retrieved_task is not None | ||
assert retrieved_task.task == "Test Task" |
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,36 @@ | ||
import pytest | ||
from pydantic import ValidationError | ||
|
||
from src.tasks.schemas import OkResponse, Task, TaskCreate | ||
|
||
|
||
def test_ok_response(): | ||
response = OkResponse(id=1, task="Test Task") | ||
assert response.id == 1 | ||
assert response.task == "Test Task" | ||
|
||
|
||
def test_ok_response_invalid(): | ||
with pytest.raises(ValidationError): | ||
OkResponse(id="one", task="Test Task") | ||
|
||
|
||
def test_task_create(): | ||
task_create = TaskCreate(task="New Task") | ||
assert task_create.task == "New Task" | ||
|
||
|
||
def test_task_create_invalid(): | ||
with pytest.raises(ValidationError): | ||
TaskCreate(task=123) | ||
|
||
|
||
def test_task(): | ||
task = Task(id=1, task="Existing Task") | ||
assert task.id == 1 | ||
assert task.task == "Existing Task" | ||
|
||
|
||
def test_task_invalid(): | ||
with pytest.raises(ValidationError): | ||
Task(id="one", task="Existing Task") |