def test_equality(self): a = ChatInviteLink("link", User(1, "", False), True, True, True) b = ChatInviteLink("link", User(1, "", False), True, True, True) c = ChatInviteLink("link", User(2, "", False), True, True, True) d1 = ChatInviteLink("link", User(1, "", False), False, True, True) d2 = ChatInviteLink("link", User(1, "", False), True, False, True) d3 = ChatInviteLink("link", User(1, "", False), True, True, False) e = ChatInviteLink("notalink", User(1, "", False), True, False, True) f = ChatInviteLink("notalink", User(1, "", False), True, True, True) g = User(1, "", False) assert a == b assert hash(a) == hash(b) assert a is not b assert a != c assert hash(a) != hash(c) assert a != d1 assert hash(a) != hash(d1) assert a != d2 assert hash(a) != hash(d2) assert d2 != d3 assert hash(d2) != hash(d3) assert a != e assert hash(a) != hash(e) assert a != f assert hash(a) != hash(f) assert a != g assert hash(a) != hash(g)
def invite_link(creator): return ChatInviteLink( TestChatInviteLink.link, creator, TestChatInviteLink.primary, TestChatInviteLink.revoked, expire_date=TestChatInviteLink.expire_date, member_limit=TestChatInviteLink.member_limit, )
def invite_link(creator): return ChatInviteLink( TestChatInviteLink.link, creator, TestChatInviteLink.primary, TestChatInviteLink.revoked, expire_date=TestChatInviteLink.expire_date, member_limit=TestChatInviteLink.member_limit, name=TestChatInviteLink.name, pending_join_request_count=TestChatInviteLink.pending_join_request_count, )
def test_equality(self): a = ChatInviteLink("link", User(1, '', False), True, True) b = ChatInviteLink("link", User(1, '', False), True, True) d = ChatInviteLink("link", User(2, '', False), False, True) d2 = ChatInviteLink("notalink", User(1, '', False), False, True) d3 = ChatInviteLink("notalink", User(1, '', False), True, True) e = User(1, '', False) assert a == b assert hash(a) == hash(b) assert a is not b assert a != d assert hash(a) != hash(d) assert a != d2 assert hash(a) != hash(d2) assert d2 != d3 assert hash(d2) != hash(d3) assert a != e assert hash(a) != hash(e)
def chat_join_request(time, bot): return ChatJoinRequest( chat=Chat(1, Chat.SUPERGROUP), from_user=User(2, 'first_name', False), date=time, bio='bio', invite_link=ChatInviteLink( 'https://invite.link', User(42, 'creator', False), name='InviteLink', is_revoked=False, is_primary=False, ), bot=bot, )
def chat_join_request(time, bot): return ChatJoinRequest( chat=Chat(1, Chat.SUPERGROUP), from_user=User(2, "first_name", False), date=time, bio="bio", invite_link=ChatInviteLink( "https://invite.link", User(42, "creator", False), creates_join_request=False, name="InviteLink", is_revoked=False, is_primary=False, ), bot=bot, )
def invite_link(user): return ChatInviteLink('link', user, True, True)
class TestChatJoinRequest: chat = Chat(1, Chat.SUPERGROUP) from_user = User(2, 'first_name', False) bio = 'bio' invite_link = ChatInviteLink( 'https://invite.link', User(42, 'creator', False), name='InviteLink', is_revoked=False, is_primary=False, ) def test_slot_behaviour(self, chat_join_request, recwarn, mro_slots): inst = chat_join_request for attr in inst.__slots__: assert getattr(inst, attr, 'err') != 'err', f"got extra slot '{attr}'" assert not inst.__dict__, f"got missing slot(s): {inst.__dict__}" assert len(mro_slots(inst)) == len(set( mro_slots(inst))), "duplicate slot" inst.custom, inst.bio = 'should give warning', self.bio assert len(recwarn) == 1 and 'custom' in str( recwarn[0].message), recwarn.list def test_de_json(self, bot, time): json_dict = { 'chat': self.chat.to_dict(), 'from': self.from_user.to_dict(), 'date': to_timestamp(time), } chat_join_request = ChatJoinRequest.de_json(json_dict, bot) assert chat_join_request.chat == self.chat assert chat_join_request.from_user == self.from_user assert pytest.approx(chat_join_request.date == time) assert to_timestamp(chat_join_request.date) == to_timestamp(time) json_dict.update({ 'bio': self.bio, 'invite_link': self.invite_link.to_dict() }) chat_join_request = ChatJoinRequest.de_json(json_dict, bot) assert chat_join_request.chat == self.chat assert chat_join_request.from_user == self.from_user assert pytest.approx(chat_join_request.date == time) assert to_timestamp(chat_join_request.date) == to_timestamp(time) assert chat_join_request.bio == self.bio assert chat_join_request.invite_link == self.invite_link def test_to_dict(self, chat_join_request, time): chat_join_request_dict = chat_join_request.to_dict() assert isinstance(chat_join_request_dict, dict) assert chat_join_request_dict[ 'chat'] == chat_join_request.chat.to_dict() assert chat_join_request_dict[ 'from'] == chat_join_request.from_user.to_dict() assert chat_join_request_dict['date'] == to_timestamp( chat_join_request.date) assert chat_join_request_dict['bio'] == chat_join_request.bio assert chat_join_request_dict[ 'invite_link'] == chat_join_request.invite_link.to_dict() def test_equality(self, chat_join_request, time): a = chat_join_request b = ChatJoinRequest(self.chat, self.from_user, time) c = ChatJoinRequest(self.chat, self.from_user, time, bio='bio') d = ChatJoinRequest(self.chat, self.from_user, time + datetime.timedelta(1)) e = ChatJoinRequest(self.chat, User(-1, 'last_name', True), time) f = User(456, '', False) assert a == b assert hash(a) == hash(b) assert a is not b assert a == c assert hash(a) == hash(c) assert a != d assert hash(a) != hash(d) assert a != e assert hash(a) != hash(e) assert a != f assert hash(a) != hash(f) def test_approve(self, monkeypatch, chat_join_request): def make_assertion(*_, **kwargs): chat_id_test = kwargs['chat_id'] == chat_join_request.chat.id user_id_test = kwargs['user_id'] == chat_join_request.from_user.id return chat_id_test and user_id_test assert check_shortcut_signature(ChatJoinRequest.approve, Bot.approve_chat_join_request, ['chat_id', 'user_id'], []) assert check_shortcut_call(chat_join_request.approve, chat_join_request.bot, 'approve_chat_join_request') assert check_defaults_handling(chat_join_request.approve, chat_join_request.bot) monkeypatch.setattr(chat_join_request.bot, 'approve_chat_join_request', make_assertion) assert chat_join_request.approve() def test_decline(self, monkeypatch, chat_join_request): def make_assertion(*_, **kwargs): chat_id_test = kwargs['chat_id'] == chat_join_request.chat.id user_id_test = kwargs['user_id'] == chat_join_request.from_user.id return chat_id_test and user_id_test assert check_shortcut_signature(ChatJoinRequest.decline, Bot.decline_chat_join_request, ['chat_id', 'user_id'], []) assert check_shortcut_call(chat_join_request.decline, chat_join_request.bot, 'decline_chat_join_request') assert check_defaults_handling(chat_join_request.decline, chat_join_request.bot) monkeypatch.setattr(chat_join_request.bot, 'decline_chat_join_request', make_assertion) assert chat_join_request.decline()
def invite_link(user): return ChatInviteLink("link", user, False, True, True)