|
|
@ -17,33 +17,25 @@ from flaskr.blueprints.flaskr import init_db |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture |
|
|
|
@pytest.fixture |
|
|
|
def app(request): |
|
|
|
def app(): |
|
|
|
|
|
|
|
db_fd, db_path = tempfile.mkstemp() |
|
|
|
db_fd, temp_db_location = tempfile.mkstemp() |
|
|
|
|
|
|
|
config = { |
|
|
|
config = { |
|
|
|
'DATABASE': temp_db_location, |
|
|
|
'DATABASE': db_path, |
|
|
|
'TESTING': True, |
|
|
|
'TESTING': True, |
|
|
|
'DB_FD': db_fd |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
app = create_app(config=config) |
|
|
|
app = create_app(config=config) |
|
|
|
|
|
|
|
|
|
|
|
with app.app_context(): |
|
|
|
with app.app_context(): |
|
|
|
init_db() |
|
|
|
init_db() |
|
|
|
yield app |
|
|
|
yield app |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
os.close(db_fd) |
|
|
|
|
|
|
|
os.unlink(db_path) |
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture |
|
|
|
|
|
|
|
def client(request, app): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client = app.test_client() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def teardown(): |
|
|
|
|
|
|
|
os.close(app.config['DB_FD']) |
|
|
|
|
|
|
|
os.unlink(app.config['DATABASE']) |
|
|
|
|
|
|
|
request.addfinalizer(teardown) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return client |
|
|
|
@pytest.fixture |
|
|
|
|
|
|
|
def client(app): |
|
|
|
|
|
|
|
return app.test_client() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def login(client, username, password): |
|
|
|
def login(client, username, password): |
|
|
|