예제 #1
0
 def setUp(self):
     """Before each test, set up a blank database"""
     self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
     flaskr.app.config['TESTING'] = True
     flaskr.init_db()
     flaskr.testing = True
     self.app = flaskr.app.test_client(use_cookies=True)
예제 #2
0
 def setUp(self):
     # SQLite 3 是基于文件系统 用tempfile 创建临时数据库并且初始化
     # mkstemp() 函数 返回一个低级别的文件句柄和一个随机文件名,使用后者作为数据库名。
     self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
     flaskr.app.config['TESTING'] = True
     self.app = flaskr.app.test_client()
     flaskr.init_db()
예제 #3
0
 def setUp(self):
     """Before each test, set up a blank database"""
     self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
     flaskr.app.config['TESTING'] = True
     self.app = flaskr.app.test_client()
     with flaskr.app.app_context():
         flaskr.init_db()
예제 #4
0
 def setUp(self):
     tmk = tempfile.mkstemp()
     print tmk
     self.db_fd, flaskr.app.config['DATABASE'] = tmk
     flaskr.app.config['TESTING'] = True
     self.app = flaskr.app.test_client()
     flaskr.init_db()
예제 #5
0
def app():
    """Create and configure a new app instance for each test."""
    # create the app with common test config
    app = create_app({"TESTING": True, "SQLALCHEMY_DATABASE_URI": "sqlite:///:memory:"})

    # create the database and load test data
    # set _password to pre-generated hashes, since hashing for each test is slow
    with app.app_context():
        init_db()
        user = User(username="******", _password=_user1_pass)
        db.session.add_all(
            (
                user,
                User(username="******", _password=_user2_pass),
                Post(
                    title="test title",
                    body="test\nbody",
                    author=user,
                    created=datetime(2018, 1, 1),
                ),
            )
        )
        db.session.commit()

    yield app
예제 #6
0
 def setUp(self):
     db_fd = tempfile.mkstemp()
     self.db_fd, flaskr.app.config['DATABASE'] = db_fd
     flaskr.app.config['TESTING'] = True
     self.client = flaskr.app.test_client()
     self.app = flaskr.app
     flaskr.init_db()
예제 #7
0
 def setUp(self):
     '''
     创建了一个新的测试客户端并且初始化了一个新的数据库。这个函数将会在每次独立的测试函数运行之前运行。
     '''
     self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
     flaskr.app.config['TESTING'] = True
     self.app = flaskr.app.test_client()
     flaskr.init_db()
예제 #8
0
    def setUp(self):

        self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
        self.app = flaskr.app.test_client()
        
        with flaskr.app.app_context():

            flaskr.init_db()
예제 #9
0
 def setUp(self):
     '''
     setUp() 函数在每个单独的测试函数运行前被调用
     '''
     self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()    #? mkstemp() 函数返回一个低级别的文件句柄和一个随机文件名 ​​,我们使用后者作为数据库名。
     flaskr.app.config['TESTING'] = True 
     self.app = flaskr.app.test_client()   # 创建了一个新的测试客户端
     flaskr.init_db()    # 初始化新的数据库
예제 #10
0
def tempdb():
    """Before each test, set up a blank database"""
    fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
    flaskr.init_db()
    try:
        yield
    finally:
        os.close(fd)
        os.unlink(flaskr.app.config['DATABASE'])
예제 #11
0
	def setUp(self):
		'''
		The mkstemp() function does two things for us:
		it returns a low-level file handle and a random file name, the latter we use as database name.
		'''
		self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()  #create a new database file
		flaskr.app.config['TESTING'] = True
		self.app = flaskr.app.test_client() #create a new test client
		with flaskr.app.app_context():
			flaskr.init_db()
예제 #12
0
 def setUp(self):
     '''
     Creates a new test client and initializes a new database.
     This function is called before each individual test function is run.
     The mkstemp() returns low-level filed handle and a random file name.
     '''
     self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
     flaskr.app.config['TESTING'] = True
     self.app = flaskr.app.test_client()
     flaskr.init_db()
예제 #13
0
	def setUp(self):
		'''Creates a new test_client and initializes a new database
		before each test is run.  Also activates testing config flag
		to true
		'''
		self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp() #returns a low-level handle and random file name
		flaskr.app.testing = True
		self.app = flaskr.app.test_client()
		with flaskr.app.app_context():
			flaskr.init_db()
