fix: use ChatMemberFactory instead of the direct class

This commit is contained in:
Egor 2020-07-03 16:32:26 +05:00
parent 36c70577bf
commit bb2ab6ff63
6 changed files with 9 additions and 9 deletions

View file

@ -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)
return super().__new__(*args, **kwargs)

View file

@ -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

View file

@ -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)
return super().__new__(*args, **kwargs)

View file

@ -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()

View file

@ -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)