2019-10-25 14:32:23 +08:00
|
|
|
import os
|
2019-10-21 16:21:32 +08:00
|
|
|
import logging
|
|
|
|
import pytest
|
|
|
|
import grpc
|
2019-10-25 14:32:23 +08:00
|
|
|
import tempfile
|
|
|
|
import shutil
|
2019-10-21 16:21:32 +08:00
|
|
|
from mishards import settings, db, create_app
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2019-10-25 14:32:23 +08:00
|
|
|
tpath = tempfile.mkdtemp()
|
|
|
|
dirpath = '{}/db'.format(tpath)
|
|
|
|
filepath = '{}/meta.sqlite'.format(dirpath)
|
|
|
|
os.makedirs(dirpath, 0o777)
|
|
|
|
settings.TestingConfig.SQLALCHEMY_DATABASE_URI = 'sqlite:///{}?check_same_thread=False'.format(
|
|
|
|
filepath)
|
2019-10-21 16:21:32 +08:00
|
|
|
|
2019-10-25 14:32:23 +08:00
|
|
|
|
2019-10-21 16:21:32 +08:00
|
|
|
@pytest.fixture
|
|
|
|
def app(request):
|
|
|
|
app = create_app(settings.TestingConfig)
|
|
|
|
db.drop_all()
|
|
|
|
db.create_all()
|
|
|
|
|
|
|
|
yield app
|
|
|
|
|
|
|
|
db.drop_all()
|
2019-10-25 20:39:44 +08:00
|
|
|
app.stop()
|
2019-10-25 14:32:23 +08:00
|
|
|
# shutil.rmtree(tpath)
|
2019-10-21 16:21:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def started_app(app):
|
|
|
|
app.on_pre_run()
|
|
|
|
app.start(settings.SERVER_TEST_PORT)
|
|
|
|
|
|
|
|
yield app
|
|
|
|
|
|
|
|
app.stop()
|