Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
def test_init(self):
config = {"example_item": "test"}
database = Database(config)
self.assertEqual("", database.name)
self.assertEqual("test", database.config["example_item"])
def test_init(self):
"""Test that the connector is initialised properly."""
connector = ConnectorWebexTeams({})
self.assertEqual("webexteams", connector.name)
self.assertEqual("opsdroid", connector.bot_name)
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)
def test_respond(self):
connector = Connector({}, opsdroid=OpsDroid())
with self.assertRaises(TypeError):
self.loop.run_until_complete(connector.send(Message("")))
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)
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"
)
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,
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)
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)