Example #1
0
    def test_format(self):

        logging.info('***** format')

        u = Updater()

        inbound = 'hello world'
        outbound = u.format(inbound)
        self.assertEqual(outbound, inbound)

        inbound = Message({'text': 'hello world'})
        outbound = u.format(inbound)
        self.assertEqual(json.loads(outbound), {
            "text": "hello world",
            "type": "message"
        })

        inbound = Message({'personEmail': '*****@*****.**'})
        outbound = u.format(inbound)
        self.assertEqual(json.loads(outbound), {
            "type": "message",
            "personEmail": "*****@*****.**"
        })

        inbound = Message({'text': 'hello world', 'personEmail': '*****@*****.**'})
        outbound = u.format(inbound)
        self.assertEqual(json.loads(outbound), {
            "text": "hello world",
            "type": "message",
            "personEmail": "*****@*****.**"
        })
Example #2
0
    def test_put(self):

        logging.info('***** put')

        class FakeDb(object):
            def __init__(self):
                self.expected = None

            def index(self, index, doc_type, body):
                assert index == 'shellbot'
                assert doc_type == 'event'
                assert body == self.expected

        u = ElasticsearchUpdater()
        u.db = FakeDb()

        message_1 = Message({
            'person_label': '*****@*****.**',
            'text': 'a first message',
        })
        u.db.expected = message_1.attributes
        u.put(message_1)

        message_2 = Message({
            'person_label': '*****@*****.**',
            'text': 'a second message',
        })
        u.db.expected = message_2.attributes
        u.put(message_2)
Example #3
0
    def test_message(self):

        item = {
            "id": "Z2lzY29zcGFyazovL3VzDNiZC0xMWU2LThhZTktZGQ1YjNkZmM1NjVk",
            "channel_id": "Y2lzY29zcGFyazovNmMS0zYLTkxNDctZjE0YmIwYzRkMTU0",
            "text": "/plumby use containers/docker",
            "content": "<p>/plumby use containers/docker</p>",
            "stamp": "2015-10-18T14:26:16+00:00",
            "from_id": "Y2lzY29zcGFyjOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
            "from_label": "Masked Cucumber",
            "is_direct": True,
            "mentioned_ids": ["Y2lzYDMzLTRmYTUtYTcyYS1jYzg5YjI1ZWVlMmX"],
        }

        event = Message(item)
        self.assertEqual(event.type, 'message')
        self.assertEqual(event.channel_id,
                         "Y2lzY29zcGFyazovNmMS0zYLTkxNDctZjE0YmIwYzRkMTU0")
        self.assertEqual(event.text, "/plumby use containers/docker")
        self.assertEqual(event.content, "<p>/plumby use containers/docker</p>")
        self.assertEqual(event.stamp, "2015-10-18T14:26:16+00:00")
        self.assertEqual(event.from_id,
                         "Y2lzY29zcGFyjOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY")
        self.assertEqual(event.from_label, "Masked Cucumber")
        self.assertEqual(event.is_direct, True)
        self.assertEqual(event.mentioned_ids,
                         ["Y2lzYDMzLTRmYTUtYTcyYS1jYzg5YjI1ZWVlMmX"])
        self.assertEqual(event.url, None)
        self.assertEqual(event.attachment, None)

        item.update({'type': 'message'})
        self.assertEqual(json.loads(str(event)), item)
        self.assertEqual(yaml.safe_load(str(event)), item)

        item = {
            "id": "Z2lzY29zcGFyazovL3VzDNiZC0xMWU2LThhZTktZGQ1YjNkZmM1NjVk",
            "channel_id": "Y2lzY29zcGFyazovNmMS0zYLTkxNDctZjE0YmIwYzRkMTU0",
            "text": "/plumby use containers/docker",
            "stamp": "2015-10-18T14:26:16+00:00",
            "from_id": "Y2lzY29zcGFyjOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
            "from_label": "Masked Cucumber",
            "mentioned_ids": ["Y2lzYDMzLTRmYTUtYTcyYS1jYzg5YjI1ZWVlMmX"],
        }

        event = Message(item)
        self.assertEqual(event.text, event.content)
