def test_verify_link_message(base_message):
    msg = base_message

    msg.type = MsgType.Link
    msg.attributes = EFBMsgLinkAttribute(title='Title', url='URL')
    msg.verify()

    with pytest.raises(ValueError) as exec_info:
        msg.attributes = EFBMsgLinkAttribute(title="Title")
    assert "URL" in exec_info.value.args[0]
Beispiel #2
0
 def qq_share_wrapper(self, data) -> EFBMsg:
     efb_msg = EFBMsg()
     efb_msg.type = MsgType.Link
     efb_msg.text = ''
     efb_msg.attributes = EFBMsgLinkAttribute(
         title='' if 'title' not in data else data['title'],
         description='' if 'content' not in data else data['content'],
         image='' if 'image' not in data else data['image'],
         url=data['url'])
     return efb_msg
Beispiel #3
0
 def send_link_msg(self):
     slave = next(iter(coordinator.slaves.values()))
     alice = slave.get_chat('alice')
     msg = EFBMsg()
     msg.deliver_to = slave
     msg.chat = alice
     msg.author = EFBChat(self).self()
     msg.type = MsgType.Link
     msg.text = "Check it out."
     msg.attributes = EFBMsgLinkAttribute(title="Example",
                                          url="https://example.com")
     return coordinator.send_message(msg)
Beispiel #4
0
def test_verify_link_message():
    msg = EFBMsg()
    msg.deliver_to = coordinator.master

    msg.author = patch_chat_0
    msg.chat = patch_chat_1
    msg.text = "Message"
    msg.verify()

    msg.type = MsgType.Link
    msg.attributes = EFBMsgLinkAttribute(title='Title', url='URL')
    msg.attributes.verify = mock.Mock()
    msg.verify()

    msg.attributes.verify.assert_called_once()
 def wechat_raw_link_msg(self, msg: wxpy.Message, title: str, description: str, image: str,
                         url: str, suffix: str = "") -> EFBMsg:
     efb_msg = EFBMsg()
     if url:
         efb_msg.type = MsgType.Link
         efb_msg.text = suffix
         efb_msg.attributes = EFBMsgLinkAttribute(
             title=title,
             description=description,
             image=image,
             url=url
         )
     else:
         efb_msg.type = MsgType.Text
         efb_msg.text = "%s\n%s" % (title, description)
         if suffix:
             efb_msg.text += "\n%s" % suffix
         if image:
             efb_msg.text += "\n\n%s" % image
     return efb_msg
Beispiel #6
0
def test_pickle_link_attribute():
    link = EFBMsgLinkAttribute(title="a", description="b", image="c", url="d")
    link_dup = pickle.loads(pickle.dumps(link))
    for attr in ("title", "description", "image", "url"):
        assert getattr(link, attr) == getattr(link_dup, attr)
Beispiel #7
0
    def test_chain_verify(self):
        patch_chat_0 = self.chat.copy()
        patch_chat_1 = self.chat.copy()
        patch_chat_0.verify = mock.Mock()
        patch_chat_1.verify = mock.Mock()

        msg = EFBMsg()
        msg.deliver_to = self.channel

        with self.subTest("Different author and chat"):
            msg.author = patch_chat_0
            msg.chat = patch_chat_1
            msg.text = "Message"
            msg.verify()

            patch_chat_0.verify.assert_called_once()
            patch_chat_1.verify.assert_called_once()

        patch_chat_0.verify.reset_mock()

        with self.subTest("Same author and chat"):
            msg.author = patch_chat_0
            msg.chat = patch_chat_0
            msg.text = "Message"
            msg.verify()

            patch_chat_0.verify.assert_called_once()

        with self.subTest("Link message"):
            msg.type = MsgType.Link
            msg.attributes = EFBMsgLinkAttribute(title='Title', url='URL')
            msg.attributes.verify = mock.Mock()
            msg.verify()

            msg.attributes.verify.assert_called_once()

        with self.subTest("Location message"):
            msg.type = MsgType.Location
            msg.attributes = EFBMsgLocationAttribute(latitude=0.0,
                                                     longitude=0.0)
            msg.attributes.verify = mock.Mock()
            msg.verify()

            msg.attributes.verify.assert_called_once()

        with self.subTest("Status message"):
            msg.type = MsgType.Status
            msg.attributes = EFBMsgStatusAttribute(
                status_type=EFBMsgStatusAttribute.Types.TYPING)
            msg.attributes.verify = mock.Mock()
            msg.verify()

            msg.attributes.verify.assert_called_once()

        with self.subTest("Message Command"):
            msg.type = MsgType.Text
            msg.attributes = None
            msg.commands = EFBMsgCommands(
                [EFBMsgCommand(name="Command 1", callable_name="command_1")])

            msg.commands.commands[0].verify = mock.Mock()

            msg.verify()

            msg.commands.commands[0].verify.assert_called_once()