예제 #14
0
	def setUp(self):
		self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
		flaskr.app.testing = True
		self.app = flaskr.app.test_client()
		with flaskr.app.app_context():
		flaskr.init_db()

	def tearDown(self):
		os.close(self.db_fd)
		os.unlink(flaskr.app.config['DATABASE'])
예제 #15
0
def client():
    db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
    flaskr.app.config['TESTING'] = True
    
    with flaskr.app.test_client() as client:
        with flaskr.app.app_context():
            flaskr.init_db()
        yield client
    
    os.close(db_fd)
    os.unlink(flaskr.app.config['DATABASE'])
예제 #16
0
    def setUp(self):
        '''
		The mkstemp() function does two things for us:
		it returns a low-level file handle and a random file name, the latter we use as database name.
		'''
        self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp(
        )  #create a new database file
        flaskr.app.config['TESTING'] = True
        self.app = flaskr.app.test_client()  #create a new test client
        with flaskr.app.app_context():
            flaskr.init_db()
예제 #17
0
def client():
    fid, dbfile = tempfile.mkstemp(suffix=".db")
    shutil.rmtree("./test/migrations", ignore_errors=True)
    web_app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + dbfile
    web_app.config["TESTING"] = True
    print("Initing...")
    with web_app.test_client() as client:
        with web_app.app_context() as ctx:
            init_db()
        yield client
    os.close(fid)
