tests user_with_load
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
import pytest
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
from sqlalchemy import NullPool, insert
|
||||
|
||||
38
tests/mock_tasks.json
Normal file
38
tests/mock_tasks.json
Normal file
@@ -0,0 +1,38 @@
|
||||
[
|
||||
{
|
||||
"title": "test1",
|
||||
"description": "test1",
|
||||
"due_date": "2026-06-01",
|
||||
"status": "open",
|
||||
"priority": "medium"
|
||||
},
|
||||
{
|
||||
"title": "test2",
|
||||
"description": "test2",
|
||||
"due_date": "2026-06-01",
|
||||
"status": "open",
|
||||
"priority": "high"
|
||||
|
||||
},
|
||||
{
|
||||
"title": "test3",
|
||||
"description": "test3",
|
||||
"due_date": "2026-06-02",
|
||||
"status": "todo",
|
||||
"priority": "medium"
|
||||
},
|
||||
{
|
||||
"title": "test4",
|
||||
"description": "test4",
|
||||
"due_date": "2026-06-02",
|
||||
"status": "open",
|
||||
"priority": "high"
|
||||
},
|
||||
{
|
||||
"title": "test5",
|
||||
"description": "test5",
|
||||
"due_date": "2026-06-02",
|
||||
"status": "todo",
|
||||
"priority": "low"
|
||||
}
|
||||
]
|
||||
@@ -1,5 +1,8 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from src.models.users import UsersORM
|
||||
from src.schemas.users import User
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -29,3 +32,24 @@ async def test_user_crud(db: "TestDBManager"):
|
||||
await db.user.delete_one(id=updated_user.id)
|
||||
delete_user = await db.user.get_one_or_none(id=new_user.id)
|
||||
assert not delete_user
|
||||
|
||||
|
||||
async def test_tasks_user(db: "TestDBManager"):
|
||||
with open("tests/mock_tasks.json") as jsonfile:
|
||||
data = json.load(jsonfile)
|
||||
admin_user: UsersORM | None = await db.user.get_one_or_none(id=1)
|
||||
assert admin_user
|
||||
data = [
|
||||
{
|
||||
**item,
|
||||
"user_id": admin_user.id,
|
||||
"due_date": datetime.strptime(item["due_date"], "%Y-%m-%d"),
|
||||
}
|
||||
for item in data
|
||||
]
|
||||
result = await db.task.create_bulk(data)
|
||||
await db.commit()
|
||||
assert result
|
||||
user_with_tasks = await db.user.get_one_with_load(user_id=admin_user.id)
|
||||
assert user_with_tasks
|
||||
assert user_with_tasks.tasks
|
||||
|
||||
Reference in New Issue
Block a user