first commit

This commit is contained in:
552068321@qq.com
2022-11-04 17:37:08 +08:00
commit 6f7de660aa
192 changed files with 32574 additions and 0 deletions

40
tests/__init__.py Normal file
View File

@ -0,0 +1,40 @@
from flask_sqlalchemy import model
from app.run import app, db
class BaseTest:
mimetype = 'application/json'
headers = {
'Content-Type': mimetype,
'Accept': mimetype
}
@classmethod
def setup_class(cls):
with app.app_context():
db.create_all()
@classmethod
def teardown_class(cls):
with app.app_context():
db.drop_all()
def setup_method(self, method):
pass
def teardown_method(self, method):
exclude_tables = []
models = {
m.__tablename__: m
for m in db.Model._decl_class_registry.values()
if isinstance(m, model.DefaultMeta)
}
tables = db.metadata.sorted_tables
tables.reverse()
with app.app_context():
for table in tables:
if table.name in exclude_tables:
continue
db.session.query(models[table.name]).delete()
db.session.commit()

20
tests/conftest.py Normal file
View File

@ -0,0 +1,20 @@
import pytest
from app.run import app as tapp
@pytest.fixture(scope='session')
def app(request):
ctx = tapp.app_context()
ctx.push()
def teardown():
ctx.pop()
request.addfinalizer(teardown)
return tapp
@pytest.fixture(scope='session')
def client(app, request):
return app.test_client()

10
tests/testSql.py Normal file
View File

@ -0,0 +1,10 @@
import pytest
from app.run import app as tapp
@pytest.fixture(scope='session')
def app(request):
ctx = tapp.app_context()
ctx.push()

8
tests/test_tools.py Normal file
View File

@ -0,0 +1,8 @@
from . import BaseTest
class TestAPIExample(BaseTest):
def test_ping_api(self, client):
resp = client.get('/api/ping')
assert resp.status_code == 200