示例#1
0
    async def create_newroom(self, event, channel):
        """Send a NewRoom event."""
        user_id = event["channel"]["creator"]
        user_info = await self.connector.lookup_username(user_id)

        name = event["channel"].get("name_normalized", event["channel"].get("name"))
        return events.NewRoom(
            name=name,
            params=None,
            user=user_info["name"],
            user_id=user_id,
            target=event["channel"]["id"],
            connector=self.connector,
            event_id=event["event_ts"],
            raw_event=event,
        )
示例#2
0
    async def test_respond_new_room(self):
        event = events.NewRoom(name="test", target="!test:localhost")
        with amock.patch(api_string.format("create_room")) as patched_send, amock.patch(
            api_string.format("set_room_name")
        ) as patched_name:
            patched_name.return_value = asyncio.Future()
            patched_name.return_value.set_result(None)

            patched_send.return_value = asyncio.Future()
            patched_send.return_value.set_result({"room_id": "!test:localhost"})

            resp = await self.connector.send(event)
            assert resp == "!test:localhost"

            assert patched_name.called_once_with("#test:localhost", "test")

            assert patched_send.called_once_with()
 async def test_send_room_creation(self):
     connector = ConnectorSlack({"token": "abc123"}, opsdroid=self.od)
     connector.slack_user.api_call = amock.CoroutineMock()
     await connector.send(events.NewRoom(name="mynewroom"))
     connector.slack_user.api_call.assert_called_once_with(
         "conversations.create", data={"name": "mynewroom"})
示例#4
0
async def test_send_room_creation(send_event):
    event = events.NewRoom(name="new_room")
    payload, response = await send_event(CONVERSATIONS_CREATE, event)
    assert payload == {"name": "new_room"}
    assert response["ok"]