Example #4
0
    def test_message_queue(self):

        item = {
            "id": "Z2lzY29zcGFyazovL3VzDNiZC0xMWU2LThhZTktZGQ1YjNkZmM1NjVk",
            "channel_id": "Y2lzY29zcGFyazovNmMS0zYLTkxNDctZjE0YmIwYzRkMTU0",
            "text": "/plumby use containers/docker",
            "stamp": "2015-10-18T14:26:16+00:00",
            "from_id": "Y2lzY29zcGFyjOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
            "from_label": "Masked Cucumber",
            "is_direct": True,
            "mentioned_ids": ["Y2lzYDMzLTRmYTUtYTcyYS1jYzg5YjI1ZWVlMmX"],
        }

        before = Message(item)
        my_queue = Queue()
        my_queue.put(str(before))
        after = Message(my_queue.get())
        self.assertEqual(after.attributes, item)
Example #5
0
    def test_put(self):

        logging.info('***** put')

        try:
            os.remove(my_file)
        except:
            pass

        try:
            os.rmdir(my_path)
        except:
            pass

        u = FileUpdater(path=my_file)
        u.on_bond(bot='*dummy')

        message_1 = Message({
            'person_label': '*****@*****.**',
            'text': 'a first message',
        })
        u.put(message_1)

        message_2 = Message({
            'person_label': '*****@*****.**',
            'text': 'a second message',
        })
        u.put(message_2)

        expected = '{"person_label": "*****@*****.**", "text": "a first message", "type": "message"}\n{"person_label": "*****@*****.**", "text": "a second message", "type": "message"}\n'
        with open(my_file, 'r') as handle:
            self.assertEqual(handle.read(), expected)

        try:
            os.remove(my_file)
        except:
            pass

        try:
            os.rmdir(my_path)
        except:
            pass
Example #6
0
    def on_message(self, item, queue):
        """
        Normalizes message for the listener

        :param item: attributes of the inbound message
        :type item: dict

        :param queue: the processing queue
        :type queue: Queue

        This function prepares a Message and push it to the provided queue.

        """
        message = Message(item)
        message.from_id = '*user'
        message.mentioned_ids = [self.context.get('bot.id')]
        message.channel_id = '*local'

        logging.debug(u"- putting message to ears")
        queue.put(str(message))
Example #7
0
    def test_format(self):

        logging.info('***** format')

        space = mock.Mock()
        speaker = mock.Mock()
        u = SpaceUpdater(space=space, speaker=speaker)

        inbound = Event({
            'who_cares': 'no attribute will be used anayway',
        })
        outbound = u.format(inbound)
        self.assertEqual(outbound, u'an unknown event has been received')

        inbound = Message({
            'from_label': '*****@*****.**',
            'text': 'my message',
        })
        outbound = u.format(inbound)
        self.assertEqual(outbound, '[email protected]: my message')

        inbound = Message({
            'from_label': '*****@*****.**',
            'text': 'my message',
            'content': '<p>my message</p>',
        })
        outbound = u.format(inbound)
        self.assertEqual(outbound.text, '[email protected]: my message')
        self.assertEqual(outbound.content, '[email protected]: <p>my message</p>')

        inbound = Join({
            'actor_label': '*****@*****.**',
        })
        outbound = u.format(inbound)
        self.assertEqual(outbound, u'[email protected] has joined')

        inbound = Leave({
            'actor_label': '*****@*****.**',
        })
        outbound = u.format(inbound)
        self.assertEqual(outbound, u'[email protected] has left')
Example #8
0
    def test_message_init(self):

        event = Message()
        self.assertEqual(event.type, 'message')
        with self.assertRaises(AttributeError):
            message = event.text
        self.assertEqual(event.attachment, None)
        self.assertEqual(event.url, None)
        self.assertEqual(event.from_id, None)
        self.assertEqual(event.from_label, None)
        self.assertEqual(event.is_direct, False)
        self.assertEqual(event.mentioned_ids, [])
        self.assertEqual(event.channel_id, None)
        self.assertEqual(event.stamp, None)
Example #9
0
    def test_filter(self):

        logging.info('***** filter')

        u = Updater()
        u.put = mock.Mock()
        message = Message({
            'personEmail': '*****@*****.**',
            'text': 'my message',
        })

        outcome = u.filter(message)
        self.assertEqual(outcome.attributes, message.attributes)
        u.put.assert_called_with(message)
