async def test_react_unknown_error(self): import slacker connector = ConnectorSlack({"api-token": "abc123"}) connector.slacker.reactions.post = amock.CoroutineMock(side_effect=slacker.Error('unknown')) with self.assertRaises(slacker.Error), OpsDroid() as opsdroid: prev_message = Message("test", "user", "room", connector, raw_event={'ts': 0}) await prev_message.respond(Reaction("😀"))
async def test_react_invalid_name(self): import slacker connector = ConnectorSlack({"api-token": "abc123"}) connector.slacker.reactions.post = amock.CoroutineMock(side_effect=slacker.Error('invalid_name')) prev_message = Message("test", "user", "room", connector, raw_event={'ts': 0}) with OpsDroid() as opsdroid: await prev_message.respond(Reaction("😀")) self.assertLogs('_LOGGER', 'warning')
async def test_react(self): connector = ConnectorSlack({"api-token": "abc123"}) connector.slacker.reactions.post = amock.CoroutineMock() prev_message = Message("test", "user", "room", connector, raw_event={'ts': 0}) with OpsDroid() as opsdroid: await prev_message.respond(Reaction("😀")) self.assertTrue(connector.slacker.reactions.post) self.assertEqual( connector.slacker.reactions.post.call_args[1]['data']['name'], ':grinning_face:')
async def test_react(self): connector = ConnectorSlack({"api-token": "abc123"}) connector.slack.api_call = amock.CoroutineMock() prev_message = Message("test", "user", "room", connector, raw_event={"ts": 0}) with OpsDroid() as opsdroid: await prev_message.respond(Reaction("😀")) self.assertTrue(connector.slack.api_call) self.assertEqual(connector.slack.api_call.call_args[1]["data"]["name"], "grinning_face")
async def test_react_unknown_error(self): import slack connector = ConnectorSlack({"api-token": "abc123"}) connector.slack.api_call = amock.CoroutineMock( side_effect=slack.errors.SlackApiError("unknown", "unknown")) with self.assertRaises(slack.errors.SlackApiError), OpsDroid(): prev_message = Message("test", "user", "room", connector, raw_event={"ts": 0}) await prev_message.respond(Reaction("😀"))
async def test_react_invalid_name(self): import slack connector = ConnectorSlack({"api-token": "abc123"}) connector.slack.api_call = amock.CoroutineMock( side_effect=slack.errors.SlackApiError("invalid_name", "invalid_name")) prev_message = Message("test", "user", "room", connector, raw_event={"ts": 0}) with OpsDroid() as opsdroid: await prev_message.respond(Reaction("😀")) self.assertLogs("_LOGGER", "warning")
async def react(self, message, emoji): """React to a message. Not all connectors will have capabilities to react messages, so this method don't have to be implemented and by default logs a debug message and returns False. Args: message (Message): A message received by the connector. emoji (string): The emoji name with which opsdroid will react Returns: bool: True for message successfully sent. False otherwise. """ warnings.warn( "Connector.react is deprecated. Use " "Connector.send(events.Reaction(emoji)) instead.", DeprecationWarning) return await message.respond(Reaction(emoji))
def test_unsupported_event(self): connector = Connector({}, opsdroid=OpsDroid()) with self.assertRaises(TypeError): self.loop.run_until_complete(connector.send(Reaction("emoji")))
def test_unsupported_event(self, event_loop, get_connector): with pytest.raises(TypeError): event_loop.run_until_complete(get_connector().send( Reaction("emoji")))