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)
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)
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)