From bb2ab6ff63384ac634aafb15883d916a22da2b97 Mon Sep 17 00:00:00 2001 From: Egor Date: Fri, 3 Jul 2020 16:32:26 +0500 Subject: [PATCH] fix: use ChatMemberFactory instead of the direct class --- pyproject.toml | 2 +- tests/factories/chat.py | 4 ++-- tests/factories/message.py | 2 +- tests/factories/user.py | 2 +- tests/test_api/test_methods/test_get_chat_administrators.py | 4 ++-- tests/test_api/test_methods/test_get_chat_member.py | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b562d82e..d934e9e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,7 +96,7 @@ include_trailing_comma = true force_grid_wrap = 0 use_parentheses = true line_length = 99 -known_third_party = ["aiofiles", "aiohttp", "aiohttp_socks", "aresponses", "async_lru", "packaging", "pkg_resources", "pydantic", "pytest"] +known_third_party = ["aiofiles", "aiohttp", "aiohttp_socks", "aresponses", "async_lru", "factory", "packaging", "poetry", "pydantic", "pytest", "typing_extensions"] [build-system] requires = ["poetry>=0.12"] diff --git a/tests/factories/chat.py b/tests/factories/chat.py index 513c4dda..77b0f607 100644 --- a/tests/factories/chat.py +++ b/tests/factories/chat.py @@ -26,10 +26,10 @@ class ChatFactory(factory.Factory): def title(self, n): if self.type is ChatType.CHANNEL: return f"Title #{n}" - + def __new__(cls, *args, **kwargs) -> "ChatFactory.Meta.model": """ This is a dirty hack for correct type hints See https://github.com/FactoryBoy/factory_boy/issues/468#issuecomment-505646794 """ - return super().__new__(*args, **kwargs) \ No newline at end of file + return super().__new__(*args, **kwargs) diff --git a/tests/factories/message.py b/tests/factories/message.py index 8860c824..1b8dc399 100644 --- a/tests/factories/message.py +++ b/tests/factories/message.py @@ -18,7 +18,7 @@ class MessageFactory(factory.Factory): text = factory.Sequence(lambda n: f"Message text #{n}") date = factory.LazyFunction(lambda _: datetime.now().toordinal()) - + def __new__(cls, *args, **kwargs) -> "MessageFactory.Meta.model": """ This is a dirty hack for correct type hints diff --git a/tests/factories/user.py b/tests/factories/user.py index ed074c19..b52efe77 100644 --- a/tests/factories/user.py +++ b/tests/factories/user.py @@ -17,4 +17,4 @@ class UserFactory(factory.Factory): This is a dirty hack for correct type hints See https://github.com/FactoryBoy/factory_boy/issues/468#issuecomment-505646794 """ - return super().__new__(*args, **kwargs) \ No newline at end of file + return super().__new__(*args, **kwargs) diff --git a/tests/test_api/test_methods/test_get_chat_administrators.py b/tests/test_api/test_methods/test_get_chat_administrators.py index 04605a7f..7fc58f23 100644 --- a/tests/test_api/test_methods/test_get_chat_administrators.py +++ b/tests/test_api/test_methods/test_get_chat_administrators.py @@ -12,7 +12,7 @@ class TestGetChatAdministrators: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): prepare_result = bot.add_result_for( - GetChatAdministrators, ok=True, result=[ChatMemberFactory(status="creator")], + GetChatAdministrators, ok=True, result=[ChatMemberFactory(status="creator")] ) response: List[ChatMember] = await GetChatAdministrators(chat_id=-42) @@ -23,7 +23,7 @@ class TestGetChatAdministrators: @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( - GetChatAdministrators, ok=True, result=[ChatMemberFactory(status="creator")], + GetChatAdministrators, ok=True, result=[ChatMemberFactory(status="creator")] ) response: List[ChatMember] = await bot.get_chat_administrators(chat_id=-42) request: Request = bot.get_request() diff --git a/tests/test_api/test_methods/test_get_chat_member.py b/tests/test_api/test_methods/test_get_chat_member.py index f6655a69..d3135dce 100644 --- a/tests/test_api/test_methods/test_get_chat_member.py +++ b/tests/test_api/test_methods/test_get_chat_member.py @@ -11,7 +11,7 @@ class TestGetChatMember: @pytest.mark.asyncio async def test_method(self, bot: MockedBot): prepare_result = bot.add_result_for( - GetChatMember, ok=True, result=ChatMemberFactory(status="creator"), + GetChatMember, ok=True, result=ChatMemberFactory(status="creator") ) response: ChatMember = await GetChatMember(chat_id=-42, user_id=42) @@ -22,7 +22,7 @@ class TestGetChatMember: @pytest.mark.asyncio async def test_bot_method(self, bot: MockedBot): prepare_result = bot.add_result_for( - GetChatMember, ok=True, result=ChatMemberFactory(status="creator"), + GetChatMember, ok=True, result=ChatMemberFactory(status="creator") ) response: ChatMember = await bot.get_chat_member(chat_id=-42, user_id=42)