mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-15 22:06:52 +08:00
Initial commit
This commit is contained in:
50
api/tests/conftest.py
Normal file
50
api/tests/conftest.py
Normal file
@@ -0,0 +1,50 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
import pytest
|
||||
import flask_migrate
|
||||
|
||||
from app import create_app
|
||||
from extensions.ext_database import db
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def test_client():
|
||||
# Create a Flask app configured for testing
|
||||
from config import TestConfig
|
||||
flask_app = create_app(TestConfig())
|
||||
flask_app.config.from_object('config.TestingConfig')
|
||||
|
||||
# Create a test client using the Flask application configured for testing
|
||||
with flask_app.test_client() as testing_client:
|
||||
# Establish an application context
|
||||
with flask_app.app_context():
|
||||
yield testing_client # this is where the testing happens!
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def init_database(test_client):
|
||||
# Initialize the database
|
||||
with test_client.application.app_context():
|
||||
flask_migrate.upgrade()
|
||||
|
||||
yield # this is where the testing happens!
|
||||
|
||||
# Clean up the database
|
||||
with test_client.application.app_context():
|
||||
flask_migrate.downgrade()
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def db_session(test_client):
|
||||
with test_client.application.app_context():
|
||||
yield db.session
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def login_default_user(test_client):
|
||||
|
||||
# todo
|
||||
|
||||
yield # this is where the testing happens!
|
||||
|
||||
test_client.get('/logout', follow_redirects=True)
|
||||
Reference in New Issue
Block a user