示例#1
0
def client():
    db_fd, app.app.config['DATABASE_PATH'] = tempfile.mkstemp()
    app.app.config['TESTING'] = True
    client = app.app.test_client()

    with app.app.app_context():
        print(app.app.config['DATABASE_PATH'])
        app.init_db(app.get_db(app.app.config['DATABASE_PATH']))
        # Add some more users
        f = open('users/views/test/test_data_create.sql', 'r')
        sql = f.read()
        f.close()
        cur = app.g.db.cursor()
        cur.executescript(sql)
        # doris and John need passwords
        rec = app.User(app.g.db).get('doris')
        rec.password = getPasswordHash('password')
        app.User(app.g.db).save(rec)
        rec = app.User(app.g.db).get('John')
        rec.password = getPasswordHash('password')
        app.User(app.g.db).save(rec)
        app.g.db.commit()

        rec = app.User(app.g.db).get('doris')
        print(rec)
        rec = app.User(app.g.db).get('John')
        print(rec)

    yield client

    os.close(db_fd)
    os.unlink(app.app.config['DATABASE_PATH'])
示例#2
0
def app():
    app = create_app("testing")

    with app.app_context():
        init_db()

    yield app
示例#3
0
 def setUp(self):
     self.fd, app.config['DATABASE'] = tempfile.mkstemp()
     app.config['TESTING'] = True
     app.config['TORRENTS'] = tempfile.mkdtemp()
     self.app = app.test_client()
     init_db()
     self.client = init_client(putio.Client('123456'))
示例#4
0
 def setUp(self):
     self.fd, app.config['DATABASE'] = tempfile.mkstemp()
     app.config['TESTING'] = True
     app.config['TORRENTS'] = tempfile.mkdtemp()
     self.app = app.test_client()
     init_db()
     self.client = init_client(putio.Client('123456'))
 def setUp(self):
    app.config['DB_FILE'] = test_db_file
    try:
       init_db()
    except sqlite3.Error as e:
       os.remove(test_db_file)
       init_db()
    self.appTest = app.test_client()
示例#6
0
def main():

    init_db()
    updater = init_telegram()
    app = init_app()
    app.register_blueprint(Routes.mod)
    # updater.start_polling()
    app.run(host="0.0.0.0", port=8080, debug=False)
示例#7
0
 def setup_method(self, foo):
     self.db_fd, app.config['DATABASE'] = tempfile.mkstemp()
     self.app = app.test_client()
     init_db()
     u = User('good',
              'valid_email@good_domain.org',
              'http://good.good_domain.org')
     db.session.add(u)
示例#8
0
    def setUp(self):
        """Deploy the test DB (sqlite).

        """

        self.db_handle, app.app.config['DATABASE'] = tempfile.mkstemp()
        self.app = app.app.test_client()
        with app.app.app_context():
           app.init_db()  # nope
示例#9
0
def app():
    app = create_app({
        "TESTING": True,
        "SQLALCHEMY_DATABASE_URI": "sqlite:///:memory:"
    })

    with app.app_context():
        init_db()

    yield app
示例#10
0
 def setUp(self):
     """creates a new test client, initialize a database"""
     self.__username = app.config['USERNAME']
     self.__password = app.config['PASSWORD']
     # mkstemp() - create temporary db
     #   returns(tuple): os-level file hanlde and its absolute pathname
     self.db_fd, app.config['DATABASE_URI'] = tempfile.mkstemp()
     app.config['TESTING'] = True
     self.app = app.test_client()
     init_db()
示例#11
0
    def setUp(self):
        app.app.config['TESTING'] = True
        app.app.config["MONGODB_DB"] = 'dfkm'
        connect(config.MONGO_DBNAME,
                host=config.MONGO_HOST,
                port=config.MONGO_PORT)
        self.app = app.app.test_client()
        self.name = app.app.name

        # Setup the database (index build, etc)
        app.init_db()
示例#12
0
def client():
	db_fd, app.config["DATABASE"] = tempfile.mkstemp()
	app.config["TESTING"] = True
	client = app.test_client()

	with app.app_context():
		init_db()
	yield client

	os.close(db_fd)
	os.unlink(app.config["DATABASE"])
