Skip to content

Commit b07dc54

Browse files
dpgasparclaude
andcommitted
fix: Use mock for app context test to avoid CI issues
Mock has_app_context instead of relying on actual context teardown which behaves differently in CI environment. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ebc0164 commit b07dc54

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

tests/test_security_signals.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -716,31 +716,23 @@ def failing_post_handler(sender, event):
716716
user_created.disconnect(failing_post_handler)
717717

718718

719-
class NoAppContextTestCase(unittest.TestCase):
719+
class NoAppContextTestCase(SecuritySignalsTestCase):
720720
"""Test signal behavior outside app context."""
721721

722722
def test_signals_disabled_without_app_context(self):
723723
"""Test that _signals_enabled returns False outside app context."""
724-
from flask import Flask
725-
from flask_appbuilder import AppBuilder
726-
from flask_appbuilder.utils.legacy import get_sqla_class
727-
728-
app = Flask(__name__)
729-
app.config.from_object("tests.config_api")
730-
app.config["FAB_SECURITY_SIGNALS_ENABLED"] = True
731-
732-
# Create the app within context
733-
with app.app_context():
734-
SQLA = get_sqla_class()
735-
db = SQLA(app)
736-
appbuilder = AppBuilder(app, db.session)
737-
sm = appbuilder.sm
738-
739-
# Within context, signals should be enabled
740-
self.assertTrue(sm._signals_enabled())
741-
742-
# Outside context, signals should be disabled
743-
self.assertFalse(sm._signals_enabled())
724+
from unittest.mock import patch
725+
726+
sm = self.appbuilder.sm
727+
728+
# Within context, signals should be enabled
729+
self.assertTrue(sm._signals_enabled())
730+
731+
# Mock has_app_context to return False
732+
with patch(
733+
"flask_appbuilder.security.sqla.manager.has_app_context", return_value=False
734+
):
735+
self.assertFalse(sm._signals_enabled())
744736

745737

746738
class TriggeredByUserTestCase(SecuritySignalsTestCase):

0 commit comments

Comments
 (0)