Пример #1
0
    async def test_send_provided_messages(self):
        http = AsyncMock()
        url = "http://url"
        ch = Channel(url, http)
        await ch.send(["first message", "second message"])

        assert http.post.call_count == 2
        assert http.post.call_args_list == [
            call(url, json={"text": "first message"}),
            call(url, json={"text": "second message"}),
        ]
Пример #2
0
    async def test_send_provided_messages(self):
        http = AsyncMock()
        url = 'http://url'
        ch = Channel(url, http)
        await ch.send(['first message', 'second message'])

        assert http.post.call_count == 2
        assert http.post.call_args_list == [
            call(url, json={'text': 'first message'}),
            call(url, json={'text': 'second message'})
        ]
Пример #3
0
 def test_no_replace(self):
     '''
     Check that no substitutions are done on regular strings and nickname in url
     '''
     cases = [
         'ciao',
         'http://LtWorf/',
         'ciao https://link.com/LtWorf',
         'ciao https://link.com/LtWorf?param',
     ]
     dest = Channel('0', '0', None, None)
     for i in cases:
         assert asyncio.run(self.client._addmagic(i, dest)) == i
Пример #4
0
 def test_mentions(self):
     dest = Channel('0', '0', None, None)
     assert asyncio.run(self.client._addmagic('ciao LtWorf',
                                              dest)) == 'ciao <@LtWorf>'
     assert asyncio.run(self.client._addmagic('LtWorf: ciao',
                                              dest)) == '<@LtWorf>: ciao'
     assert asyncio.run(self.client._addmagic(
         'LtWorf: ciao LtWorf', dest)) == '<@LtWorf>: ciao <@LtWorf>'
     assert asyncio.run(self.client._addmagic('_LtWorf', dest)) == '_LtWorf'
     assert asyncio.run(
         self.client._addmagic(
             'LtWorf: http://link/user=LtWorf',
             dest)) == '<@LtWorf>: http://link/user=LtWorf'
Пример #5
0
    def _update_channels(self) -> None:
        data: Optional[List[Dict[str,
                                 Any]]] = self._call('rooms/get', [], True)
        if not data:
            raise Exception('No channel list was returned')
        self._channels.clear()

        for i in data:
            # Subscribe to it
            self._subscribe('stream-room-messages',
                            [i['_id'], {
                                'useCollection': False,
                                'args': []
                            }])

            # If it's a real channel
            channel_type = ChannelType(i.get('t'))
            if channel_type == ChannelType.CHANNEL:
                self._channels.append(
                    Channel(
                        id=i['_id'],
                        name_normalized=i['fname'],
                        purpose=Topic(i.get('topic', '')),
                        topic=Topic(i.get('topic', '')),
                    ))
            elif channel_type == ChannelType.PUBLIC_CHANNEL:
                self._channels.append(
                    Channel(
                        id=i['_id'],
                        name_normalized=i['name'],
                        purpose=Topic(i.get('topic', '')),
                        topic=Topic(i.get('topic', '')),
                    ))
            elif channel_type == ChannelType.QUERY:
                pass
            else:
                log('Unknown data %s' % repr(i))