mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-06 07:50:32 +00:00
feat: add UserFactory
This commit is contained in:
parent
6f53f15577
commit
e0baed8eee
14 changed files with 136 additions and 65 deletions
68
poetry.lock
generated
68
poetry.lock
generated
|
|
@ -308,6 +308,29 @@ optional = false
|
|||
python-versions = "*"
|
||||
version = "0.3.0"
|
||||
|
||||
[[package]]
|
||||
category = "dev"
|
||||
description = "A versatile test fixtures replacement based on thoughtbot's factory_bot for Ruby."
|
||||
name = "factory-boy"
|
||||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
|
||||
version = "2.12.0"
|
||||
|
||||
[package.dependencies]
|
||||
Faker = ">=0.7.0"
|
||||
|
||||
[[package]]
|
||||
category = "dev"
|
||||
description = "Faker is a Python package that generates fake data for you."
|
||||
name = "faker"
|
||||
optional = false
|
||||
python-versions = ">=3.4"
|
||||
version = "4.1.1"
|
||||
|
||||
[package.dependencies]
|
||||
python-dateutil = ">=2.4"
|
||||
text-unidecode = "1.3"
|
||||
|
||||
[[package]]
|
||||
category = "dev"
|
||||
description = "A platform independent file lock."
|
||||
|
|
@ -1155,6 +1178,17 @@ version = ">=0.700"
|
|||
python = ">=3.5"
|
||||
version = ">=2.8"
|
||||
|
||||
[[package]]
|
||||
category = "dev"
|
||||
description = "Extensions to the standard Python datetime module"
|
||||
name = "python-dateutil"
|
||||
optional = false
|
||||
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7"
|
||||
version = "2.8.1"
|
||||
|
||||
[package.dependencies]
|
||||
six = ">=1.5"
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "World timezone definitions, modern and historical"
|
||||
|
|
@ -1177,7 +1211,7 @@ category = "dev"
|
|||
description = "YAML parser and emitter for Python"
|
||||
name = "pyyaml"
|
||||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
||||
python-versions = "*"
|
||||
version = "5.3.1"
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1246,6 +1280,14 @@ optional = false
|
|||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
|
||||
version = "1.15.0"
|
||||
|
||||
[[package]]
|
||||
category = "dev"
|
||||
description = "The most basic Text::Unidecode port"
|
||||
name = "text-unidecode"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
version = "1.3"
|
||||
|
||||
[[package]]
|
||||
category = "dev"
|
||||
description = "Python Library for Tom's Obvious, Minimal Language"
|
||||
|
|
@ -1403,7 +1445,7 @@ fast = ["uvloop"]
|
|||
proxy = ["aiohttp-socks"]
|
||||
|
||||
[metadata]
|
||||
content-hash = "152bb9b155a00baadd3c8b9fa21f08af719180bddccb8ad6c3dd6548c3e71e3e"
|
||||
content-hash = "3c7ce8a032aadacee17d368f3277d652dacec5ce7ab208e93ee401fc6aa93f1b"
|
||||
python-versions = "^3.7"
|
||||
|
||||
[metadata.files]
|
||||
|
|
@ -1599,6 +1641,14 @@ decorator = [
|
|||
distlib = [
|
||||
{file = "distlib-0.3.0.zip", hash = "sha256:2e166e231a26b36d6dfe35a48c4464346620f8645ed0ace01ee31822b288de21"},
|
||||
]
|
||||
factory-boy = [
|
||||
{file = "factory_boy-2.12.0-py2.py3-none-any.whl", hash = "sha256:728df59b372c9588b83153facf26d3d28947fc750e8e3c95cefa9bed0e6394ee"},
|
||||
{file = "factory_boy-2.12.0.tar.gz", hash = "sha256:faf48d608a1735f0d0a3c9cbf536d64f9132b547dae7ba452c4d99a79e84a370"},
|
||||
]
|
||||
faker = [
|
||||
{file = "Faker-4.1.1-py3-none-any.whl", hash = "sha256:1290f589648bc470b8d98fff1fdff773fe3f46b4ca2cac73ac74668b12cf008e"},
|
||||
{file = "Faker-4.1.1.tar.gz", hash = "sha256:c006b3664c270a2cfd4785c5e41ff263d48101c4e920b5961cf9c237131d8418"},
|
||||
]
|
||||
filelock = [
|
||||
{file = "filelock-3.0.12-py3-none-any.whl", hash = "sha256:929b7d63ec5b7d6b71b0fa5ac14e030b3f70b75747cef1b10da9b879fef15836"},
|
||||
{file = "filelock-3.0.12.tar.gz", hash = "sha256:18d82244ee114f543149c66a6e0c14e9c4f8a1044b5cdaadd0f82159d6a6ff59"},
|
||||
|
|
@ -1743,6 +1793,11 @@ markupsafe = [
|
|||
{file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6"},
|
||||
{file = "MarkupSafe-1.1.1-cp37-cp37m-win32.whl", hash = "sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2"},
|
||||
{file = "MarkupSafe-1.1.1-cp37-cp37m-win_amd64.whl", hash = "sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c"},
|
||||
{file = "MarkupSafe-1.1.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6788b695d50a51edb699cb55e35487e430fa21f1ed838122d722e0ff0ac5ba15"},
|
||||
{file = "MarkupSafe-1.1.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:cdb132fc825c38e1aeec2c8aa9338310d29d337bebbd7baa06889d09a60a1fa2"},
|
||||
{file = "MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:13d3144e1e340870b25e7b10b98d779608c02016d5184cfb9927a9f10c689f42"},
|
||||
{file = "MarkupSafe-1.1.1-cp38-cp38-win32.whl", hash = "sha256:596510de112c685489095da617b5bcbbac7dd6384aeebeda4df6025d0256a81b"},
|
||||
{file = "MarkupSafe-1.1.1-cp38-cp38-win_amd64.whl", hash = "sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be"},
|
||||
{file = "MarkupSafe-1.1.1.tar.gz", hash = "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b"},
|
||||
]
|
||||
mccabe = [
|
||||
|
|
@ -1959,6 +2014,10 @@ pytest-mypy = [
|
|||
{file = "pytest-mypy-0.4.2.tar.gz", hash = "sha256:5a5338cecff17f005b181546a13e282761754b481225df37f33d37f86ac5b304"},
|
||||
{file = "pytest_mypy-0.4.2-py3-none-any.whl", hash = "sha256:3b7b56912d55439d5f447cc609f91caac7f74f0f1c89f1379d04f06bac777c32"},
|
||||
]
|
||||
python-dateutil = [
|
||||
{file = "python-dateutil-2.8.1.tar.gz", hash = "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c"},
|
||||
{file = "python_dateutil-2.8.1-py2.py3-none-any.whl", hash = "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a"},
|
||||
]
|
||||
pytz = [
|
||||
{file = "pytz-2020.1-py2.py3-none-any.whl", hash = "sha256:a494d53b6d39c3c6e44c3bec237336e14305e4f29bbf800b599253057fbb79ed"},
|
||||
{file = "pytz-2020.1.tar.gz", hash = "sha256:c35965d010ce31b23eeb663ed3cc8c906275d6be1a34393a1d73a41febf4a048"},
|
||||
|
|
@ -2004,6 +2063,7 @@ regex = [
|
|||
{file = "regex-2020.6.8.tar.gz", hash = "sha256:e9b64e609d37438f7d6e68c2546d2cb8062f3adb27e6336bc129b51be20773ac"},
|
||||
]
|
||||
requests = [
|
||||
{file = "requests-2.23.0-py2.7.egg", hash = "sha256:5d2d0ffbb515f39417009a46c14256291061ac01ba8f875b90cad137de83beb4"},
|
||||
{file = "requests-2.23.0-py2.py3-none-any.whl", hash = "sha256:43999036bfa82904b6af1d99e4882b560e5e2c68e5c4b0aa03b655f3d7d73fee"},
|
||||
{file = "requests-2.23.0.tar.gz", hash = "sha256:b3f43d496c6daba4493e7c431722aeb7dbc6288f52a6e04e7b6023b0247817e6"},
|
||||
]
|
||||
|
|
@ -2023,6 +2083,10 @@ six = [
|
|||
{file = "six-1.15.0-py2.py3-none-any.whl", hash = "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"},
|
||||
{file = "six-1.15.0.tar.gz", hash = "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259"},
|
||||
]
|
||||
text-unidecode = [
|
||||
{file = "text-unidecode-1.3.tar.gz", hash = "sha256:bad6603bb14d279193107714b288be206cac565dfa49aa5b105294dd5c4aab93"},
|
||||
{file = "text_unidecode-1.3-py2.py3-none-any.whl", hash = "sha256:1311f10e8b895935241623731c2ba64f4c455287888b18189350b67134a822e8"},
|
||||
]
|
||||
toml = [
|
||||
{file = "toml-0.10.1-py2.py3-none-any.whl", hash = "sha256:bda89d5935c2eac546d648028b9901107a595863cb36bae0c73ac804a9b4ce88"},
|
||||
{file = "toml-0.10.1.tar.gz", hash = "sha256:926b612be1e5ce0634a2ca03470f95169cf16f939018233a670519cb4ac58b0f"},
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ pre-commit = "^2.3.0"
|
|||
packaging = "^20.3"
|
||||
typing-extensions = "^3.7.4"
|
||||
poetry = "^1.0.5"
|
||||
factory_boy = "^2.12.0"
|
||||
|
||||
[tool.poetry.extras]
|
||||
fast = ["uvloop"]
|
||||
|
|
|
|||
0
tests/factories/chat_member.py
Normal file
0
tests/factories/chat_member.py
Normal file
0
tests/factories/inline_query.py
Normal file
0
tests/factories/inline_query.py
Normal file
0
tests/factories/message.py
Normal file
0
tests/factories/message.py
Normal file
13
tests/factories/user.py
Normal file
13
tests/factories/user.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import factory
|
||||
|
||||
from aiogram.api.types import User
|
||||
|
||||
|
||||
class UserFactory(factory.Factory):
|
||||
class Meta:
|
||||
model = User
|
||||
|
||||
id = factory.Sequence(lambda n: n)
|
||||
first_name = factory.Sequence(lambda n: f"First name #{n}")
|
||||
last_name = factory.Sequence(lambda n: f"Last name #{n}")
|
||||
is_bot = False
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.methods import GetChatMember, Request
|
||||
from aiogram.api.types import ChatMember, User
|
||||
from aiogram.api.types import ChatMember
|
||||
from tests.factories.user import UserFactory
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
@ -9,9 +10,7 @@ class TestGetChatMember:
|
|||
@pytest.mark.asyncio
|
||||
async def test_method(self, bot: MockedBot):
|
||||
prepare_result = bot.add_result_for(
|
||||
GetChatMember,
|
||||
ok=True,
|
||||
result=ChatMember(user=User(id=42, is_bot=False, first_name="User"), status="creator"),
|
||||
GetChatMember, ok=True, result=ChatMember(user=UserFactory(), status="creator"),
|
||||
)
|
||||
|
||||
response: ChatMember = await GetChatMember(chat_id=-42, user_id=42)
|
||||
|
|
@ -22,9 +21,7 @@ class TestGetChatMember:
|
|||
@pytest.mark.asyncio
|
||||
async def test_bot_method(self, bot: MockedBot):
|
||||
prepare_result = bot.add_result_for(
|
||||
GetChatMember,
|
||||
ok=True,
|
||||
result=ChatMember(user=User(id=42, is_bot=False, first_name="User"), status="creator"),
|
||||
GetChatMember, ok=True, result=ChatMember(user=UserFactory(), status="creator"),
|
||||
)
|
||||
|
||||
response: ChatMember = await bot.get_chat_member(chat_id=-42, user_id=42)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
from aiogram.api.methods import AnswerCallbackQuery
|
||||
from aiogram.api.types import CallbackQuery, User
|
||||
from tests.factories.user import UserFactory
|
||||
|
||||
|
||||
class TestCallbackQuery:
|
||||
def test_answer_alias(self):
|
||||
callback_query = CallbackQuery(
|
||||
id="id", from_user=User(id=42, is_bot=False, first_name="name"), chat_instance="chat"
|
||||
)
|
||||
callback_query = CallbackQuery(id="id", from_user=UserFactory(), chat_instance="chat")
|
||||
|
||||
kwargs = dict(text="foo", show_alert=True, url="https://foo.bar/", cache_time=123)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.types import ChatMember, User
|
||||
|
||||
user = User(id=42, is_bot=False, first_name="User", last_name=None)
|
||||
from aiogram.api.types import ChatMember
|
||||
from tests.factories.user import UserFactory
|
||||
|
||||
|
||||
class TestChatMember:
|
||||
|
|
@ -10,7 +9,7 @@ class TestChatMember:
|
|||
"status,result", [["administrator", True], ["creator", True], ["member", False]]
|
||||
)
|
||||
def test_is_chat_admin(self, status: str, result: bool):
|
||||
chat_member = ChatMember(user=user, status=status)
|
||||
chat_member = ChatMember(user=UserFactory(), status=status)
|
||||
assert chat_member.is_chat_admin == result
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -25,5 +24,5 @@ class TestChatMember:
|
|||
],
|
||||
)
|
||||
def test_is_chat_member(self, status: str, result: bool):
|
||||
chat_member = ChatMember(user=user, status=status)
|
||||
chat_member = ChatMember(user=UserFactory(), status=status)
|
||||
assert chat_member.is_chat_member == result
|
||||
|
|
|
|||
|
|
@ -1,15 +1,11 @@
|
|||
from aiogram.api.methods import AnswerInlineQuery
|
||||
from aiogram.api.types import InlineQuery, User
|
||||
from aiogram.api.types import InlineQuery
|
||||
from tests.factories.user import UserFactory
|
||||
|
||||
|
||||
class TestInlineQuery:
|
||||
def test_answer_alias(self):
|
||||
inline_query = InlineQuery(
|
||||
id="id",
|
||||
from_user=User(id=42, is_bot=False, first_name="name"),
|
||||
query="query",
|
||||
offset="",
|
||||
)
|
||||
inline_query = InlineQuery(id="id", from_user=UserFactory(), query="query", offset="",)
|
||||
|
||||
kwargs = dict(
|
||||
results=[],
|
||||
|
|
|
|||
|
|
@ -39,13 +39,13 @@ from aiogram.api.types import (
|
|||
PollOption,
|
||||
Sticker,
|
||||
SuccessfulPayment,
|
||||
User,
|
||||
Venue,
|
||||
Video,
|
||||
VideoNote,
|
||||
Voice,
|
||||
)
|
||||
from aiogram.api.types.message import ContentType, Message
|
||||
from tests.factories.user import UserFactory
|
||||
|
||||
|
||||
class TestMessage:
|
||||
|
|
@ -58,7 +58,7 @@ class TestMessage:
|
|||
date=datetime.datetime.now(),
|
||||
text="test",
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.TEXT,
|
||||
],
|
||||
|
|
@ -68,7 +68,7 @@ class TestMessage:
|
|||
date=datetime.datetime.now(),
|
||||
audio=Audio(file_id="file id", file_unique_id="file id", duration=42),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.AUDIO,
|
||||
],
|
||||
|
|
@ -84,7 +84,7 @@ class TestMessage:
|
|||
duration=0,
|
||||
),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.ANIMATION,
|
||||
],
|
||||
|
|
@ -94,7 +94,7 @@ class TestMessage:
|
|||
date=datetime.datetime.now(),
|
||||
document=Document(file_id="file id", file_unique_id="file id"),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.DOCUMENT,
|
||||
],
|
||||
|
|
@ -112,7 +112,7 @@ class TestMessage:
|
|||
],
|
||||
),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.GAME,
|
||||
],
|
||||
|
|
@ -124,7 +124,7 @@ class TestMessage:
|
|||
PhotoSize(file_id="file id", file_unique_id="file id", width=42, height=42)
|
||||
],
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.PHOTO,
|
||||
],
|
||||
|
|
@ -140,7 +140,7 @@ class TestMessage:
|
|||
is_animated=False,
|
||||
),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.STICKER,
|
||||
],
|
||||
|
|
@ -156,7 +156,7 @@ class TestMessage:
|
|||
duration=0,
|
||||
),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.VIDEO,
|
||||
],
|
||||
|
|
@ -168,7 +168,7 @@ class TestMessage:
|
|||
file_id="file id", file_unique_id="file id", length=0, duration=0
|
||||
),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.VIDEO_NOTE,
|
||||
],
|
||||
|
|
@ -178,7 +178,7 @@ class TestMessage:
|
|||
date=datetime.datetime.now(),
|
||||
voice=Voice(file_id="file id", file_unique_id="file id", duration=0),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.VOICE,
|
||||
],
|
||||
|
|
@ -188,7 +188,7 @@ class TestMessage:
|
|||
date=datetime.datetime.now(),
|
||||
contact=Contact(phone_number="911", first_name="911"),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.CONTACT,
|
||||
],
|
||||
|
|
@ -203,7 +203,7 @@ class TestMessage:
|
|||
"Little Whinging, Surrey, England, Great Britain",
|
||||
),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.VENUE,
|
||||
],
|
||||
|
|
@ -213,7 +213,7 @@ class TestMessage:
|
|||
date=datetime.datetime.now(),
|
||||
location=Location(longitude=3.14, latitude=3.14),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.LOCATION,
|
||||
],
|
||||
|
|
@ -221,9 +221,9 @@ class TestMessage:
|
|||
Message(
|
||||
message_id=42,
|
||||
date=datetime.datetime.now(),
|
||||
new_chat_members=[User(id=42, is_bot=False, first_name="Test")],
|
||||
new_chat_members=[UserFactory()],
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.NEW_CHAT_MEMBERS,
|
||||
],
|
||||
|
|
@ -231,9 +231,9 @@ class TestMessage:
|
|||
Message(
|
||||
message_id=42,
|
||||
date=datetime.datetime.now(),
|
||||
left_chat_member=User(id=42, is_bot=False, first_name="Test"),
|
||||
left_chat_member=UserFactory(),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.LEFT_CHAT_MEMBER,
|
||||
],
|
||||
|
|
@ -249,7 +249,7 @@ class TestMessage:
|
|||
total_amount=1,
|
||||
),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.INVOICE,
|
||||
],
|
||||
|
|
@ -265,7 +265,7 @@ class TestMessage:
|
|||
provider_payment_charge_id="payment",
|
||||
),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.SUCCESSFUL_PAYMENT,
|
||||
],
|
||||
|
|
@ -275,7 +275,7 @@ class TestMessage:
|
|||
date=datetime.datetime.now(),
|
||||
connected_website="token",
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.CONNECTED_WEBSITE,
|
||||
],
|
||||
|
|
@ -285,7 +285,7 @@ class TestMessage:
|
|||
date=datetime.datetime.now(),
|
||||
migrate_from_chat_id=42,
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.MIGRATE_FROM_CHAT_ID,
|
||||
],
|
||||
|
|
@ -295,7 +295,7 @@ class TestMessage:
|
|||
date=datetime.datetime.now(),
|
||||
migrate_to_chat_id=42,
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.MIGRATE_TO_CHAT_ID,
|
||||
],
|
||||
|
|
@ -308,10 +308,10 @@ class TestMessage:
|
|||
date=datetime.datetime.now(),
|
||||
text="pinned",
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.PINNED_MESSAGE,
|
||||
],
|
||||
|
|
@ -321,7 +321,7 @@ class TestMessage:
|
|||
date=datetime.datetime.now(),
|
||||
new_chat_title="test",
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.NEW_CHAT_TITLE,
|
||||
],
|
||||
|
|
@ -333,7 +333,7 @@ class TestMessage:
|
|||
PhotoSize(file_id="file id", file_unique_id="file id", width=42, height=42)
|
||||
],
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.NEW_CHAT_PHOTO,
|
||||
],
|
||||
|
|
@ -343,7 +343,7 @@ class TestMessage:
|
|||
date=datetime.datetime.now(),
|
||||
delete_chat_photo=True,
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.DELETE_CHAT_PHOTO,
|
||||
],
|
||||
|
|
@ -353,7 +353,7 @@ class TestMessage:
|
|||
date=datetime.datetime.now(),
|
||||
group_chat_created=True,
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.GROUP_CHAT_CREATED,
|
||||
],
|
||||
|
|
@ -366,7 +366,7 @@ class TestMessage:
|
|||
credentials=EncryptedCredentials(data="test", hash="test", secret="test"),
|
||||
),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.PASSPORT_DATA,
|
||||
],
|
||||
|
|
@ -389,7 +389,7 @@ class TestMessage:
|
|||
correct_option_id=1,
|
||||
),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.POLL,
|
||||
],
|
||||
|
|
@ -399,7 +399,7 @@ class TestMessage:
|
|||
date=datetime.datetime.now(),
|
||||
chat=Chat(id=42, type="private"),
|
||||
dice=Dice(value=6, emoji="X"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.DICE,
|
||||
],
|
||||
|
|
@ -408,7 +408,7 @@ class TestMessage:
|
|||
message_id=42,
|
||||
date=datetime.datetime.now(),
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
from_user=UserFactory(),
|
||||
),
|
||||
ContentType.UNKNOWN,
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
from aiogram.api.methods import AnswerPreCheckoutQuery
|
||||
from aiogram.api.types import PreCheckoutQuery, User
|
||||
from aiogram.api.types import PreCheckoutQuery
|
||||
from tests.factories.user import UserFactory
|
||||
|
||||
|
||||
class TestPreCheckoutQuery:
|
||||
def test_answer_alias(self):
|
||||
pre_checkout_query = PreCheckoutQuery(
|
||||
id="id",
|
||||
from_user=User(id=42, is_bot=False, first_name="name"),
|
||||
from_user=UserFactory(),
|
||||
currency="currency",
|
||||
total_amount=123,
|
||||
invoice_payload="payload",
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
from aiogram.api.methods import AnswerShippingQuery
|
||||
from aiogram.api.types import LabeledPrice, ShippingAddress, ShippingOption, ShippingQuery, User
|
||||
from aiogram.api.types import LabeledPrice, ShippingAddress, ShippingOption, ShippingQuery
|
||||
from tests.factories.user import UserFactory
|
||||
|
||||
|
||||
class TestInlineQuery:
|
||||
def test_answer_alias(self):
|
||||
shipping_query = ShippingQuery(
|
||||
id="id",
|
||||
from_user=User(id=42, is_bot=False, first_name="name"),
|
||||
from_user=UserFactory(),
|
||||
invoice_payload="payload",
|
||||
shipping_address=ShippingAddress(
|
||||
country_code="foo",
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.api.types import User
|
||||
from tests.factories.user import UserFactory
|
||||
|
||||
|
||||
class TestUser:
|
||||
@pytest.mark.parametrize(
|
||||
"first,last,result",
|
||||
"first_name,last_name,result",
|
||||
[
|
||||
["User", None, "User"],
|
||||
["", None, ""],
|
||||
|
|
@ -15,6 +15,6 @@ class TestUser:
|
|||
[" ", " ", " "],
|
||||
],
|
||||
)
|
||||
def test_full_name(self, first: str, last: str, result: bool):
|
||||
user = User(id=42, is_bot=False, first_name=first, last_name=last)
|
||||
def test_full_name(self, first_name: str, last_name: str, result: bool):
|
||||
user = UserFactory(first_name=first_name, last_name=last_name)
|
||||
assert user.full_name == result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue