コード例 #1
0
ファイル: test_messages.py プロジェクト: ExpressApp/pybotx
def sending_message() -> SendingMessage:
    return SendingMessage(
        text="text",
        file=File.from_string(b"data", filename="file.txt"),
        credentials=SendingCredentials(
            sync_id=uuid.uuid4(),
            bot_id=uuid.uuid4(),
            host="host",
        ),
        markup=MessageMarkup(
            bubbles=[[BubbleElement(command="")]],
            keyboard=[[KeyboardElement(command="")]],
        ),
        options=MessageOptions(
            recipients=[uuid.uuid4()],
            mentions=[
                Mention(mention_data=UserMention(user_huid=uuid.uuid4())),
                Mention(
                    mention_data=UserMention(user_huid=uuid.uuid4()),
                    mention_type=MentionTypes.contact,
                ),
                Mention(
                    mention_data=ChatMention(group_chat_id=uuid.uuid4()),
                    mention_type=MentionTypes.chat,
                ),
            ],
            notifications=NotificationOptions(send=False, force_dnd=True),
        ),
    )
コード例 #2
0
ファイル: sending_data3.py プロジェクト: ExpressApp/pybotx
async def my_handler(message: Message) -> None:
    with open("my_file.txt") as f:
        notification = SendingMessage(
            file=File.from_file(f), credentials=message.credentials,
        )

    await bot.send(notification)
コード例 #3
0
ファイル: test_messages.py プロジェクト: ExpressApp/pybotx
 def test_options_from_recipients(
         self, sending_message: SendingMessage) -> None:
     msg = SendingMessage(
         text=sending_message.text,
         credentials=sending_message.credentials,
         recipients=sending_message.options.recipients,
     )
     assert msg.options.recipients == sending_message.options.recipients
コード例 #4
0
async def some_function() -> None:
    message = SendingMessage(
        text="You were chosen by random.",
        bot_id=BOT_ID,
        host=CTS_HOST,
        chat_id=CHAT_ID,
    )
    await bot.send(message)
コード例 #5
0
ファイル: test_messages.py プロジェクト: ExpressApp/pybotx
 def test_option_from_message_options(
     self,
     sending_message: SendingMessage,
 ) -> None:
     msg = SendingMessage(
         text=sending_message.text,
         credentials=sending_message.credentials,
         options=sending_message.options,
     )
     assert msg.options == sending_message.options
コード例 #6
0
ファイル: test_messages.py プロジェクト: ExpressApp/pybotx
 def test_markup_creation_from_bubbles_and_keyboard(
     self,
     sending_message: SendingMessage,
 ) -> None:
     msg = SendingMessage(
         text=sending_message.text,
         credentials=sending_message.credentials,
         bubbles=sending_message.markup.bubbles,
         keyboard=sending_message.markup.keyboard,
     )
     assert msg.markup == sending_message.markup
コード例 #7
0
ファイル: test_messages.py プロジェクト: ExpressApp/pybotx
 def test_merging_message_id_into_credentials(
     self,
     sending_message: SendingMessage,
 ) -> None:
     message_id = uuid.uuid4()
     msg = SendingMessage(
         text=sending_message.text,
         credentials=sending_message.credentials,
         message_id=message_id,
     )
     assert msg.credentials.message_id == message_id
コード例 #8
0
ファイル: test_messages.py プロジェクト: ExpressApp/pybotx
 def test_credentials_will_be_built_from_credential_parts(
     self,
     sending_message: SendingMessage,
 ) -> None:
     msg = SendingMessage(
         text=sending_message.text,
         sync_id=sending_message.sync_id,
         bot_id=sending_message.bot_id,
         host=sending_message.host,
     )
     assert msg.credentials == sending_message.credentials
コード例 #9
0
ファイル: test_messages.py プロジェクト: ExpressApp/pybotx
 def test_only_credentials_or_separate_credential_parts(
     self,
     sending_message: SendingMessage,
 ) -> None:
     with pytest.raises(AssertionError):
         _ = SendingMessage(
             sync_id=sending_message.sync_id,
             bot_id=sending_message.bot_id,
             host=sending_message.host,
             credentials=sending_message.credentials,
         )
コード例 #10
0
ファイル: test_messages.py プロジェクト: ExpressApp/pybotx
 def test_only_markup_or_separate_markup_parts(
     self,
     sending_message: SendingMessage,
 ) -> None:
     with pytest.raises(AssertionError):
         _ = SendingMessage(
             text=sending_message.text,
             credentials=sending_message.credentials,
             bubbles=sending_message.markup.bubbles,
             keyboard=sending_message.markup.keyboard,
             markup=sending_message.markup,
         )
コード例 #11
0
ファイル: test_messages.py プロジェクト: ExpressApp/pybotx
 def test_leaving_credentials_message_id_into_credentials_if_was_set(
     self,
     sending_message: SendingMessage,
 ) -> None:
     message_id = uuid.uuid4()
     sending_message.credentials.message_id = message_id
     msg = SendingMessage(
         text=sending_message.text,
         credentials=sending_message.credentials,
         message_id=uuid.uuid4(),
     )
     assert msg.credentials.message_id == sending_message.credentials.message_id
コード例 #12
0
ファイル: test_messages.py プロジェクト: ExpressApp/pybotx
 def test_only_options_or_separate_options_parts(
     self,
     sending_message: SendingMessage,
 ) -> None:
     with pytest.raises(AssertionError):
         _ = SendingMessage(
             text=sending_message.text,
             credentials=sending_message.credentials,
             options=sending_message.options,
             mentions=sending_message.options.mentions,
             recipients=sending_message.options.recipients,
             notification_options=sending_message.options.notifications,
         )
コード例 #13
0
ファイル: test_messages.py プロジェクト: ExpressApp/pybotx
def test_credentials_or_parameters_required_for_message_creation():
    with pytest.raises(AssertionError):
        SendingMessage()