Beispiel #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()
Beispiel #2
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()
Beispiel #3
0
class OratorTestCase(TestCase):
    def tearDown(self):
        if hasattr(self, "local_database"):
            os.remove(self.local_database)

        flexmock_teardown()

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

    def assertRegex(self, *args, **kwargs):
        if PY2:
            return self.assertRegexpMatches(*args, **kwargs)
        else:
            return super(OratorTestCase, self).assertRegex(*args, **kwargs)

    def assertNotRegex(self, *args, **kwargs):
        if PY2:
            return self.assertNotRegexpMatches(*args, **kwargs)
        else:
            return super(OratorTestCase, self).assertNotRegex(*args, **kwargs)
Beispiel #4
0
class OratorTestCase(TestCase):

    def tearDown(self):
        if hasattr(self, 'local_database'):
            os.remove(self.local_database)

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

    def assertRegex(self, *args, **kwargs):
        if PY2:
            return self.assertRegexpMatches(*args, **kwargs)
        else:
            return super(OratorTestCase, self).assertRegex(*args, **kwargs)

    def assertNotRegex(self, *args, **kwargs):
        if PY2:
            return self.assertNotRegexpMatches(*args, **kwargs)
        else:
            return super(OratorTestCase, self).assertNotRegex(*args, **kwargs)
Beispiel #5
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()
Beispiel #6
0
    def _get_real_manager(self):
        manager = DatabaseManager({
            'default': 'sqlite',
            'sqlite': {
                'driver': 'sqlite',
                'database': ':memory:'
            }
        })

        return manager
    def _get_real_manager(self):
        manager = DatabaseManager({
            "default": "sqlite",
            "sqlite": {
                "driver": "sqlite",
                "database": ":memory:"
            },
        })

        return manager
Beispiel #8
0
    def __init__(self):
        """
        Initialize the Orator Migrator Class. Check if the migration table has been created. If not, Create the
        Repository
        """
        check, config = self.get_config()
        if not check:
            print("Error Occurred")
        else:
            self.manager = DatabaseManager(config=config)
            self.path = os.path.abspath('.') + "/database/migrations/"
            self.repository = DatabaseMigrationRepository(resolver=self.manager, table='migrations')

            if not self.repository.repository_exists():
                self.repository.create_repository()

            super().__init__(self.repository, self.manager)
Beispiel #9
0
import environs
from orator import Model, SoftDeletes, mutator
from orator.orm import (has_one, has_many, belongs_to, accessor,
                        belongs_to_many, scope, has_many_through,
                        morphed_by_many, morph_to_many)
from orator.database_manager import DatabaseManager

env = environs.Env()
log = logging.getLogger(__name__)

db = DatabaseManager({
    'postgres': {
        'driver': 'postgres',
        'host': env('POSTGRES_HOST'),
        'port': env('POSTGRES_PORT'),
        'database': env('POSTGRES_DB'),
        'user': env('POSTGRES_USER'),
        'password': env('POSTGRES_PASSWORD'),
        'prefix': '',
        'log_queries': True
    }
})
Model.set_connection_resolver(db)


class Trainers(Model):

    __fillable__ = ['name', 'gender', 'rival_name']
    __hidden__ = ['created_at', 'updated_at']
    __appends__ = []
    _with = ['pokemon']
Beispiel #10
0
def get_db():
    config = yaml.load(open("orator.yaml"))
    return DatabaseManager(config["databases"])
Beispiel #11
0
def load_db():
    config = yaml.load(open("orator.yaml"))
    db = DatabaseManager(config["databases"])
    Model.set_connection_resolver(db)
    return db