示例#13
0
def app():
    """Create and configure a new app instance for each test."""

    # create the app with common test config
    app = create_app(environment='testing')

    # create the database and load test data
    with app.app_context():
        init_db()

    yield app
示例#14
0
    def setUp(self):
        self.app = create_app('testing')
        self.app.config['WTF_CSRF_ENABLED'] = False
        self.client = self.app.test_client()
        self.app_context = self.app.app_context()
        self.app_context.push()

        # initialize database and add a user
        init_db()
        u = User(nickname="admin", email="*****@*****.**", password="******")
        db.session.add(u)
        db.session.commit()
示例#15
0
def tester_db(request):
    db_fd, app.config['DATABASE'] = tempfile.mkstemp()
    app.config['TESTING'] = True
    tester = app.test_client()
    init_db()

    def tester_db_teardown():
        os.close(db_fd)
        os.unlink(app.config['DATABASE'])

    request.addfinalizer(tester_db_teardown())
    return tester
示例#16
0
def original(request):
	db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
	flaskr.app.config['TESTING'] = True
	client = flaskr.app.test_client()
	with flaskr.app.app_context():
		flaskr.init_db()

	def teardown():
		os.close(db_fd)
		os.unlink(flaskr.app.config['DATABASE'])
	request.addfinalizer(teardown)
	return client
示例#17
0
def client():
    fd, caminho = tempfile.mkstemp()
    app.config['ARQUIVO_BD'] = caminho
    app.config['TESTING'] = True

    with app.test_client() as client:
        with app.app_context():
            init_db()
        yield client

    os.close(fd)
    os.unlink(caminho)
示例#18
0
    def setUp(self):
        app.app.config.from_object("testing_config")
        self.app = app.app.test_client()

        with app.app.app_context():
            # Reinitialize the db connection with testing values.
            app.db = app.get_db()
            app.init_db()

            # Register and log in a test user.
            self.register()
            self.login()
示例#19
0
文件: test_app.py 项目: mfix22/arlo
def client():
    app.app.config['TESTING'] = True
    client = app.app.test_client()

    with app.app.app_context():
        app.init_db()

    yield client

    # clear database between test runs
    app.db.drop_all()
    app.db.create_all()
示例#20
0
def client():
    app = app.create_app()
    db_fd, app.config['DATABASE'] = tempfile.mkstemp()
    app.config['TESTING'] = True

    with app.test_client() as client:
        with app.app_context():
            app.init_db()
        yield client

    os.close(db_fd)
    os.unlink(app.config['DATABASE'])
示例#21
0
    def setUp(self):
        self.student = User("user", "password", 1)
        self.lecture = LectureTopic(1, "L1", "author", "Lecture", "info")
        self.comment = Comment(1, "author", "info", 2, self.lecture.getLTid())
        self.subscribe = Subscription(1, self.lecture.getLTid(),
                                      self.student.getUid())
        self.notify = Notification(1, self.subscribe.getSid())

        self.db_fd, app.app.config['DATABASE'] = tempfile.mkstemp()
        app.app.testing = True
        self.app = app.app.test_client()
        with app.app.app_context():
            app.init_db()
示例#22
0
    def setUp(self):
        """Set up a blank test database before each test"""
        self.db_name = name_from_uri(os.environ['TEST_DATABASE_URL'])
        app.app.config.update(
            TESTING=True,
            SQLALCHEMY_DATABASE_URI=os.environ['TEST_DATABASE_URL']

        )
        upgrade(directory='migrations')

        self.app = app.app.test_client()
        app.init_db(self.db_name)
        self.cursor = app.connect_db()
示例#23
0
    def setUp(self):
        self.app = create_app()

        self.app.config['TESTING'] = True
        self.app.config['WTF_CSRF_ENABLED'] = False

        self.fd, self.filename = tempfile.mkstemp()
        os.write(self.fd, content)

        self.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + self.filename
        init_db(self.app)

        self.client = self.app.test_client()
示例#24
0
def app():
    app = create_app({
        "TESTING": True,
        "SQLALCHEMY_DATABASE_URI": "sqlite:///:memory:"
    })

    with app.app_context():
        init_db()
        user = User(username="******", birthday=date(1962, 3, 7))
        db.session.add(user)
        db.session.commit()

    yield app