Example #10
0
    def test_put(self):

        logging.info('***** put')

        u = QueueUpdater()

        message_1 = Message({
            'person_label': '*****@*****.**',
            'text': 'a first message',
        })
        u.put(message_1)

        message_2 = Message({
            'person_label': '*****@*****.**',
            'text': 'a second message',
        })
        u.put(message_2)

        message_1.attributes.update({"type": "message"})
        self.assertEqual(yaml.safe_load(u.queue.get()), message_1.attributes)

        message_2.attributes.update({"type": "message"})
        self.assertEqual(yaml.safe_load(u.queue.get()), message_2.attributes)
Example #11
0
    def test_put(self):

        logging.info('***** put')

        u = Updater()
        message = Message({
            'personEmail': '*****@*****.**',
            'text': 'my message',
        })

        with mock.patch('sys.stdout') as mocked:
            u.put(message)
            mocked.write.assert_called_with(
                '{"personEmail": "*****@*****.**", "text": "my message", "type": "message"}\n'
            )
Example #12
0
    def test_put(self):

        logging.info('***** put')

        space = mock.Mock()
        speaker = mock.Mock()
        u = SpaceUpdater(space=space, speaker=speaker)

        item = Message({
            'from_label': '*****@*****.**',
            'text': 'my message',
        })

        u.put(item)
        self.assertEqual(u.mouth.get(), '[email protected]: my message')
        with self.assertRaises(Exception):
            u.mouth.get_nowait()
Example #13
0
    def test_event___eq__(self):

        a = Event({"hello": "world"})
        b = Event({"hello": "world"})
        self.assertEqual(a, b)

        a = Event({"hello": "world"})
        b = Event({"hello": "world"})
        self.assertTrue(a.__eq__(b))
        self.assertTrue(b.__eq__(a))

        a = Event({"hello": "world"})
        b = Event({"hello": "moon"})
        self.assertFalse(a.__eq__(b))
        self.assertFalse(b.__eq__(a))

        a = Event({"hello": "world"})
        b = Message({"hello": "world"})
        self.assertFalse(a.__eq__(b))
        self.assertFalse(b.__eq__(a))

        a = Event({"hello": "world"})
        b = {"hello": "world"}
        self.assertFalse(a.__eq__(b))
Example #14
0
 def setUp(self):
     self.engine = MyEngine(mouth=Queue())
     self.engine.configure()
     self.bot = MyBot(engine=self.engine)
     self.message = Message(my_message)
     self.upload = Message(my_upload)
