async def test_connect(self): """Test database connection. This method will test the database connection of sqlite database. As the database is created `opsdroid` table is created first. """ database = DatabaseSqlite({"file": "sqlite.db"}) opsdroid = amock.CoroutineMock() opsdroid.eventloop = self.loop try: await database.connect() except NotImplementedError: raise Exception else: self.assertEqual("opsdroid", database.table) self.assertEqual("Connection", type(database.client).__name__)
async def test_connect(): """Test database connection. This method will test the database connection of sqlite database. As the database is created `opsdroid` table is created first. """ database = DatabaseSqlite({"path": "sqlite.db"}) opsdroid = amock.CoroutineMock() opsdroid.eventloop = asyncio.new_event_loop() try: await database.connect() table = database.table client = type(database.client).__name__ await database.disconnect() except NotImplementedError: raise Exception else: assert table == "opsdroid" assert client == "Connection"
async def test_get_and_put(self): """Test get and put functions of database This method will test the get and put functions which help to read and write data from the database. The function `put` a value with key and asserts the same value after the `get` operation is completed. """ database = DatabaseSqlite({"file": "sqlite.db"}) opsdroid = amock.CoroutineMock() opsdroid.eventloop = self.loop try: await database.connect() await database.put("hello", {}) data = await database.get("hello") except NotImplementedError: raise Exception else: self.assertEqual("opsdroid", database.table) self.assertEqual({}, data) self.assertEqual("Connection", type(database.client).__name__)
async def test_deprecated_path(caplog): database = DatabaseSqlite({"file": "sqlite.db"}) assert database.db_file == "sqlite.db" assert "The option 'file' is deprecated, please use 'path' instead." in caplog.text
async def test_deprecated_path(self): database = DatabaseSqlite({"file": "sqlite.db"}) assert database.db_file == "sqlite.db"