def test_get_or_create_db(self): get_or_create_db("test_db", "sqlite:///superset.db") database = db.session.query(Database).filter_by(database_name="test_db").one() self.assertIsNotNone(database) self.assertEqual(database.sqlalchemy_uri, "sqlite:///superset.db") self.assertIsNotNone( security_manager.find_permission_view_menu("database_access", database.perm) ) # Test change URI get_or_create_db("test_db", "sqlite:///changed.db") database = db.session.query(Database).filter_by(database_name="test_db").one() self.assertEqual(database.sqlalchemy_uri, "sqlite:///changed.db") db.session.delete(database) db.session.commit()
def test_get_or_create_db_invalid_uri(self): with self.assertRaises(DatabaseInvalidError): get_or_create_db("test_db", "yoursql:superset.db/()")
def setUp(self) -> None: self.login(username="******") self._test_db_id = get_or_create_db( "column_test_db", app.config["SQLALCHEMY_DATABASE_URI"]).id self._old_sqla_table_mutator = app.config["SQLA_TABLE_MUTATOR"]
def set_database_uri(database_name: str, uri: str, skip_create: bool) -> None: """Updates a database connection URI""" database_utils.get_or_create_db(database_name, uri, not skip_create)