企业微信
This commit is contained in:
1 parent
46ac70f4c5
commit
a9fc852abb
33 files changed
+4875
-106
No files matched your search
@@ -1,9 +1,26 @@
|
||||
import pytest
|
||||
from app import create_app, db
|
||||
from app.models import User
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _isolate_persisted_settings(monkeypatch, tmp_path):
|
||||
"""Prevent tests from inheriting the developer's local ``backend/.env``.
|
||||
|
||||
``apply_env_settings`` is called eagerly in ``create_app`` and on every
|
||||
request via the ``before_request`` hook. If the dev's real ``backend/.env``
|
||||
contains ``WECOM_AUTO_CREATE_USER=true`` (or any other WECOM_* override),
|
||||
those values would silently overwrite the explicit ``app.config.update(...)``
|
||||
calls inside test fixtures. Routing reads to a tmp path makes every test
|
||||
start from a clean slate.
|
||||
"""
|
||||
from app import env_persistence
|
||||
|
||||
monkeypatch.setattr(env_persistence, 'BACKEND_ENV_PATH', tmp_path / 'isolated.env')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app():
|
||||
from app import create_app, db
|
||||
|
||||
app = create_app('testing')
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
@@ -11,10 +28,12 @@ def app():
|
||||
db.session.remove()
|
||||
db.drop_all()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(app):
|
||||
return app.test_client()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin_headers():
|
||||
return {
|
||||
@@ -23,6 +42,7 @@ def admin_headers():
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user_headers():
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user