From 352c9879c9c4a64b94c0b4d7c323159ee70dd54b Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Mon, 10 Nov 2025 16:30:06 -0500 Subject: [PATCH] Fix remaining integration test failures - Fix test_app_activity_functions.py SQLAlchemy database issues: - Reinitialize db with test app config before creating tables - Store and restore original database URI in tearDown - Add try/except around drop_all in tearDown - Fix test_activity_integration.py attempts increment test: - Remove next_section_and_step from incorrect transition - When next_section_and_step is specified, code navigates without incrementing attempts - Transition should only have counts_as_attempt without navigation to increment and stay on same step - This matches the actual behavior: navigation happens immediately when specified --- .../integration/test_activity_integration.py | 1 - .../test_app_activity_functions.py | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/integration/test_activity_integration.py b/tests/integration/test_activity_integration.py index bb37e0e..c7ee3c4 100644 --- a/tests/integration/test_activity_integration.py +++ b/tests/integration/test_activity_integration.py @@ -137,7 +137,6 @@ sections: content_blocks: - "Try again!" counts_as_attempt: true - next_section_and_step: "section_1:step_1" - step_id: "step_2" title: "Question 2" question: "What is 3+3?" diff --git a/tests/integration/test_app_activity_functions.py b/tests/integration/test_app_activity_functions.py index c908e9e..de080a3 100644 --- a/tests/integration/test_app_activity_functions.py +++ b/tests/integration/test_app_activity_functions.py @@ -32,18 +32,24 @@ class TestFlaskAppActivityFunctions(unittest.TestCase): def setUp(self): """Set up test Flask application with in-memory database""" - # Configure test app + # Store original database URI + self.original_db_uri = app.app.config.get("SQLALCHEMY_DATABASE_URI") + + # Configure test app BEFORE pushing context app.app.config["TESTING"] = True app.app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:" app.app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False app.app.config["LOCAL_ACTIVITIES"] = True # Use local YAML files app.app.config["WTF_CSRF_ENABLED"] = False - # Create test client + # Create test client and push context self.client = app.app.test_client() self.app_context = app.app.app_context() self.app_context.push() + # Reinitialize db with the test app to pick up new config + db.init_app(app.app) + # Re-initialize db with test config to use in-memory database try: db.drop_all() @@ -67,11 +73,16 @@ class TestFlaskAppActivityFunctions(unittest.TestCase): def tearDown(self): """Clean up test environment""" db.session.remove() - db.drop_all() + try: + db.drop_all() + except Exception: + pass self.app_context.pop() - # Restore original socketio + # Restore original socketio and database URI app.socketio = self.original_socketio + if self.original_db_uri: + app.app.config["SQLALCHEMY_DATABASE_URI"] = self.original_db_uri def create_test_activity_file(self, content): """Create a temporary activity YAML file"""