Example #15
0
    def test_dynamic(self):

        logging.info('*** Dynamic test ***')

        self.engine.speaker.start()
        self.engine.listener.start()

        items = [
            {
                "id":
                "1_lzY29zcGFyazovL3VzL01FU1NBR0UvOTJkYjNiZTAtNDNiZC0xMWU2LThhZTktZGQ1YjNkZmM1NjVk",
                "channel_id":
                "Y2lzY29zcGFyazovL3VzL1JPT00vYmJjZWIxYWQtNDNmMS0zYjU4LTkxNDctZjE0YmIwYzRkMTU0",
                "roomType":
                "group",
                "toPersonId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mMDZkNzFhNS0wODMzLTRmYTUtYTcyYS1jYzg5YjI1ZWVlMmX",
                "toPersonEmail":
                "*****@*****.**",
                "text":
                "PROJECT UPDATE - A new project plan has been published on Box: http://box.com/s/lf5vj. The PM for this project is Mike C. and the Engineering Manager is Jane W.",
                "markdown":
                "**PROJECT UPDATE** A new project plan has been published [on Box](http://box.com/s/lf5vj). The PM for this project is <@personEmail:[email protected]> and the Engineering Manager is <@personEmail:[email protected]>.",
                "files": ["http://www.example.com/images/media.png"],
                "personId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "personEmail":
                "*****@*****.**",
                "stamp":
                "2015-10-18T14:26:16+00:00",
                "mentionedPeople": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
                "type":
                "message",
                "from_id":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
            },
            {
                "id":
                "2_2lzY29zcGFyazovL3VzL01FU1NBR0UvOTJkYjNiZTAtNDNiZC0xMWU2LThhZTktZGQ1YjNkZmM1NjVk",
                "channel_id":
                "Y2lzY29zcGFyazovL3VzL1JPT00vYmJjZWIxYWQtNDNmMS0zYjU4LTkxNDctZjE0YmIwYzRkMTU0",
                "roomType":
                "group",
                "toPersonId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mMDZkNzFhNS0wODMzLTRmYTUtYTcyYS1jYzg5YjI1ZWVlMmX",
                "toPersonEmail":
                "*****@*****.**",
                "text":
                "/shelly version",
                "personId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "personEmail":
                "*****@*****.**",
                "stamp":
                "2015-10-18T14:26:16+00:00",
                "mentionedPeople": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
                "type":
                "message",
                "from_id":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "mentioned_ids": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
            },
            {
                "id":
                "3_2lzY29zcGFyazovL3VzL01FU1NBR0UvOTJkYjNiZTAtNDNiZC0xMWU2LThhZTktZGQ1YjNkZmM1NjVk",
                "channel_id":
                "Y2lzY29zcGFyazovL3VzL1JPT00vYmJjZWIxYWQtNDNmMS0zYjU4LTkxNDctZjE0YmIwYzRkMTU0",
                "roomType":
                "group",
                "toPersonId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mMDZkNzFhNS0wODMzLTRmYTUtYTcyYS1jYzg5YjI1ZWVlMmX",
                "toPersonEmail":
                "*****@*****.**",
                "text":
                "@shelly help",
                "personId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "personEmail":
                "*****@*****.**",
                "stamp":
                "2015-10-18T14:26:16+00:00",
                "mentionedPeople": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
                "type":
                "message",
                "from_id":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "mentioned_ids": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
            },
            {
                "id":
                "3_2lzY29zcGFyazovL3VzL01FU1NBR0UvOTJkYjNiZTAtNDNiZC0xMWU2LThhZTktZGQ1YjNkZmM1NjVk",
                "channel_id":
                "Y2lzY29zcGFyazovL3VzL1JPT00vYmJjZWIxYWQtNDNmMS0zYjU4LTkxNDctZjE0YmIwYzRkMTU0",
                "roomType":
                "group",
                "toPersonId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mMDZkNzFhNS0wODMzLTRmYTUtYTcyYS1jYzg5YjI1ZWVlMmX",
                "toPersonEmail":
                "*****@*****.**",
                "text":
                "!shelly sleep 0.01",
                "personId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "personEmail":
                "*****@*****.**",
                "stamp":
                "2015-10-18T14:26:16+00:00",
                "mentionedPeople": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
                "type":
                "message",
                "from_id":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "mentioned_ids": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
            },
            {
                "id":
                "4_2lzY29zcGFyazovL3VzL01FU1NBR0UvOTJkYjNiZTAtNDNiZC0xMWU2LThhZTktZGQ1YjNkZmM1NjVk",
                "channel_id":
                "Y2lzY29zcGFyazovL3VzL1JPT00vYmJjZWIxYWQtNDNmMS0zYjU4LTkxNDctZjE0YmIwYzRkMTU0",
                "roomType":
                "group",
                "toPersonId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mMDZkNzFhNS0wODMzLTRmYTUtYTcyYS1jYzg5YjI1ZWVlMmX",
                "toPersonEmail":
                "*****@*****.**",
                "text":
                "PROJECT UPDATE - A new project plan has been published on Box: http://box.com/s/lf5vj. The PM for this project is Mike C. and the Engineering Manager is Jane W.",
                "markdown":
                "**PROJECT UPDATE** A new project plan has been published [on Box](http://box.com/s/lf5vj). The PM for this project is <@personEmail:[email protected]> and the Engineering Manager is <@personEmail:[email protected]>.",
                "files": ["http://www.example.com/images/media.png"],
                "personId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "personEmail":
                "*****@*****.**",
                "stamp":
                "2015-10-18T14:26:16+00:00",
                "mentionedPeople": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
                "type":
                "message",
                "from_id":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "mentioned_ids": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM"
                ],
            },
        ]

        for item in items:
            self.engine.ears.put(str(Message(item)))

        self.engine.listener.join(1.0)
        if self.engine.listener.is_alive():
            logging.info('Stopping all threads')
            self.engine.set('general.switch', 'off')
            self.engine.listener.join()
            self.engine.speaker.join()

        self.assertEqual(self.engine.get('listener.counter', 0), 5)
        self.assertEqual(self.engine.get('speaker.counter', 0), 2)
