How to use opsdroid - 10 common examples

To help you get started, we’ve selected a few opsdroid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github opsdroid / opsdroid / tests / test_connector_slack.py View on Github external
def test_init(self):
        """Test that the connector is initialised properly."""
        connector = ConnectorSlack({"token": "abc123"}, opsdroid=OpsDroid())
        self.assertEqual("#general", connector.default_target)
        self.assertEqual("slack", connector.name)
        self.assertEqual(10, connector.timeout)
github opsdroid / opsdroid / tests / test_database.py View on Github external
def test_init(self):
        config = {"example_item": "test"}
        database = Database(config)
        self.assertEqual("", database.name)
        self.assertEqual("test", database.config["example_item"])
github opsdroid / opsdroid / tests / test_connector_webexteams.py View on Github external
def test_init(self):
        """Test that the connector is initialised properly."""
        connector = ConnectorWebexTeams({})
        self.assertEqual("webexteams", connector.name)
        self.assertEqual("opsdroid", connector.bot_name)
github opsdroid / opsdroid / tests / test_connector_facebook.py View on Github external
async def test_respond(self):
        """Test that responding sends a message."""
        post_response = amock.Mock()
        post_response.status = 200

        with OpsDroid() as opsdroid, amock.patch(
            "aiohttp.ClientSession.post", new=asynctest.CoroutineMock()
        ) as patched_request:
            self.assertTrue(opsdroid.__class__.instances)
            connector = ConnectorFacebook({}, opsdroid=opsdroid)
            room = "a146f52c-548a-11e8-a7d1-28cfe949e12d"
            test_message = Message(
                text="Hello world", user="Alice", target=room, connector=connector
            )
            patched_request.return_value = asyncio.Future()
            patched_request.return_value.set_result(post_response)
            await test_message.respond("Response")
            self.assertTrue(patched_request.called)
github opsdroid / opsdroid / tests / test_connector.py View on Github external
def test_respond(self):
        connector = Connector({}, opsdroid=OpsDroid())
        with self.assertRaises(TypeError):
            self.loop.run_until_complete(connector.send(Message("")))
github opsdroid / opsdroid / tests / test_events.py View on Github external
self.assertTrue(mocksleep.called)

            # Test thinking-delay with a list

            mock_connector_list = Connector(
                {
                    "name": "shell",
                    "typing-delay": [1, 4],
                    "type": "connector",
                    "module_path": "opsdroid-modules.connector.shell",
                },
                opsdroid=opsdroid,
            )

            with amock.patch("asyncio.sleep") as mocksleep_list:
                message = events.Message(
                    "hi", "user_id", "user", "default", mock_connector_list
                )
                with self.assertRaises(TypeError):
                    await message.respond("Hello there")

                self.assertTrue(mocksleep_list.called)
github opsdroid / opsdroid / tests / test_connector_matrix.py View on Github external
async def test_send_reply(self):
        message = events.Message(
            "hello",
            event_id="$11111",
            connector=self.connector,
            target="!test:localhost",
        )
        reply = events.Reply("reply")
        with OpsDroid() as _:
            with amock.patch(api_string.format("send_message_event")) as patched_send:
                patched_send.return_value = asyncio.Future()
                patched_send.return_value.set_result(None)

                await message.respond(reply)

                content = self.connector._get_formatted_message_body(
                    reply.text, msgtype="m.text"
                )
github opsdroid / opsdroid / tests / test_parser_rasanlu.py View on Github external
async def test_call_rasanlu(self):
        opsdroid = amock.CoroutineMock()
        mock_connector = Connector({}, opsdroid=opsdroid)
        message = Message(
            text="how's the weather outside",
            user="user",
            target="default",
            connector=mock_connector,
        )
        config = {"name": "rasanlu", "min-score": 0.3, "token": "12345"}
        result = amock.Mock()
        result.status = 200
        result.json = amock.CoroutineMock()
        result.json.return_value = {
            "entities": [
                {
                    "end": 32,
                    "entity": "state",
                    "extractor": "ner_crf",
                    "confidence": 0.854,
github opsdroid / opsdroid / tests / test_events.py View on Github external
async def test_response_effects(self):
        """Responding to a message shouldn't change the message."""
        with OpsDroid() as opsdroid:
            mock_connector = Connector({}, opsdroid=opsdroid)
            message_text = "Hello world"
            message = events.Message(
                message_text, "user_id", "user", "default", mock_connector
            )
            with self.assertRaises(TypeError):
                await message.respond("Goodbye world")
            self.assertEqual(message_text, message.text)
github opsdroid / opsdroid / tests / test_parser_always.py View on Github external
async def test_parse_always_decorate_no_parens(self):
        with OpsDroid() as opsdroid:
            mock_skill = await self.getMockSkill()
            opsdroid.skills.append(match_always(mock_skill))
            opsdroid.run_skill = amock.CoroutineMock()

            mock_connector = amock.CoroutineMock()
            message = Message(
                text="Hello world",
                user="user",
                target="default",
                connector=mock_connector,
            )

            await parse_always(opsdroid, message)

            self.assertTrue(opsdroid.run_skill.called)