|
4 | 4 | # pylint: disable=too-many-arguments |
5 | 5 | import uuid |
6 | 6 | from collections.abc import Awaitable, Callable |
7 | | -from datetime import datetime |
| 7 | +from datetime import datetime, timezone |
8 | 8 | from typing import Any, AsyncIterator |
9 | 9 |
|
10 | 10 | import pytest |
11 | 11 | import sqlalchemy |
| 12 | +import sqlalchemy as sa |
12 | 13 | from aiopg.sa.connection import SAConnection |
13 | 14 | from aiopg.sa.result import RowProxy |
14 | 15 | from faker import Faker |
| 16 | +from pydantic import parse_obj_as |
15 | 17 | from simcore_postgres_database.models.projects import projects |
16 | 18 | from simcore_postgres_database.utils_projects import ( |
17 | 19 | DBProjectNotFoundError, |
18 | 20 | ProjectsRepo, |
19 | 21 | ) |
| 22 | +from simcore_postgres_database.utils_repos import transaction_context |
20 | 23 | from sqlalchemy.ext.asyncio import AsyncEngine |
21 | 24 |
|
22 | 25 |
|
@@ -51,6 +54,26 @@ async def registered_project( |
51 | 54 | await _delete_project(connection, project["uuid"]) |
52 | 55 |
|
53 | 56 |
|
| 57 | +@pytest.mark.parametrize("expected", (datetime.now(tz=timezone.utc), None)) |
| 58 | +async def test_get_project_trashed_at_column_can_be_converted_to_datetime( |
| 59 | + asyncpg_engine: AsyncEngine, registered_project: dict, expected: datetime | None |
| 60 | +): |
| 61 | + project_id = registered_project["uuid"] |
| 62 | + |
| 63 | + async with transaction_context(asyncpg_engine) as conn: |
| 64 | + result = await conn.execute( |
| 65 | + projects.update() |
| 66 | + .values(trashed_at=expected) |
| 67 | + .where(projects.c.uuid == project_id) |
| 68 | + .returning(sa.literal_column("*")) |
| 69 | + ) |
| 70 | + |
| 71 | + row = result.fetchone() |
| 72 | + |
| 73 | + trashed_at = parse_obj_as(datetime | None, row.trashed_at) |
| 74 | + assert trashed_at == expected |
| 75 | + |
| 76 | + |
54 | 77 | async def test_get_project_last_change_date( |
55 | 78 | asyncpg_engine: AsyncEngine, registered_project: dict, faker: Faker |
56 | 79 | ): |
|
0 commit comments