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
This commit is contained in:
Russell Ballestrini 2025-11-10 16:30:06 -05:00
parent f9ddc4ec03
commit 352c9879c9
2 changed files with 15 additions and 5 deletions

View file

@ -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?"

View file

@ -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"""