+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser Public License for more details.
+#
+# You should have received a copy of the GNU Lesser Public License
+# along with this program. If not, see [http://www.gnu.org/licenses/].
+import datetime as dtm
+
+import pytest
+
+from telegram import BusinessConnection, User
+
+
+class BusinessMethodsTestBase:
+ bci = "42"
+
+
+class TestBusinessMethodsWithoutRequest(BusinessMethodsTestBase):
+ async def test_get_business_connection(self, offline_bot, monkeypatch):
+ user = User(1, "first", False)
+ user_chat_id = 1
+ date = dtm.datetime.utcnow()
+ can_reply = True
+ is_enabled = True
+ bc = BusinessConnection(
+ self.bci, user, user_chat_id, date, can_reply, is_enabled
+ ).to_json()
+
+ async def do_request(*args, **kwargs):
+ data = kwargs.get("request_data")
+ obj = data.parameters.get("business_connection_id")
+ if obj == self.bci:
+ return 200, f'{{"ok": true, "result": {bc}}}'.encode()
+ return 400, b'{"ok": false, "result": []}'
+
+ monkeypatch.setattr(offline_bot.request, "do_request", do_request)
+ obj = await offline_bot.get_business_connection(business_connection_id=self.bci)
+ assert isinstance(obj, BusinessConnection)
+
+ async def test_read_business_message(self, offline_bot, monkeypatch):
+ chat_id = 43
+ message_id = 44
+
+ async def make_assertion(*args, **kwargs):
+ data = kwargs.get("request_data").parameters
+ assert data.get("business_connection_id") == self.bci
+ assert data.get("chat_id") == chat_id
+ assert data.get("message_id") == message_id
+ return True
+
+ monkeypatch.setattr(offline_bot.request, "post", make_assertion)
+ assert await offline_bot.read_business_message(
+ business_connection_id=self.bci, chat_id=chat_id, message_id=message_id
+ )
+
+ async def test_delete_business_messages(self, offline_bot, monkeypatch):
+ message_ids = [1, 2, 3]
+
+ async def make_assertion(*args, **kwargs):
+ data = kwargs.get("request_data").parameters
+ assert data.get("business_connection_id") == self.bci
+ assert data.get("message_ids") == message_ids
+ return True
+
+ monkeypatch.setattr(offline_bot.request, "post", make_assertion)
+ assert await offline_bot.delete_business_messages(
+ business_connection_id=self.bci, message_ids=message_ids
+ )
+
+ @pytest.mark.parametrize("last_name", [None, "last_name"])
+ async def test_set_business_account_name(self, offline_bot, monkeypatch, last_name):
+ first_name = "Test Business Account"
+
+ async def make_assertion(*args, **kwargs):
+ data = kwargs.get("request_data").parameters
+ assert data.get("business_connection_id") == self.bci
+ assert data.get("first_name") == first_name
+ assert data.get("last_name") == last_name
+ return True
+
+ monkeypatch.setattr(offline_bot.request, "post", make_assertion)
+ assert await offline_bot.set_business_account_name(
+ business_connection_id=self.bci, first_name=first_name, last_name=last_name
+ )
+
+ @pytest.mark.parametrize("username", ["username", None])
+ async def test_set_business_account_username(self, offline_bot, monkeypatch, username):
+ async def make_assertion(*args, **kwargs):
+ data = kwargs.get("request_data").parameters
+ assert data.get("business_connection_id") == self.bci
+ assert data.get("username") == username
+ return True
+
+ monkeypatch.setattr(offline_bot.request, "post", make_assertion)
+ assert await offline_bot.set_business_account_username(
+ business_connection_id=self.bci, username=username
+ )
+
+ @pytest.mark.parametrize("bio", ["bio", None])
+ async def test_set_business_account_bio(self, offline_bot, monkeypatch, bio):
+ async def make_assertion(*args, **kwargs):
+ data = kwargs.get("request_data").parameters
+ assert data.get("business_connection_id") == self.bci
+ assert data.get("bio") == bio
+ return True
+
+ monkeypatch.setattr(offline_bot.request, "post", make_assertion)
+ assert await offline_bot.set_business_account_bio(business_connection_id=self.bci, bio=bio)
diff --git a/tests/test_chat.py b/tests/test_chat.py
index f53a0fdd2fe..c241b080392 100644
--- a/tests/test_chat.py
+++ b/tests/test_chat.py
@@ -1384,6 +1384,27 @@ async def make_assertion(*_, **kwargs):
monkeypatch.setattr(chat.get_bot(), "remove_chat_verification", make_assertion)
assert await chat.remove_verification()
+ async def test_instance_method_read_business_message(self, monkeypatch, chat):
+ async def make_assertion(*_, **kwargs):
+ return (
+ kwargs["chat_id"] == chat.id
+ and kwargs["business_connection_id"] == "business_connection_id"
+ and kwargs["message_id"] == "message_id"
+ )
+
+ assert check_shortcut_signature(
+ Chat.read_business_message, Bot.read_business_message, ["chat_id"], []
+ )
+ assert await check_shortcut_call(
+ chat.read_business_message, chat.get_bot(), "read_business_message"
+ )
+ assert await check_defaults_handling(chat.read_business_message, chat.get_bot())
+
+ monkeypatch.setattr(chat.get_bot(), "read_business_message", make_assertion)
+ assert await chat.read_business_message(
+ message_id="message_id", business_connection_id="business_connection_id"
+ )
+
def test_mention_html(self):
chat = Chat(id=1, type="foo")
with pytest.raises(TypeError, match="Can not create a mention to a private group chat"):
diff --git a/tests/test_message.py b/tests/test_message.py
index 7150a0502a1..c713cd38862 100644
--- a/tests/test_message.py
+++ b/tests/test_message.py
@@ -2820,6 +2820,31 @@ async def make_assertion(*_, **kwargs):
monkeypatch.setattr(message.get_bot(), "unpin_all_forum_topic_messages", make_assertion)
assert await message.unpin_all_forum_topic_messages()
+ async def test_read_business_message(self, monkeypatch, message):
+ async def make_assertion(*_, **kwargs):
+ return (
+ kwargs["chat_id"] == message.chat_id
+ and kwargs["business_connection_id"] == message.business_connection_id
+ and kwargs["message_id"] == message.message_id,
+ )
+
+ assert check_shortcut_signature(
+ Message.read_business_message,
+ Bot.read_business_message,
+ ["chat_id", "message_id", "business_connection_id"],
+ [],
+ )
+ assert await check_shortcut_call(
+ message.read_business_message,
+ message.get_bot(),
+ "read_business_message",
+ shortcut_kwargs=["chat_id", "message_id", "business_connection_id"],
+ )
+ assert await check_defaults_handling(message.read_business_message, message.get_bot())
+
+ monkeypatch.setattr(message.get_bot(), "read_business_message", make_assertion)
+ assert await message.read_business_message()
+
def test_attachement_successful_payment_deprecated(self, message, recwarn):
message.successful_payment = "something"
# kinda unnecessary to assert but one needs to call the function ofc so. Here we are.
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy