mirror of
https://github.com/Balshgit/mosgortrans.git
synced 2026-02-03 11:20:56 +03:00
run in executor
This commit is contained in:
18
app/tests/factories.py
Normal file
18
app/tests/factories.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import factory
|
||||
from faker import Faker
|
||||
|
||||
from tests.models import User
|
||||
|
||||
faker = Faker('ru_RU')
|
||||
|
||||
|
||||
class UserFactory(factory.Factory):
|
||||
id = factory.Sequence(lambda n: 1000 + n)
|
||||
is_bot = False
|
||||
first_name = factory.Faker('first_name')
|
||||
last_name = factory.Faker('last_name')
|
||||
username = faker.profile(fields=['username'])['username']
|
||||
language_code = 'ru'
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
@@ -1,6 +1,20 @@
|
||||
""""
|
||||
Dict data set for Telegram message types
|
||||
"""
|
||||
from typing import NamedTuple, Any
|
||||
|
||||
|
||||
class User(NamedTuple):
|
||||
id: int
|
||||
is_bot: bool
|
||||
first_name: str | None
|
||||
last_name: str | None
|
||||
username: str | None
|
||||
language_code: str
|
||||
|
||||
def as_dict(self) -> dict[str, Any]:
|
||||
return self._asdict()
|
||||
|
||||
|
||||
USER = {
|
||||
"id": 12345678,
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from aiogram import Bot, types
|
||||
from app.tests.conftest import FakeTelegram
|
||||
from app.tests.dataset import USER
|
||||
from tests.factories import UserFactory
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.asyncio,
|
||||
@@ -9,9 +9,10 @@ pytestmark = [
|
||||
|
||||
|
||||
async def test_parse_site(bot: Bot) -> None:
|
||||
user = types.User(**USER)
|
||||
tg_user = UserFactory().as_dict()
|
||||
user = types.User(**tg_user)
|
||||
|
||||
async with FakeTelegram(message_data=USER):
|
||||
async with FakeTelegram(message_data=tg_user):
|
||||
result = await bot.me
|
||||
|
||||
assert result == user
|
||||
|
||||
Reference in New Issue
Block a user