示例#25
0
def client():
    db_fd, app.app.config['DATABASE'] = tempfile.mkstemp()
    app.app.config['TESTING'] = True
    client = app.app.test_client()

    with app.app.app_context():
        print(app.app.config['DATABASE'])
        app.init_db(app.get_db(app.app.config['DATABASE']))
        print(app.g.db)

    yield client

    os.close(db_fd)
    os.unlink(app.app.config['DATABASE'])
示例#26
0
    def setUp(self):
        self.app = create_app()

        self.app.config['TESTING'] = True
        self.app.config['WTF_CSRF_ENABLED'] = False

        self.fd, self.filename = tempfile.mkstemp()
        os.write(self.fd, content)

        self.app.config[
            'SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + self.filename
        init_db(self.app)

        self.client = self.app.test_client()
示例#27
0
def app():

    db_fd, db_path = tempfile.mkstemp()
    app = create_app(config_test=dict(TESTING=True,
                                      DATABASE=f'sqlite:///{db_path}',
                                      CELERY_ALWAYS_EAGER=True))

    make_celery(app)

    with app.app_context():
        init_db()

    yield app

    os.close(db_fd)
    os.unlink(db_path)
示例#28
0
class TestApp(unittest.TestCase):

	def setUp(self):
		self.db_fd, app.app.config['DATABASE'] = tempfile.mkstemp()
        app.app.config['TESTING'] = True
        self.app = app.app.test_client()
        with app.app.app_context():
            app.init_db()
示例#29
0
    def setUpClass(cls):
        # create application and client
        cls.client = webdriver.Chrome()
        cls.app = create_app('testing')
        cls.app_context = cls.app.app_context()
        cls.app_context.push()

        # supress logging to keep output clean
        logger = logging.getLogger('werkzeug')
        logger.setLevel("ERROR")

        # set up database and a user
        init_db()
        u = User(nickname="admin", email="*****@*****.**", password="******")
        db.session.add(u)
        db.session.commit()

        threading.Thread(target=cls.app.run).start()
示例#30
0
    def setUpClass(cls):
        # create application and client
        cls.client = webdriver.Chrome()
        cls.app = create_app('testing')
        cls.app_context = cls.app.app_context()
        cls.app_context.push()

        # supress logging to keep output clean
        logger = logging.getLogger('werkzeug')
        logger.setLevel("ERROR")

        # set up database and a user
        init_db()
        u = User(nickname="admin", email="*****@*****.**", password="******")
        db.session.add(u)
        db.session.commit()

        threading.Thread(target=cls.app.run).start()
示例#31
0
def create_user(username='******', password='******', email='*****@*****.**',
                active=False):
    app.init_db()

    password = get_password_for_database(password)

    if active:
        sql = CREATE_ACTIVE_USER
    else:
        sql = CREATE_USER

    sql = sql % {
        'username': username,
        'password': password,
        'email': email,
    }

    db = app.connect_db()
    db.executescript(sql)
    db.commit()
示例#32
0
def app():
    """Create and configure a new app instance for each tests."""
    # create a temporary file to isolate the database for each tests
    db_fd, db_path = tempfile.mkstemp()
    # create the app with common tests config
    app = create_app({
        "TESTING": True,
        "SQLALCHEMY_DATABASE_URI": "sqlite:///:memory:",
        "SQLALCHEMY_TRACK_MODIFICATIONS": False,
        'JWT_SECRET_KEY': 'test'
    })

    # create the database and load tests data
    with app.app_context():
        init_db()
        get_db().engine.execute(_data_sql)

    yield app

    # close and remove the temporary database
    os.close(db_fd)
    os.unlink(db_path)
示例#33
0
def bootstrap_tests():
    filename = app.config['BASE_DIR'] + '/data/tests.db'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + filename

    init_db(app)

    create_roles(quiet=True)

    create_network(u'main-network', u'Network', quiet=True)
    create_network(u'other-network', u'Other Network', quiet=True)

    create_gateway(u'main-network', u'main-gateway1', u'Main Gateway #1', quiet=True)
    create_gateway(u'main-network', u'main-gateway2', u'Main Gateway #2', quiet=True)

    create_gateway(u'other-network', u'other-gateway1', u'Other Gateway #1', quiet=True)
    create_gateway(u'other-network', u'other-gateway2', u'Other Gateway #2', quiet=True)

    create_user(u'*****@*****.**', u'admin', u'super-admin', quiet=True)

    create_user(u'*****@*****.**', u'admin', u'network-admin', u'main-network', quiet=True)
    create_user(u'*****@*****.**', u'admin', u'network-admin', u'other-network', quiet=True)

    create_user(u'*****@*****.**', u'admin', u'gateway-admin', u'main-network', u'main-gateway1', quiet=True)
    create_user(u'*****@*****.**', u'admin', u'gateway-admin', u'main-network', u'main-gateway2', quiet=True)

    create_user(u'*****@*****.**', u'admin', u'gateway-admin', u'other-network', u'other-gateway1', quiet=True)
    create_user(u'*****@*****.**', u'admin', u'gateway-admin', u'other-network', u'other-gateway2', quiet=True)

    create_voucher(u'main-gateway1', 60, 'main-1-1', quiet=True)
    create_voucher(u'main-gateway1', 60, 'main-1-2', quiet=True)
    create_voucher(u'main-gateway2', 60, 'main-2-1', quiet=True)
    create_voucher(u'main-gateway2', 60, 'main-2-2', quiet=True)
    create_voucher(u'other-gateway1', 60, 'other-1-1', quiet=True)
    create_voucher(u'other-gateway1', 60, 'other-1-2', quiet=True)
    create_voucher(u'other-gateway2', 60, 'other-2-1', quiet=True)
    create_voucher(u'other-gateway2', 60, 'other-2-2', quiet=True)
示例#34
0
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from app import get_engine, get_db_session, init_db, Base


if __name__ == '__main__':
    engine = get_engine('sqlite:///history.sql')
    init_db(engine, Base)
示例#35
0
#!/usr/bin/env python

from app import init_db
from productInsertionHandler import dbProductSetup
import os

if __name__ == "__main__":

    ans = input("Run Setup? y or n\n")
    if ans == 'y':
        dirs = os.listdir()
        if 'main.db' in dirs:
            print("DB already exists. Please delete and run setup again")
            quit()
        else:
            init_db()
            dbProductSetup()
            print("Complete")
            quit()
示例#36
0
def before_feature(context, feature):
    context.db, app.config['DATABASE'] = tempfile.mkstemp()
    app.testing = True
    context.client = app.test_client()
    with app.app_context():
        init_db()
示例#37
0
# -*- coding: utf-8 -*-

import os
from app import app
from app import init_db

if __name__ == '__main__':
    init_db()  # create database schema
    port = int(os.environ.get("PORT", 8080))
    app.run('0.0.0.0', port=port)
示例#38
0
def before_feature(context, feature):
    app.config['TESTING'] = True
    context.db_file, app.config['DATABASE_FILE'] = tempfile.mkstemp()
    context.client = app.test_client()
    init_db()
    AlexaRequest.is_valid = Mock(return_value=True)
示例#39
0
文件: app-test.py 项目: kwikiel/tdf
 def setUp(self):
     """ Set up a db before each test """
     self.db_fd, app.app.config['DATABASE'] = tempfile.mkstemp()
     app.app.config['TESTING'] = True
     self.app = app.app.test_client()
     app.init_db()
示例#40
0
def init_db():
    global application
    app.init_db(application)
示例#41
0
import app
app.init_db()
示例#42
0
 def setUp(self):
     self.db_fd, app.app.config['DATABASE'] = tempfile.mkstemp()
     app.app.config['TESTING'] = True
     self.app = app.app.test_client()
     app.init_db()
示例#43
0
 def run(self):
     from app import init_db
     init_db()
示例#44
0
 def setUp(self):
     '''Set up a blank temp database before each test'''
     self.db_fd, app.app.config['DATABASE'] = tempfile.mkstemp()
     app.app.config['TESTING'] = True
     self.app = app.app.test_client()
     app.init_db()
示例#45
0
def dbinit(dboption):
    print('init db', dboption)
    init_db(dboption, app)
示例#46
0
 def setUp(self):
     self.db_fd, app.app.config['DATABASE'] = tempfile.mkstemp()
     app.app.config['TESTING'] = True
     self.app = app.app.test_client()
     app.init_db()
示例#47
0
def initdb():
    print "Initializing database"
    init_db()