Exemple #1
0
    def prepare_database(cls):
        with DatabaseManager() as m:
            m.drop_database()
            m.create_database()

        cls.engine = create_engine()
        cls.session = session = session_factory(bind=cls.engine,
                                                expire_on_commit=False)
        setup_schema(session)
        session.commit()
Exemple #2
0
 def launch(self):
     with DatabaseManager() as db_admin:
         if self.args.drop_db:
             db_admin.drop_database()
         db_admin.create_database()
         if self.args.schema or self.args.basedata or self.args.mockup:
             setup_schema()
             if self.args.basedata:
                 self.args.application.insert_basedata()
             if self.args.mockup:
                 self.args.application.insert_mockup()
Exemple #3
0
    def __call__(self, args):
        with DBManager() as db_admin:
            if args.drop_db:
                db_admin.drop_database()

            db_admin.create_database()
            if args.schema or args.basedata or args.mockup:
                setup_schema()
                if args.basedata:
                    args.application.insert_basedata()

                if args.mockup:
                    args.application.insert_mockup()
Exemple #4
0
    def __call__(self, args=None):
        if args.version:
            print(__version__)
            return

        self.application = MockupApplication()
        self.application.configure(filename=args.config_file)
        #if exists(db):
        #    os.remove(db)
        # makedirs(settings.data_directory, exist_ok=True)
        self.application.initialize_orm()
        setup_schema()
        DBSession.execute('TRUNCATE TABLE resource')
        DBSession.commit()
        print(f'DB {DBSession.bind}')
        self.application.insert_mockup()
        host, port = args.bind.split(':') if ':' in args.bind else (
            'localhost', args.bind)
        httpd = make_server(host, int(port), self.application)

        url = 'http://%s:%d' % httpd.server_address
        print(
            f'The server is up!, Get {url} to more info about how to use it!')
        server_thread = threading.Thread(target=httpd.serve_forever,
                                         daemon=True)
        try:
            server_thread.start()

            if not args.command:
                server_thread.join()
                exitstatus = 0
            else:
                test_runner_command = ' '.join(args.command).replace(
                    '{url}', url)
                time.sleep(1)
                result = run(test_runner_command, shell=True)
                exitstatus = result.returncode
            return exitstatus
        except KeyboardInterrupt:
            print('CTRL+X is pressed.')
            return 1
        finally:
            httpd.shutdown()
            sys.exit(exitstatus)
Exemple #5
0
    def launch(self):
        if self.args.version:
            print(__version__)
            return

        self.application = MockupApplication()
        self.application.configure(files=self.args.config_file)
        if exists(db):
            remove(db)
        # makedirs(settings.data_directory, exist_ok=True)
        self.application.initialize_models()
        setup_schema()
        # DBSession.commit()
        print(f'DB {DBSession.bind}')
        self.application.insert_mockup()
        host, port = self.args.bind.split(':') if ':' in self.args.bind else (
            'localhost', self.args.bind)
        httpd = make_server(host, int(port), self.application)

        url = 'http://%s:%d' % httpd.server_address
        print(
            f'The server is up!, Get {url} to more info about how to use it!')
        server_thread = threading.Thread(target=httpd.serve_forever,
                                         daemon=True)
        try:
            server_thread.start()

            if not self.args.command:
                server_thread.join()
            else:
                test_runner_command = ' '.join(self.args.command).replace(
                    '{url}', url)
                time.sleep(1)
                run(test_runner_command, shell=True)
            return 0
        except KeyboardInterrupt:
            print('CTRL+X is pressed.')
            return 1
        finally:
            httpd.shutdown()
            server_thread.join()
Exemple #6
0
 def setUpClass(cls):
     configure(init_value=cls.__configuration__, force=True)
     cls.engine = create_engine()
     init_model(cls.engine)
     setup_schema()
Exemple #7
0
 def __call__(self, args):
     setup_schema()
Exemple #8
0
 def launch(self):
     setup_schema()
Exemple #9
0
from stemerald.models import Client, Cryptocurrency
from stemerald.models.fund import Fund
from restfulpy.db import DatabaseManager
from restfulpy.orm import DBSession, session_factory, setup_schema, create_engine

app = stemerald.stemerald
app.configure()
# app.initialize_models()

with DatabaseManager() as m:
    m.drop_database()
    m.create_database()

engine = create_engine()
session = session_factory(bind=engine, expire_on_commit=True)
setup_schema(session)
session.commit()
session.close()

session0 = session_factory(bind=engine, expire_on_commit=True)

client1 = Client()
client1.email = '*****@*****.**'
client1.password = '******'
client1.is_active = True
session0.add(client1)

fund1 = Fund(currency=Cryptocurrency(name='a', code='b'), client=client1)

fund2 = Fund(currency=Cryptocurrency(name='c', code='d'), client=client1)