Example #16
0
    def on_message(self, item, queue=None):
        """
        Normalizes message for the listener

        :param item: attributes of the inbound message
        :type item: dict

        :param queue: the processing queue (optional)
        :type queue: Queue

        :return: a Message

        This function prepares a Message and push it to the provided queue.

        This function adds following keys to messages so that a neutral format
        can be used with the listener:

        * ``type`` is set to ``message``
        * ``content`` is a copy of ``html``
        * ``from_id`` is a copy of ``personId``
        * ``from_label`` is a copy of ``personEmail``
        * ``is_direct`` if the message is coming from 1:1 room
        * ``mentioned_ids`` is a copy of ``mentionedPeople``
        * ``channel_id`` is a copy of ``roomId``
        * ``stamp`` is a copy of ``created``

        """
        message = Message(item.copy())
        message.content = message.get('html', message.text)
        message.from_id = message.get('personId')
        message.from_label = message.get('personEmail')
        message.is_direct = True if message.get('roomType') == 'direct' else False
        message.mentioned_ids = message.get('mentionedPeople', [])
        message.channel_id = message.get('roomId')
        message.stamp = message.get('created')

        files = item.get('files', [])
        if files:
            url = files[0]
            message.url = url

            if message.hook == 'shellbot-audit':
                token = self.context.get('space.audit_token', '*no*token')
            else:
                token = self.context.get('space.token', '*no*token')

            message.attachment = self.name_attachment(url, token=token)

        if queue:
            logging.debug(u"- putting message to queue")
            queue.put(str(message))

        return message
