Ejemplo n.º 1
0
    def init_database(self):
        self.local_database = "/tmp/orator_test_database.db"

        if os.path.exists(self.local_database):
            os.remove(self.local_database)

        self.manager = DatabaseManager({
            "default": "sqlite",
            "sqlite": {
                "driver": "sqlite",
                "database": self.local_database
            },
        })

        with self.manager.transaction():
            try:
                self.manager.statement(
                    "CREATE TABLE `users` ("
                    "id INTEGER PRIMARY KEY NOT NULL, "
                    "name CHAR(50) NOT NULL, "
                    "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, "
                    "updated_at DATETIME DEFAULT CURRENT_TIMESTAMP"
                    ")")
            except Exception:
                pass

        Model.set_connection_resolver(self.manager)

        self.manager.disconnect()
Ejemplo n.º 2
0
 def connection(self):
     return Model.get_connection_resolver().connection()
Ejemplo n.º 3
0
 def tearDownClass(cls):
     Model.unset_connection_resolver()
Ejemplo n.º 4
0
 def setUpClass(cls):
     Model.set_connection_resolver(DatabaseConnectionResolver())
Ejemplo n.º 5
0
 def connection(self):
     return Model.get_connection_resolver().connection()
Ejemplo n.º 6
0
 def tearDownClass(cls):
     Model.unset_connection_resolver()
Ejemplo n.º 7
0
 def setUpClass(cls):
     Model.set_connection_resolver(DatabaseConnectionResolver())