first commit
This commit is contained in:
40
tests/__init__.py
Normal file
40
tests/__init__.py
Normal 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
20
tests/conftest.py
Normal 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
10
tests/testSql.py
Normal 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
8
tests/test_tools.py
Normal 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
|
Reference in New Issue
Block a user