Example #17
0
my_01_message_from_bot_in_group = Message({
    "channel_id":
    "*id1",
    "content":
    "<p>Hello there!</p>",
    "stamp":
    "2017-07-30T20:34:35.593Z",
    "files": ["http://hydra-a5.wbx2.com/MWU3LTg5MzgtZjU1MWY1ZTU1ZmE5LzA"],
    "from_id":
    "*shelly*id",
    "from_label":
    "*****@*****.**",
    "hook":
    "shellbot-audit",
    "id":
    "Y2lzY29zcGFyazovL3VzL01FU1NBR0UvgtZjU1MWY1ZTU1ZmE5",
    "is_direct":
    False,
    "markdown":
    "Hello there!",
    "mentioned_ids": [],
    "personEmail":
    "*****@*****.**",
    "personId":
    "*shelly*id",
    "roomId":
    "*id1",
    "roomType":
    "group",
    "text":
    "Type '@shelly help' for more information",
    "type":
    "message",
})
Example #18
0
my_message = Message({
    "id":
    "1_lzY29zcGFyazovL3VzL01FU1NBR0UvOTJkYjNiZTAtNDNiZC0xMWU2LThhZTktZGQ1YjNkZmM1NjVk",
    "channel_id":
    "Y2lzY29zcGFyazovL3VzL1JPT00vYmJjZWIxYWQtNDNmMS0zYjU4LTkxNDctZjE0YmIwYzRkMTU0",
    "roomType":
    "group",
    "toPersonId":
    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mMDZkNzFhNS0wODMzLTRmYTUtYTcyYS1jYzg5YjI1ZWVlMmX",
    "toPersonEmail":
    "*****@*****.**",
    "text":
    "The PM for this project is Mike C. and the Engineering Manager is Jane W.",
    "markdown":
    "**PROJECT UPDATE** A new project plan has been published [on Box](http://box.com/s/lf5vj). The PM for this project is <@personEmail:[email protected]> and the Engineering Manager is <@personEmail:[email protected]>.",
    "files": ["http://www.example.com/images/media.png"],
    "personId":
    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
    "personEmail":
    "*****@*****.**",
    "stamp":
    "2015-10-18T14:26:16+00:00",
    "mentionedPeople": [
        "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
        "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
    ],
    "from_id":
    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
    "mentioned_ids": [
        "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
        "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
    ],
    "attachment":
    "media.png",
    "url":
    "http://www.example.com/images/media.png",
})
Example #19
0
    def test_dynamic(self):

        logging.info('*** Dynamic test ***')

        items = [
            {
                "id":
                "1_lzY29zcGFyazovL3VzL01FU1NBR0UvOTJkYjNiZTAtNDNiZC0xMWU2LThhZTktZGQ1YjNkZmM1NjVk",
                "channel_id":
                "Y2lzY29zcGFyazovL3VzL1JPT00vYmJjZWIxYWQtNDNmMS0zYjU4LTkxNDctZjE0YmIwYzRkMTU0",
                "roomType":
                "group",
                "toPersonId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mMDZkNzFhNS0wODMzLTRmYTUtYTcyYS1jYzg5YjI1ZWVlMmX",
                "toPersonEmail":
                "*****@*****.**",
                "text":
                "PROJECT UPDATE - A new project plan has been published on Box: http://box.com/s/lf5vj. The PM for this project is Mike C. and the Engineering Manager is Jane W.",
                "markdown":
                "**PROJECT UPDATE** A new project plan has been published [on Box](http://box.com/s/lf5vj). The PM for this project is <@personEmail:[email protected]> and the Engineering Manager is <@personEmail:[email protected]>.",
                "files": ["http://www.example.com/images/media.png"],
                "personId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "personEmail":
                "*****@*****.**",
                "stamp":
                "2015-10-18T14:26:16+00:00",
                "mentionedPeople": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
                "from_id":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
            },
            {
                "id":
                "2_2lzY29zcGFyazovL3VzL01FU1NBR0UvOTJkYjNiZTAtNDNiZC0xMWU2LThhZTktZGQ1YjNkZmM1NjVk",
                "channel_id":
                "Y2lzY29zcGFyazovL3VzL1JPT00vYmJjZWIxYWQtNDNmMS0zYjU4LTkxNDctZjE0YmIwYzRkMTU0",
                "roomType":
                "group",
                "toPersonId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mMDZkNzFhNS0wODMzLTRmYTUtYTcyYS1jYzg5YjI1ZWVlMmX",
                "toPersonEmail":
                "*****@*****.**",
                "text":
                "/shelly version",
                "personId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "personEmail":
                "*****@*****.**",
                "stamp":
                "2015-10-18T14:26:16+00:00",
                "mentionedPeople": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
                "from_id":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "mentioned_ids": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
            },
            {
                "id":
                "2_2lzY29zcGFyazovL3VzL01FU1NBR0UvOTJkYjNiZTAtNDNiZC0xMWU2LThhZTktZGQ1YjNkZmM1NjVk",
                "channel_id":
                "Y2lzY29zcGFyazovL3VzL1JPT00vYmJjZWIxYWQtNDNmMS0zYjU4LTkxNDctZjE0YmIwYzRkMTU0",
                "roomType":
                "group",
                "toPersonId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mMDZkNzFhNS0wODMzLTRmYTUtYTcyYS1jYzg5YjI1ZWVlMmX",
                "toPersonEmail":
                "*****@*****.**",
                "text":
                "",
                "personId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "personEmail":
                "*****@*****.**",
                "stamp":
                "2015-10-18T14:26:16+00:00",
                "mentionedPeople": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
                "from_id":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "mentioned_ids": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
            },
            {
                "id":
                "3_2lzY29zcGFyazovL3VzL01FU1NBR0UvOTJkYjNiZTAtNDNiZC0xMWU2LThhZTktZGQ1YjNkZmM1NjVk",
                "channel_id":
                "Y2lzY29zcGFyazovL3VzL1JPT00vYmJjZWIxYWQtNDNmMS0zYjU4LTkxNDctZjE0YmIwYzRkMTU0",
                "roomType":
                "group",
                "toPersonId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mMDZkNzFhNS0wODMzLTRmYTUtYTcyYS1jYzg5YjI1ZWVlMmX",
                "toPersonEmail":
                "*****@*****.**",
                "text":
                "@shelly help",
                "personId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "personEmail":
                "*****@*****.**",
                "stamp":
                "2015-10-18T14:26:16+00:00",
                "mentionedPeople": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
                "from_id":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "mentioned_ids": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
            },
            {
                "id":
                "3_2lzY29zcGFyazovL3VzL01FU1NBR0UvOTJkYjNiZTAtNDNiZC0xMWU2LThhZTktZGQ1YjNkZmM1NjVk",
                "channel_id":
                "Y2lzY29zcGFyazovL3VzL1JPT00vYmJjZWIxYWQtNDNmMS0zYjU4LTkxNDctZjE0YmIwYzRkMTU0",
                "roomType":
                "group",
                "toPersonId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mMDZkNzFhNS0wODMzLTRmYTUtYTcyYS1jYzg5YjI1ZWVlMmX",
                "toPersonEmail":
                "*****@*****.**",
                "text":
                "!shelly help help",
                "personId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "personEmail":
                "*****@*****.**",
                "stamp":
                "2015-10-18T14:26:16+00:00",
                "mentionedPeople": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
                "from_id":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "mentioned_ids": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
            },
            {
                "id":
                "4_2lzY29zcGFyazovL3VzL01FU1NBR0UvOTJkYjNiZTAtNDNiZC0xMWU2LThhZTktZGQ1YjNkZmM1NjVk",
                "channel_id":
                "Y2lzY29zcGFyazovL3VzL1JPT00vYmJjZWIxYWQtNDNmMS0zYjU4LTkxNDctZjE0YmIwYzRkMTU0",
                "roomType":
                "group",
                "toPersonId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mMDZkNzFhNS0wODMzLTRmYTUtYTcyYS1jYzg5YjI1ZWVlMmX",
                "toPersonEmail":
                "*****@*****.**",
                "text":
                "PROJECT UPDATE - A new project plan has been published on Box: http://box.com/s/lf5vj. The PM for this project is Mike C. and the Engineering Manager is Jane W.",
                "markdown":
                "**PROJECT UPDATE** A new project plan has been published [on Box](http://box.com/s/lf5vj). The PM for this project is <@personEmail:[email protected]> and the Engineering Manager is <@personEmail:[email protected]>.",
                "files": ["http://www.example.com/images/media.png"],
                "personId":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "personEmail":
                "*****@*****.**",
                "stamp":
                "2015-10-18T14:26:16+00:00",
                "mentionedPeople": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM",
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS83YWYyZjcyYy0xZDk1LTQxZjAtYTcxNi00MjlmZmNmYmM0ZDg"
                ],
                "from_id":
                "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY",
                "mentioned_ids": [
                    "Y2lzY29zcGFyazovL3VzL1BFT1BMRS8yNDlmNzRkOS1kYjhhLTQzY2EtODk2Yi04NzllZDI0MGFjNTM"
                ],
            },
            {
                "id":
                "Y2lzY29zcGFyazovL3VzL01FU1NB0xMWU3LTljODctNTljZjJjNDRhYmIy",
                "roomId":
                "Y2lzY29zcGFyazovL3VzL1JP0zY2VmLWJiNDctOTZlZjA1NmJhYzFl",
                "roomType":
                "direct",
                "text":
                "test",
                "stamp":
                "2017-07-22T16:49:22.008Z",
                "hook":
                "shellbot-messages",
                "personEmail":
                "*****@*****.**",
                "personId":
                "Y2lzY29zcGFyazovL3VzL1LTQ5YzQtYTIyYi1mYWYwZWQwMjkyMzU",
                "content":
                "test",
                "from_id":
                'Y2lzY29zcGFyazovL3VzL1LTQ5YzQtYTIyYi1mYWYwZWQwMjkyMzU',
                "from_label":
                '*****@*****.**',
                'is_direct':
                True,
                "mentioned_ids": [],
                "channel_id":
                'Y2lzY29zcGFyazovL3VzL1JP0zY2VmLWJiNDctOTZlZjA1NmJhYzFl',
            },
        ]

        for item in items:
            self.engine.ears.put(str(Message(item)))

        self.engine.ears.put(None)

        tee = Queue()

        def filter(item):
            tee.put(str(item))
            return item

        listener = Listener(engine=self.engine, filter=filter)
        listener.DEFER_DURATION = 0.0

        listener.run()
        time.sleep(0.01)

        self.assertEqual(self.engine.get('listener.counter'), 7)
        with self.assertRaises(Exception):
            self.engine.ears.get_nowait()
        self.assertEqual(self.engine.mouth.get_nowait().text,
                         'Shelly version *unknown*')
        self.assertEqual(
            self.engine.mouth.get_nowait().text,
            u'Available commands:\n' + u'help - Show commands and usage')
        self.assertEqual(
            self.engine.mouth.get_nowait().text,
            u'Available commands:\n' + u'help - Show commands and usage')
        self.assertEqual(
            self.engine.mouth.get_nowait().text,
            u'help - Show commands and usage\nusage: help <command>')
        self.assertEqual(self.engine.mouth.get_nowait().text,
                         u"Sorry, I do not know how to handle 'test'")
        with self.assertRaises(Exception):
            print(self.engine.mouth.get_nowait())

        self.maxDiff = None
        for item in items:
            item.update({'type': 'message'})
            self.assertEqual(yaml.safe_load(tee.get()), item)
        with self.assertRaises(Exception):
            print(tee.get_nowait())