Добавлена отправка накладных на почту

This commit is contained in:
Раис Юсупалиев
2026-05-24 00:55:09 +03:00
parent 5526f90cb3
commit 50124fb2c9
36 changed files with 1615 additions and 22 deletions
+127
View File
@@ -442,6 +442,133 @@ def test_record_waybill_poll_sets_url_only_when_previously_null() -> None:
asyncio.run(_with_repository(run))
def test_list_orders_pending_waybill_email_returns_orders_with_url_and_no_sent_at() -> None:
async def run(
repository: OrderRepository,
_session_factory: async_sessionmaker[AsyncSession],
) -> None:
await _seed_order(
repository,
order_uuid="ready",
cdek_order_uuid="o1",
cdek_waybill_uuid="w1",
cdek_waybill_url="https://cdek.test/1.pdf",
)
await _seed_order(
repository,
order_uuid="no-url",
cdek_order_uuid="o2",
cdek_waybill_uuid="w2",
)
await _seed_order(
repository,
order_uuid="already-sent",
cdek_order_uuid="o3",
cdek_waybill_uuid="w3",
cdek_waybill_url="https://cdek.test/3.pdf",
)
async with repository.session() as session:
sent = await repository.get_order_by_order_uuid(session, "already-sent")
assert sent is not None
sent.waybill_email_sent_at = datetime(
2026, 5, 24, 12, 0, tzinfo=timezone.utc
)
async with repository.session() as session:
orders = await repository.list_orders_pending_waybill_email(
session, limit=10
)
assert [order.order_uuid for order in orders] == ["ready"]
asyncio.run(_with_repository(run))
def test_list_orders_pending_waybill_email_orders_by_created_at_asc() -> None:
async def run(
repository: OrderRepository,
_session_factory: async_sessionmaker[AsyncSession],
) -> None:
await _seed_order(
repository,
order_uuid="first",
cdek_order_uuid="o1",
cdek_waybill_uuid="w1",
cdek_waybill_url="https://cdek.test/1.pdf",
)
await _seed_order(
repository,
order_uuid="second",
cdek_order_uuid="o2",
cdek_waybill_uuid="w2",
cdek_waybill_url="https://cdek.test/2.pdf",
)
async with repository.session() as session:
orders = await repository.list_orders_pending_waybill_email(
session, limit=10
)
assert [order.order_uuid for order in orders] == ["first", "second"]
asyncio.run(_with_repository(run))
def test_record_waybill_email_sent_sets_timestamp_once() -> None:
first_sent = datetime(2026, 5, 24, 12, 0, tzinfo=timezone.utc)
second_sent = datetime(2026, 5, 24, 13, 0, tzinfo=timezone.utc)
async def run(
repository: OrderRepository,
_session_factory: async_sessionmaker[AsyncSession],
) -> None:
await _seed_order(
repository,
order_uuid="o",
cdek_order_uuid="cdek-o",
cdek_waybill_uuid="w",
cdek_waybill_url="https://cdek.test/1.pdf",
)
async with repository.session() as session:
order = await repository.record_waybill_email_sent(
session, order_uuid="o", sent_at=first_sent
)
assert order is not None
assert order.waybill_email_sent_at == first_sent
async with repository.session() as session:
order = await repository.record_waybill_email_sent(
session, order_uuid="o", sent_at=second_sent
)
assert order is not None
assert order.waybill_email_sent_at is not None
assert order.waybill_email_sent_at.replace(
tzinfo=None
) == first_sent.replace(tzinfo=None)
asyncio.run(_with_repository(run))
def test_record_waybill_email_sent_returns_none_for_missing_order() -> None:
async def run(
repository: OrderRepository,
_session_factory: async_sessionmaker[AsyncSession],
) -> None:
async with repository.session() as session:
order = await repository.record_waybill_email_sent(
session,
order_uuid="missing",
sent_at=datetime(2026, 5, 24, 12, 0, tzinfo=timezone.utc),
)
assert order is None
asyncio.run(_with_repository(run))
def test_record_waybill_poll_updates_polled_at_when_url_is_none() -> None:
polled = datetime(2026, 5, 24, 13, 0, tzinfo=timezone.utc)