Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

tests: enable internal sharing explicitly in the archive and review-fix tests; they passed only because the dev .env enables it, and CI has no .env

Murtaza Nasir7ad982d4a2cd
diff --git a/tests/test_archive_and_audio_removal.py b/tests/test_archive_and_audio_removal.py
index 5762796a..99aa9f17 100644
--- a/tests/test_archive_and_audio_removal.py
+++ b/tests/test_archive_and_audio_removal.py
@@ -9,6 +9,7 @@ SHARED-DB: assertions are scoped to the recordings each test creates.
"""
import json
+from contextlib import ExitStack
import os
import sys
import uuid
@@ -27,6 +28,19 @@ from src.models.sharing import InternalShare, SharedRecordingState
app.config["WTF_CSRF_ENABLED"] = False
+def _internal_sharing_on():
+ """Enable internal sharing for the test, whatever the environment says.
+
+ Each module copies ENABLE_INTERNAL_SHARING at import time; CI has no .env,
+ so sharing is off there unless the tests switch it on in every copy.
+ """
+ stack = ExitStack()
+ for name, module in list(sys.modules.items()):
+ if name.startswith("src") and module is not None and hasattr(module, "ENABLE_INTERNAL_SHARING"):
+ stack.enter_context(patch.object(module, "ENABLE_INTERNAL_SHARING", True))
+ return stack
+
+
_created = []
@@ -34,7 +48,7 @@ _created = []
def ctx():
"""App context, and removal of every recording the test created: later
files (test_cov_admin) assume no eligible completed recordings exist."""
- with app.app_context():
+ with app.app_context(), _internal_sharing_on():
yield
db.session.rollback()
for rec_id in _created:
diff --git a/tests/test_review_fixes.py b/tests/test_review_fixes.py
index 34dfb93c..98102ce8 100644
--- a/tests/test_review_fixes.py
+++ b/tests/test_review_fixes.py
@@ -13,6 +13,7 @@ SHARED-DB: every test uses its own users and removes its recordings.
"""
import json
+from contextlib import ExitStack
import os
import sys
import uuid
@@ -32,6 +33,19 @@ from src.services import voice_profiles as vp
from src.services.recording_state import parse_archived_flag
app.config["WTF_CSRF_ENABLED"] = False
+
+
+def _internal_sharing_on():
+ """Enable internal sharing for the test, whatever the environment says.
+
+ Each module copies ENABLE_INTERNAL_SHARING at import time; CI has no .env,
+ so sharing is off there unless the tests switch it on in every copy.
+ """
+ stack = ExitStack()
+ for name, module in list(sys.modules.items()):
+ if name.startswith("src") and module is not None and hasattr(module, "ENABLE_INTERNAL_SHARING"):
+ stack.enter_context(patch.object(module, "ENABLE_INTERNAL_SHARING", True))
+ return stack
RNG = np.random.default_rng(11)
DIM = 256
_created = []
@@ -58,7 +72,7 @@ class _Client(FlaskClient):
@pytest.fixture
def ctx():
- with app.app_context():
+ with app.app_context(), _internal_sharing_on():
saved = {k: SystemSetting.get_setting(k, None) for k in (vp.SETTING_CURRENT_SPACE, vp.SETTING_LEGACY_SPACE)}
vp._calibration_cache.clear()
yield