예제 #18
0
def client(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
예제 #19
0
def client():
    # Mock database
    db_fd, flaskr.app.config["DATABASE"] = tempfile.mkstemp()
    flaskr.app.config["TESTING"] = True

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

    os.close(db_fd)
    os.unlink(flaskr.app.config["DATABASE"])
예제 #20
0
def client(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
예제 #21
0
 def setUp(self):
     '''
     一般にテストフィクスチャ(テストを実行・成功させるための必要な前提・状態の集合)
     の準備のために呼び出されるメソッド
     新しいテクストクライアントを作成、新しいデータベースを初期化
     '''
     # 低レベルなファイルハンドルと、データベース名を返す?
     # mkstempで作ったファイルはユーザーが手動で削除する必要あり
     # mkstemp()の戻りは、ファイル値とファイルの絶対パス
     self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
     self.app = flaskr.app.test_client()
     with flaskr.app.app_context():
         flaskr.init_db()
예제 #22
0
def app():
    """Create and configure a new app instance for each test."""
    # create the app with common test config
    app = create_app({
        "TESTING": True,
        "SQLALCHEMY_DATABASE_URI": "sqlite:///:memory:"
    })

    # create the database and load test data
    # set _password to pre-generated hashes, since hashing for each test is slow
    with app.app_context():
        init_db()
        user = Usuario(username="******", _password=_user1_pass)
        db.session.add_all(
            (user, Usuario(username="******",
                           _password=_user2_pass), Categoria(id=1,
                                                             name="Test")))
        db.session.commit()

    yield app
 def setUp(self):
     self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp() # what does db_fd mean and what is mkstemp()?
     flaskr.app.config['TESTING'] = True
     self.app = flaskr.app.test_client()
     flaskr.init_db()
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()
import os

parentdir = os.path.dirname(os.path.abspath(__file__))
os.sys.path.insert(0, parentdir)

import flaskr

with flaskr.app.app_context():
            flaskr.init_db()
def before_feature(context, feature):
    app.config['TESTING'] = True
    context.db, app.config['DATABASE_PATH'] = tempfile.mkstemp()
    context.client = app.test_client()
    init_db()
예제 #27
0
 def setUp(self):
     """Before each test, set up a blank database"""
     self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
     flaskr.app.config['TESTING'] = True
     self.app = flaskr.app.test_client()
     flaskr.init_db()
예제 #28
0
 def setUp(self):
     self.db_fd, flaskr.app.config["DATABASE"] = tempfile.mkstemp()
     flaskr.app.config["TESTING"] = True
     self.app = flaskr.app.test_client()
     flaskr.init_db()
예제 #29
0
 def setUp(self):
     """Before each test, set up a blank database"""
     self.db = tempfile.NamedTemporaryFile()
     self.app = flaskr.app.test_client()
     flaskr.DATABASE = self.db.name
     flaskr.init_db()
예제 #30
0
from flaskr import init_db; init_db()
예제 #31
0
    def arrange(cls):
        cls._db_fd, cls._db_path = tempfile.mkstemp()

        flaskr.init_db()
        cls.app = flaskr.app.test_client()
예제 #32
0
# -*- coding: utf-8 -*-
from flaskr import init_db
print init_db()
예제 #33
0
def before_feature(context, feature):
    # test the mock-up application
    app.config['TESTING'] = True
    context.db, app.config['DATABASE'] = tempfile.mkstemp()
    context.client = app.test_client()
    init_db()
예제 #34
0
 def setUp(self):
     self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
     flaskr.app.config['TESTING'] = True
     flaskr.init_db()
     self.app = flaskr.app.test_client(use_cookies=True)
 def setUp(self):
     self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
     EventService.app.config['TESTING'] = True
     self.app = EventService.app.test_client()
     flaskr.init_db()
예제 #36
0
 def setUp(self):
     """Before each test, set up a blank database"""
     self.db_fd, flaskr.DATABASE = tempfile.mkstemp()
     self.app = flaskr.app.test_client()
     flaskr.init_db()
예제 #37
0
 def setUp(self):
     print("1")
     self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
     self.app = flaskr.app.test_client()
     flaskr.init_db()
예제 #38
0
    def arrange(cls):
        cls._db_fd, cls._db_path = tempfile.mkstemp()

        flaskr.init_db()
        cls.app = flaskr.app.test_client()
예제 #39
0
# Flask tutorial: Stylesheet does not work
>>> from flaskr import init_db; init_db()
예제 #40
0
 def setUp(self):
     self.db_fd, self.db_file = tempfile.mkstemp()
     flaskr.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + self.db_file
     flaskr.app.config['TESTING'] = True
     self.app = flaskr.app.test_client()
     flaskr.init_db()
예제 #41
0
 def setUp(self):
     self.app_context = flaskr.app.app_context()
     self.app_context.push()
     self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
     self.app = flaskr.app.test_client()
     flaskr.init_db()
예제 #42
0
 def setUp(self):  # создает клиента тестирования и базу данных
     self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
     #flaskr.app.config['TESTING'] = True
     self.app = flaskr.app.test_client()
     flaskr.init_db()
예제 #43
0
 def setUp(self):
     """Before each test, set up a blank database"""
     self.db_fd, flaskr.app.config["DATABASE"] = tempfile.mkstemp()
     flaskr.app.config["TESTING"] = True
     self.app = flaskr.app.test_client()
     flaskr.init_db(flaskr.app)
예제 #44
0
파일: runserver.py 프로젝트: sindhus/flaskr
from flaskr import init_db, app
from sqlite3 import OperationalError
import config

if __name__ == '__main__':
    try:
        init_db()
    except OperationalError:
        print "DB exists! continuing to run app on ", config.DevelopmentConfig.SERVER_NAME
    app.run('0.0.0.0')
예제 #45
0
 def setUp(self):
     """Before each test, set up a blank database"""
     self.db_fd, flaskr.DATABASE = tempfile.mkstemp()
     self.app = flaskr.app.test_client()
     flaskr.init_db()
예제 #46
0
 def setUp(self):
     self.db_fd, flaskr.DATABASE = tempfile.mkstemp()
     self.app = flaskr.app.test_client()
     flaskr.init_db()
예제 #47
0
 def setUp(self):
     """Set up a blank temp database before each test"""
     self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
     flaskr.app.config['TESTING'] = True
     self.app = flaskr.app.test_client()
     flaskr.init_db()
예제 #48
0
def before_feature(context, feature):
    app.config['TESTING'] = True
    context.db, app.config['DATABASE'] = tempfile.mkstemp()
    context.client = app.test_client()
    init_db()
예제 #49
0
import os

parentdir = os.path.dirname(os.path.abspath(__file__))
os.sys.path.insert(0, parentdir)

import flaskr

with flaskr.app.app_context():
    flaskr.init_db()
예제 #50
0
 def setUp(self):
     print("1")
     self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
     self.app = flaskr.app.test_client()
     flaskr.init_db()
 def setUp(self):
     self.db_fd, flaskr.DATABASE = tempfile.mkstemp()
     self.app = flaskr.app.test_client()
     flaskr.init_db()