async def test_get_person(self): connector = ConnectorWebexTeams({"access-token": "abc123"}) connector.api = amock.CoroutineMock() connector.api.messages.create = amock.CoroutineMock() connector.api.people.get = amock.CoroutineMock() connector.api.people.get.return_value = "Himanshu" self.assertEqual(len(connector.people), 0) await connector.get_person("3vABZrQgDzfcz7LZi") self.assertEqual(len(connector.people), 1)
async def test_clean_up_webhooks(self): connector = ConnectorWebexTeams({"access-token": "abc123"}) connector.api = amock.CoroutineMock() x = amock.CoroutineMock() x.id = amock.CoroutineMock() connector.api.webhooks.list = amock.Mock() connector.api.webhooks.list.return_value = [x, x] connector.api.webhooks.delete = amock.Mock() await connector.clean_up_webhooks() self.assertTrue(connector.api.webhooks.list.called) self.assertTrue(connector.api.webhooks.delete.called)
async def test_respond(self): connector = ConnectorWebexTeams({"access-token": "abc123"}) connector.api = amock.CoroutineMock() connector.api.messages.create = amock.CoroutineMock() message = Message( text="Hello", user="******", target={"id": "3vABZrQgDzfcz7LZi"}, connector=None, ) await connector.send(message) self.assertTrue(connector.api.messages.create.called)
async def test_subscribe_to_rooms(self): connector = ConnectorWebexTeams({ "access-token": "abc123", "webhook-url": "http://127.0.0.1" }) connector.api = amock.CoroutineMock() connector.opsdroid = amock.CoroutineMock() connector.opsdroid.web_server.web_app.router.add_post = amock.CoroutineMock( ) connector.api.webhooks.create = amock.CoroutineMock() await connector.subscribe_to_rooms() self.assertTrue(connector.api.webhooks.create.called) self.assertTrue( connector.opsdroid.web_server.web_app.router.add_post.called)
async def test_message_handler(self): connector = ConnectorWebexTeams({"access-token": "abc123"}) connector.opsdroid = OpsDroid() connector.bot_spark_id = "spark123" connector.api = amock.CoroutineMock() request = amock.Mock() request.json = amock.CoroutineMock() request.json.return_value = { "data": { "id": "3vABZrQgDzfcz7LZi", "personId": "21ABZrQgDzfcz7Lsi" } } message = amock.Mock() connector.api.messages.get = amock.Mock() message.text = "Hello" message.roomId = "90ABCrWgrzfcz7LZi" message.roomType = "general" connector.api.messages.get.return_value = message connector.get_person = amock.CoroutineMock() person = amock.CoroutineMock() person.displayName = "Himanshu" connector.get_person.return_value = person response = await connector.webexteams_message_handler(request) self.assertLogs("_LOGGER", "debug") self.assertEqual(201, response.status) self.assertEqual('"Received"', response.text) self.assertTrue(connector.api.messages.get.called) self.assertTrue(connector.get_person.called) connector.opsdroid = amock.CoroutineMock() connector.opsdroid.parse = amock.CoroutineMock() connector.opsdroid.parse.side_effect = KeyError await connector.webexteams_message_handler(request) self.assertLogs("_LOGGER", "error")
async def test_set_own_id(self): connector = ConnectorWebexTeams({"access-token": "abc123"}) connector.api = amock.CoroutineMock() connector.api.people.me().id = "3vABZrQgDzfcz7LZi" await connector.set_own_id() self.assertTrue(connector.bot_webex_id, "3vABZrQgDzfcz7LZi")