예제 #1
0
class TestConnectorShell(unittest.TestCase):
    """Test the opsdroid shell connector class."""
    def setUp(self):
        self.connector = ConnectorShell({
            "name": "shell",
            "bot-name": "opsdroid-test"
        })
        self.loop = asyncio.new_event_loop()
        configure_lang({})
        os.environ["USERNAME"] = "******"

    def test_init(self):
        """Test that the connector is initialised properly."""
        self.assertEqual(self.connector.user, "opsdroid")
        self.assertEqual(len(self.connector.config), 2)
        self.assertEqual("shell", self.connector.name)
        self.assertEqual("opsdroid-test", self.connector.bot_name)

    def test_is_listening(self):
        self.assertEqual(self.connector.listening, self.connector.is_listening)

    def test_is_listening_setter(self):
        self.assertEqual(self.connector.listening, self.connector.is_listening)
        self.connector.is_listening = False
        self.assertFalse(self.connector.listening)

    def test_draw_prompt(self):
        self.assertEqual(self.connector.prompt_length, None)

        f = io.StringIO()
        with contextlib.redirect_stdout(f):
            self.connector.prompt_length = 1
            self.connector.draw_prompt()
            prompt = f.getvalue()
            self.assertEqual(prompt, "opsdroid-test> ")
        self.connector.draw_prompt()
        self.assertEqual(self.connector.prompt_length, 15)

    def test_clear_prompt(self):
        self.connector.prompt_length = 1

        f = io.StringIO()
        with contextlib.redirect_stdout(f):
            self.connector.clear_prompt()
            prompt = f.getvalue()
            self.assertEqual(prompt, "\r \r")
예제 #2
0
    async def test_parseloop(self):
        connector = ConnectorShell({}, opsdroid=OpsDroid())

        connector.draw_prompt = amock.CoroutineMock()
        connector.draw_prompt.return_value = "opsdroid> "
        connector.async_input = amock.CoroutineMock()
        connector.async_input.return_value = "hello"

        connector.opsdroid = amock.CoroutineMock()
        connector.opsdroid.parse = amock.CoroutineMock()

        await connector.parseloop()
        self.assertTrue(connector.opsdroid.parse.called)