Exemplo n.º 1
0
    async def test_unload_and_stop(self):
        with OpsDroid() as opsdroid:
            mock_connector = Connector({}, opsdroid=opsdroid)
            mock_connector.disconnect = amock.CoroutineMock()
            opsdroid.connectors = [mock_connector]

            mock_database = Database({})
            mock_database.disconnect = amock.CoroutineMock()
            opsdroid.memory.databases = [mock_database]

            mock_skill = amock.Mock(config={"name": "mockskill"})
            opsdroid.skills = [mock_skill]

            opsdroid.web_server = Web(opsdroid)
            opsdroid.web_server.stop = amock.CoroutineMock()
            mock_web_server = opsdroid.web_server

            async def task():
                await asyncio.sleep(0.5)

            t = asyncio.Task(task(), loop=self.loop)

            await opsdroid.stop()
            await opsdroid.unload()

            self.assertTrue(t.cancel())
            self.assertTrue(mock_connector.disconnect.called)
            self.assertTrue(mock_database.disconnect.called)
            self.assertTrue(mock_web_server.stop.called)
            self.assertTrue(opsdroid.web_server is None)
            self.assertFalse(opsdroid.connectors)
            self.assertFalse(opsdroid.memory.databases)
            self.assertFalse(opsdroid.skills)
Exemplo n.º 2
0
    async def test_unload(self):
        with OpsDroid() as opsdroid:
            mock_connector = Connector({})
            mock_connector.disconnect = amock.CoroutineMock()
            opsdroid.connectors = [mock_connector]

            mock_database = Database({})
            mock_database.disconnect = amock.CoroutineMock()
            opsdroid.memory.databases = [mock_database]

            mock_skill = amock.Mock(config={"name": "mockskill"})
            opsdroid.skills = [mock_skill]

            opsdroid.web_server = Web(opsdroid)
            opsdroid.web_server.stop = amock.CoroutineMock()
            mock_web_server = opsdroid.web_server

            opsdroid.cron_task = amock.CoroutineMock()
            opsdroid.cron_task.cancel = amock.CoroutineMock()
            mock_cron_task = opsdroid.cron_task

            await opsdroid.unload()

            self.assertTrue(mock_connector.disconnect.called)
            self.assertTrue(mock_database.disconnect.called)
            self.assertTrue(mock_web_server.stop.called)
            self.assertTrue(opsdroid.web_server is None)
            self.assertTrue(mock_cron_task.cancel.called)
            self.assertTrue(opsdroid.cron_task is None)
            self.assertFalse(opsdroid.connectors)
            self.assertFalse(opsdroid.memory.databases)
            self.assertFalse(opsdroid.skills)
Exemplo n.º 3
0
    async def test_unload(self):
        with OpsDroid() as opsdroid:
            mock_connector = Connector({}, opsdroid=opsdroid)
            mock_connector.disconnect = amock.CoroutineMock()
            opsdroid.connectors = [mock_connector]

            mock_database = Database({})
            mock_database.disconnect = amock.CoroutineMock()
            opsdroid.memory.databases = [mock_database]

            mock_skill = amock.Mock(config={"name": "mockskill"})
            opsdroid.skills = [mock_skill]

            opsdroid.web_server = Web(opsdroid)
            opsdroid.web_server.stop = amock.CoroutineMock()
            mock_web_server = opsdroid.web_server

            opsdroid.cron_task = amock.CoroutineMock()
            opsdroid.cron_task.cancel = amock.CoroutineMock()
            mock_cron_task = opsdroid.cron_task

            async def task():
                await asyncio.sleep(.5)

            t = asyncio.Task(task(), loop=self.loop)

            await opsdroid.unload()

            self.assertTrue(t.cancel())
            self.assertTrue(mock_connector.disconnect.called)
            self.assertTrue(mock_database.disconnect.called)
            self.assertTrue(mock_web_server.stop.called)
            self.assertTrue(opsdroid.web_server is None)
            self.assertTrue(mock_cron_task.cancel.called)
            self.assertTrue(opsdroid.cron_task is None)
            self.assertFalse(opsdroid.connectors)
            self.assertFalse(opsdroid.memory.databases)
            self.assertFalse(opsdroid.skills)
Exemplo n.º 4
0
 def test_init(self):
     config = {"example_item": "test"}
     database = Database(config)
     self.assertEqual("", database.name)
     self.assertEqual("test", database.config["example_item"])
Exemplo n.º 5
0
 async def test_put(self):
     database = Database({})
     with self.assertRaises(NotImplementedError):
         await database.put("test", {})
Exemplo n.º 6
0
 async def test_disconnect(self):
     database = Database({})
     try:
         await database.disconnect()
     except NotImplementedError:
         self.fail("disconnect() raised NotImplementedError unexpectedly!")
Exemplo n.º 7
0
 async def test_connect(self):
     database = Database({})
     with self.assertRaises(NotImplementedError):
         await database.connect()
Exemplo n.º 8
0
 async def test_delete(self):
     database = Database({})
     with self.assertRaises(NotImplementedError):
         await database.delete("test")
Exemplo n.º 9
0
def test_init():
    """Test that the database is initialised properly."""
    config = {"example_item": "test"}
    database = Database(config)
    assert database.name == ""
    assert database.config["example_item"] == "test"
Exemplo n.º 10
0
async def test_delete():
    database = Database({})
    with pytest.raises(NotImplementedError):
        await database.delete("test")
Exemplo n.º 11
0
async def test_put():
    database = Database({})
    with pytest.raises(NotImplementedError):
        await database.put("test", {})
Exemplo n.º 12
0
async def test_connect():
    database = Database({})
    with pytest.raises(NotImplementedError):
        await database.connect()