Ejemplo n.º 1
0
 def reply(self, message, **kwargs):
     if self.type == 'text':
         return TextReply(
             message=message,
             content=self.content if self.content else '欢迎关注花胶!')
     elif self.type == 'music':
         if self.music.url:
             return MusicReply(message=message,
                               title=self.music.music_title,
                               description=self.music.music_description,
                               url=self.music.url.link,
                               hq_url=self.music.hq_url.link)
     elif self.type == 'article':
         reply = ArticlesReply(message=message)
         if self.article:
             for art in self.article:
                 article = Article(
                     title=art.title,
                     description=art.description,
                     img=art.img.get_link(),
                     url=art.url,
                 )
                 reply.add_article(article)
             return reply
     return ''
Ejemplo n.º 2
0
def test_music_reply_process_args():
    reply = MusicReply(
        target='tg',
        source='ss',
        title='tt',
        description='ds',
        url='u1',
    )
    assert reply._args['hq_url'] == 'u1'

    reply_2 = MusicReply(target='tg',
                         source='ss',
                         title='tt',
                         description='ds',
                         url='u1',
                         hq_url='u2')
    assert reply_2._args['hq_url'] == 'u2'
Ejemplo n.º 3
0
def test_music_reply():
    t = int(time.time())
    reply = MusicReply(
        target='tg',
        source='ss',
        time=t,
        title='tt',
        description='ds',
        url='u1',
        hq_url='u2',
    )
    assert reply.render().strip() == """
    <xml>
    <ToUserName><![CDATA[tg]]></ToUserName>
    <FromUserName><![CDATA[ss]]></FromUserName>
    <CreateTime>{time}</CreateTime>
    <MsgType><![CDATA[music]]></MsgType>
    <Music>
    <Title><![CDATA[tt]]></Title>
    <Description><![CDATA[ds]]></Description>
    <MusicUrl><![CDATA[u1]]></MusicUrl>
    <HQMusicUrl><![CDATA[u2]]></HQMusicUrl>
    </Music>
    </xml>""".format(time=t).strip()