Skip to content

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

Python

Tests: the whole suite passes on PostgreSQL, and CI runs it there

Murtaza Nasirb8779a14812c
diff --git a/.forgejo/workflows/test.yml b/.forgejo/workflows/test.yml
index 08fb9937..3e5c102a 100644
--- a/.forgejo/workflows/test.yml
+++ b/.forgejo/workflows/test.yml
@@ -7,7 +7,8 @@ name: Tests
# Syntax is standard GitHub Actions. runs-on: ubuntu-latest is mapped by the
# Forgejo runner to a real container image (see the runner's labels config).
# The Python suite isolates itself to a throwaway SQLite DB via conftest.py;
-# test_postgres_migrations.py uses the postgres service below.
+# test_postgres_migrations.py uses the postgres service below, and
+# python-tests-postgres runs the whole suite on PostgreSQL.
on:
push:
@@ -56,6 +57,48 @@ jobs:
TEST_DATABASE_URI: postgresql://speakr:speakr@postgres:5432/speakr_test
run: pytest tests/ -q --cov=src --cov-report=term-missing --cov-fail-under=60
+ # The same suite on PostgreSQL, the database of most deployments. SQLite
+ # does not enforce column lengths or foreign keys the way PostgreSQL does,
+ # so a test (or a code path) that only works on SQLite fails here.
+ python-tests-postgres:
+ runs-on: ubuntu-latest
+
+ services:
+ postgres:
+ image: postgres:16
+ env:
+ POSTGRES_USER: speakr
+ POSTGRES_PASSWORD: speakr
+ POSTGRES_DB: speakr_suite
+ options: >-
+ --health-cmd "pg_isready -U speakr"
+ --health-interval 10s
+ --health-timeout 5s
+ --health-retries 5
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
+ - name: Set up Python
+ uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
+ with:
+ python-version: '3.11'
+ cache: pip
+
+ - name: Install ffmpeg (needed by stitch / ffprobe tests)
+ run: sudo apt-get update && sudo apt-get install -y ffmpeg
+
+ - name: Install dependencies
+ run: pip install --require-hashes --no-deps -r requirements.lock && pip install pytest pytest-timeout
+
+ - name: Run test suite on PostgreSQL
+ env:
+ # conftest.py points the app at this database instead of SQLite.
+ # The migration tests read TEST_DATABASE_URI, which is not set
+ # here, so they cannot drop the suite's tables.
+ PYTEST_DATABASE_URI: postgresql://speakr:speakr@postgres:5432/speakr_suite
+ run: pytest tests/ -q -p no:cacheprovider --timeout=120
+
js-tests:
runs-on: ubuntu-latest
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 6720b106..759d0404 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -8,6 +8,7 @@ name: Tests
# Syntax is standard GitHub Actions and also runs on Forgejo Actions
# (Forgejo reads .github/workflows by default). The Python suite isolates
# itself to a throwaway SQLite DB via conftest.py, so it needs no app config.
+# python-tests-postgres runs the same suite on PostgreSQL.
on:
push:
@@ -63,6 +64,53 @@ jobs:
TEST_DATABASE_URI: postgresql://speakr:speakr@localhost:5432/speakr_test
run: pytest tests/ -q --cov=src --cov-report=term-missing --cov-fail-under=60
+ # The same suite on PostgreSQL, the database of most deployments. SQLite
+ # does not enforce column lengths or foreign keys the way PostgreSQL does,
+ # so a test (or a code path) that only works on SQLite fails here.
+ python-tests-postgres:
+ runs-on: ubuntu-latest
+
+ services:
+ postgres:
+ image: postgres:16
+ env:
+ POSTGRES_USER: speakr
+ POSTGRES_PASSWORD: speakr
+ POSTGRES_DB: speakr_suite
+ ports:
+ - 5432:5432
+ options: >-
+ --health-cmd "pg_isready -U speakr"
+ --health-interval 10s
+ --health-timeout 5s
+ --health-retries 5
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
+ - name: Set up Python
+ uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
+ with:
+ python-version: '3.11'
+ cache: pip
+
+ - name: Install ffmpeg (needed by stitch / ffprobe tests)
+ run: sudo apt-get update && sudo apt-get install -y ffmpeg
+
+ - name: Install dependencies
+ run: pip install --require-hashes --no-deps -r requirements.lock && pip install pytest pytest-timeout
+
+ - name: Build the Tailwind stylesheet as the image build does
+ run: scripts/build_css.sh
+
+ - name: Run test suite on PostgreSQL
+ env:
+ # conftest.py points the app at this database instead of SQLite.
+ # The migration tests read TEST_DATABASE_URI, which is not set
+ # here, so they cannot drop the suite's tables.
+ PYTEST_DATABASE_URI: postgresql://speakr:speakr@localhost:5432/speakr_suite
+ run: pytest tests/ -q -p no:cacheprovider --timeout=120
+
# Speakr and whisperx-asr-service set up exactly as their docs describe
# (config/env.whisperx.example; the service's docker-compose.yml plus its
# SETUP_GUIDE .env block), talking over HTTP. The service runs its real code
diff --git a/conftest.py b/conftest.py
index 72230744..f3bf749b 100644
--- a/conftest.py
+++ b/conftest.py
@@ -22,7 +22,12 @@ import tempfile
# connections / app contexts, which an in-memory SQLite DB would not share.
_TEST_DIR = tempfile.mkdtemp(prefix="speakr_pytest_")
_TEST_DB_PATH = os.path.join(_TEST_DIR, "test.db")
-os.environ["SQLALCHEMY_DATABASE_URI"] = f"sqlite:///{_TEST_DB_PATH}"
+# PYTEST_DATABASE_URI runs the suite against another database, such as the
+# PostgreSQL service of the CI job. That database must be empty and is used
+# only by the tests.
+os.environ["SQLALCHEMY_DATABASE_URI"] = (
+ os.environ.get("PYTEST_DATABASE_URI") or f"sqlite:///{_TEST_DB_PATH}"
+)
# The app os.makedirs(UPLOAD_FOLDER) at import time; default is /data/uploads
# which isn't writable in CI / outside Docker. Point it at the temp dir.
diff --git a/tests/test_admin_and_bulk_tag_authz.py b/tests/test_admin_and_bulk_tag_authz.py
index 53e52bae..56b3bf87 100644
--- a/tests/test_admin_and_bulk_tag_authz.py
+++ b/tests/test_admin_and_bulk_tag_authz.py
@@ -21,7 +21,7 @@ app.config['WTF_CSRF_ENABLED'] = False
def _user(prefix):
s = uuid.uuid4().hex[:8]
- u = User(username=f'{prefix}_{s}', email=f'{prefix}_{s}@local.test',
+ u = User(username=f'{prefix[:11]}_{s}', email=f'{prefix}_{s}@local.test',
password=bcrypt.generate_password_hash('Passw0rd!').decode())
db.session.add(u)
db.session.commit()
diff --git a/tests/test_api_v1_batch_tag_authz.py b/tests/test_api_v1_batch_tag_authz.py
index f8243da9..e8580257 100644
--- a/tests/test_api_v1_batch_tag_authz.py
+++ b/tests/test_api_v1_batch_tag_authz.py
@@ -23,7 +23,7 @@ app.config["WTF_CSRF_ENABLED"] = False
def _setup_user(prefix):
suffix = uuid.uuid4().hex[:8]
user = User(
- username=f"{prefix}_{suffix}",
+ username=f"{prefix[:11]}_{suffix}",
email=f"{prefix}_{suffix}@local.test",
password="x",
)
diff --git a/tests/test_api_v1_speakers.py b/tests/test_api_v1_speakers.py
index 853ad639..3c92407c 100644
--- a/tests/test_api_v1_speakers.py
+++ b/tests/test_api_v1_speakers.py
@@ -52,7 +52,7 @@ SAMPLE_EMBEDDINGS = json.dumps({
def _get_or_create_test_user(suffix=""):
"""Get or create a test user. Returns (user, created_bool)."""
- username = f"speaker_test_user{suffix}"
+ username = f"spk_test{suffix}"
user = User.query.filter_by(username=username).first()
created = False
if not user:
diff --git a/tests/test_api_v1_users_me.py b/tests/test_api_v1_users_me.py
index 0c01bbd8..96983080 100644
--- a/tests/test_api_v1_users_me.py
+++ b/tests/test_api_v1_users_me.py
@@ -22,7 +22,7 @@ app.config["WTF_CSRF_ENABLED"] = False
def _setup_user(username_prefix, **overrides):
suffix = uuid.uuid4().hex[:8]
user = User(
- username=f"{username_prefix}_{suffix}",
+ username=f"{username_prefix[:11]}_{suffix}",
email=f"{username_prefix}_{suffix}@local.test",
password="x",
**overrides,
diff --git a/tests/test_asr_voice_recorder_upload.py b/tests/test_asr_voice_recorder_upload.py
index 8fd0f8c5..28a56478 100644
--- a/tests/test_asr_voice_recorder_upload.py
+++ b/tests/test_asr_voice_recorder_upload.py
@@ -45,7 +45,7 @@ class _Storage:
def _user(prefix="asr"):
suffix = uuid.uuid4().hex[:8]
user = User(
- username=f"{prefix}_{suffix}",
+ username=f"{prefix[:11]}_{suffix}",
email=f"{prefix}_{suffix}@local.test",
password="x",
)
diff --git a/tests/test_auto_process_tags.py b/tests/test_auto_process_tags.py
index 68ced4df..a61234e1 100644
--- a/tests/test_auto_process_tags.py
+++ b/tests/test_auto_process_tags.py
@@ -322,7 +322,7 @@ class TestTagAutoProcessAPI(unittest.TestCase):
class TestFileMonitorTagSubdirs(unittest.TestCase):
@classmethod
def tearDownClass(cls):
- _drop_synthetic_users('autotest_monitor_user')
+ _drop_synthetic_users('autotest_monitor')
"""Test file monitor tag subdirectory scanning."""
@@ -332,10 +332,10 @@ class TestFileMonitorTagSubdirs(unittest.TestCase):
self.app_context.push()
self.temp_dir = tempfile.mkdtemp()
- self.user = User.query.filter_by(username='autotest_monitor_user').first()
+ self.user = User.query.filter_by(username='autotest_monitor').first()
if not self.user:
self.user = User(
- username='autotest_monitor_user',
+ username='autotest_monitor',
password='fakehash',
is_admin=True
diff --git a/tests/test_cov_file_monitor.py b/tests/test_cov_file_monitor.py
index b4c91598..1549d756 100644
--- a/tests/test_cov_file_monitor.py
+++ b/tests/test_cov_file_monitor.py
@@ -259,7 +259,7 @@ class TestModeDispatch(unittest.TestCase):
self.ctx = app.app_context()
self.ctx.push()
self.temp_dir = tempfile.mkdtemp()
- self.username = _uniq('cov_fm_dispatch')
+ self.username = _uniq('fm_dispatch')
self.user = User(
username=self.username,
email=f'{self.username}@test.com',
@@ -428,8 +428,8 @@ class TestAdminUserSelection(unittest.TestCase):
self.ctx = app.app_context()
self.ctx.push()
self.temp_dir = tempfile.mkdtemp()
- self.admin_username = _uniq('cov_fm_admin')
- self.normal_username = _uniq('cov_fm_normal')
+ self.admin_username = _uniq('fm_admin')
+ self.normal_username = _uniq('fm_normal')
self.admin = User(
username=self.admin_username,
email=f'{self.admin_username}@test.com',
@@ -495,7 +495,7 @@ class TestProcessFile(unittest.TestCase):
self.ctx.push()
self.temp_dir = tempfile.mkdtemp()
self.staging_dir = tempfile.mkdtemp()
- self.username = _uniq('cov_fm_proc')
+ self.username = _uniq('fm_proc')
self.user = User(
username=self.username,
email=f'{self.username}@test.com',
@@ -873,7 +873,7 @@ class TestModuleHelpers(unittest.TestCase):
# user<id>), plus a tag whose user no longer exists (skip) and one with
# no folder name (skip).
with app.app_context():
- username = _uniq('cov_fm_ensure')
+ username = _uniq('fm_ensure')
user = User(username=username, email=f'{username}@t.com',
password='x', is_admin=True)
db.session.add(user)
diff --git a/tests/test_cov_processing.py b/tests/test_cov_processing.py
index b14a3218..bb45c930 100644
--- a/tests/test_cov_processing.py
+++ b/tests/test_cov_processing.py
@@ -37,7 +37,7 @@ import src.tasks.processing as proc
def _make_user(prefix, **kwargs):
suffix = uuid.uuid4().hex[:8]
user = User(
- username=f"{prefix}_{suffix}",
+ username=f"{prefix[:11]}_{suffix}",
email=f"{prefix}_{suffix}@local.test",
password="placeholder-bcrypt-hash",
**kwargs,
diff --git a/tests/test_cov_recordings_download_authz.py b/tests/test_cov_recordings_download_authz.py
index e9c56442..09486d58 100644
--- a/tests/test_cov_recordings_download_authz.py
+++ b/tests/test_cov_recordings_download_authz.py
@@ -29,7 +29,7 @@ app.config["WTF_CSRF_ENABLED"] = False
def _mk_user(prefix):
s = uuid.uuid4().hex[:8]
- u = User(username=f"{prefix}_{s}", email=f"{prefix}_{s}@example.test", password="x")
+ u = User(username=f"{prefix[:11]}_{s}", email=f"{prefix}_{s}@example.test", password="x")
db.session.add(u)
db.session.commit()
return u
diff --git a/tests/test_cov_recordings_read.py b/tests/test_cov_recordings_read.py
index 84175974..d439e28a 100644
--- a/tests/test_cov_recordings_read.py
+++ b/tests/test_cov_recordings_read.py
@@ -144,7 +144,7 @@ _PREFIX = "covrecread"
def make_user():
- suffix = uuid.uuid4().hex[:10]
+ suffix = uuid.uuid4().hex[:9]
user = User(
username=f"{_PREFIX}_{suffix}",
email=f"{_PREFIX}_{suffix}@test.local",
diff --git a/tests/test_cov_recordings_write.py b/tests/test_cov_recordings_write.py
index 6d55f59a..38f3c395 100644
--- a/tests/test_cov_recordings_write.py
+++ b/tests/test_cov_recordings_write.py
@@ -40,7 +40,7 @@ app.config["WTF_CSRF_ENABLED"] = False
def _mk_user(prefix="up"):
suffix = uuid.uuid4().hex[:8]
user = User(
- username=f"{prefix}_{suffix}",
+ username=f"{prefix[:11]}_{suffix}",
email=f"{prefix}_{suffix}@local.test",
password="x",
)
diff --git a/tests/test_cov_retention.py b/tests/test_cov_retention.py
index cbe7b7f3..ef6657bb 100644
--- a/tests/test_cov_retention.py
+++ b/tests/test_cov_retention.py
@@ -35,6 +35,28 @@ def _make_storage_mock(exists=True):
return storage
+def _wipe_recordings():
+ """Delete every recording and every row that refers to one.
+
+ A bulk delete skips the ORM cascades, and PostgreSQL refuses to delete a
+ recording while rows in other tables (events, shares, chunks...) still
+ refer to it, so those tables are emptied first, children before parents.
+ """
+ tables = {"recording"}
+ while True:
+ more = {
+ t.name for t in db.metadata.sorted_tables
+ if t.name not in tables
+ and any(fk.column.table.name in tables for fk in t.foreign_keys)
+ }
+ if not more:
+ break
+ tables |= more
+ for table in reversed(db.metadata.sorted_tables):
+ if table.name in tables:
+ db.session.execute(table.delete())
+
+
class RetentionTestBase(unittest.TestCase):
def setUp(self):
self.ctx = app.app_context()
@@ -51,8 +73,7 @@ class RetentionTestBase(unittest.TestCase):
# pytest session DB is shared across test files. Wipe any recordings
# left behind by other suites so this class's global stat-counter
# assertions are deterministic regardless of run order.
- RecordingTag.query.delete()
- Recording.query.delete()
+ _wipe_recordings()
db.session.commit()
self._created_recordings = []
self._created_tags = []
diff --git a/tests/test_cov_token_tracking_cache.py b/tests/test_cov_token_tracking_cache.py
index 3aa730e1..acc48cbe 100644
--- a/tests/test_cov_token_tracking_cache.py
+++ b/tests/test_cov_token_tracking_cache.py
@@ -21,7 +21,7 @@ from src.services.token_tracking import token_tracker
@pytest.fixture
def isolated_user():
with app.app_context():
- user = User(username="cache_track_test_user", email="[email protected]")
+ user = User(username="cache_track_user", email="[email protected]")
user.password = "unused"
db.session.add(user)
db.session.commit()
diff --git a/tests/test_csrf_token_bypass_fix.py b/tests/test_csrf_token_bypass_fix.py
index 74f1187e..ac22963e 100644
--- a/tests/test_csrf_token_bypass_fix.py
+++ b/tests/test_csrf_token_bypass_fix.py
@@ -47,7 +47,7 @@ from src.utils.token_auth import hash_token
def _make_user(prefix, **overrides):
suffix = uuid.uuid4().hex[:8]
user = User(
- username=f"{prefix}_{suffix}",
+ username=f"{prefix[:11]}_{suffix}",
email=f"{prefix}_{suffix}@local.test",
password=overrides.pop('password', 'placeholder-bcrypt-hash'),
**overrides,
diff --git a/tests/test_documented_defaults.py b/tests/test_documented_defaults.py
index f5240770..29cc1969 100644
--- a/tests/test_documented_defaults.py
+++ b/tests/test_documented_defaults.py
@@ -217,7 +217,7 @@ def _drain(recording_ids):
def _cleanup(user_ids):
- from src.models import SpeakerVoiceSample, Speaker
+ from src.models import SpeakerVoiceSample, Speaker, TranscriptionUsage
from src.models.upload_join import UploadJoinPart
rec_ids = [r.id for r in Recording.query.filter(Recording.user_id.in_(user_ids)).all()]
if rec_ids:
@@ -227,6 +227,7 @@ def _cleanup(user_ids):
if rec_ids:
Recording.query.filter(Recording.id.in_(rec_ids)).delete(synchronize_session=False)
Speaker.query.filter(Speaker.user_id.in_(user_ids)).delete(synchronize_session=False)
+ TranscriptionUsage.query.filter(TranscriptionUsage.user_id.in_(user_ids)).delete(synchronize_session=False)
User.query.filter(User.id.in_(user_ids)).delete(synchronize_session=False)
db.session.commit()
diff --git a/tests/test_export_filename_template.py b/tests/test_export_filename_template.py
index 13bf374d..a555981a 100644
--- a/tests/test_export_filename_template.py
+++ b/tests/test_export_filename_template.py
@@ -49,7 +49,7 @@ app.config["WTF_CSRF_ENABLED"] = False
def _mk_user(prefix="xf", template=None):
suffix = uuid.uuid4().hex[:8]
user = User(
- username=f"{prefix}_{suffix}",
+ username=f"{prefix[:11]}_{suffix}",
email=f"{prefix}_{suffix}@local.test",
password="x",
export_filename_template=template,
diff --git a/tests/test_folders_groups_authz.py b/tests/test_folders_groups_authz.py
index c4aa3f4a..8f1b82dc 100644
--- a/tests/test_folders_groups_authz.py
+++ b/tests/test_folders_groups_authz.py
@@ -46,7 +46,7 @@ app.config["WTF_CSRF_ENABLED"] = False
def _setup_user(prefix, is_admin=False):
suffix = uuid.uuid4().hex[:8]
user = User(
- username=f"{prefix}_{suffix}",
+ username=f"{prefix[:11]}_{suffix}",
email=f"{prefix}_{suffix}@local.test",
password="x",
is_admin=is_admin,
diff --git a/tests/test_keep_audio_only_e2e.py b/tests/test_keep_audio_only_e2e.py
index a65b8732..b21f8069 100644
--- a/tests/test_keep_audio_only_e2e.py
+++ b/tests/test_keep_audio_only_e2e.py
@@ -26,7 +26,7 @@ app.config["WTF_CSRF_ENABLED"] = False
def _setup_user(prefix):
suffix = uuid.uuid4().hex[:8]
user = User(
- username=f"{prefix}_{suffix}",
+ username=f"{prefix[:11]}_{suffix}",
email=f"{prefix}_{suffix}@local.test",
password="x",
)
diff --git a/tests/test_keep_audio_only_serialization.py b/tests/test_keep_audio_only_serialization.py
index 47f8db2e..30082a89 100644
--- a/tests/test_keep_audio_only_serialization.py
+++ b/tests/test_keep_audio_only_serialization.py
@@ -21,7 +21,7 @@ app.config["WTF_CSRF_ENABLED"] = False
def _setup_user(prefix):
suffix = uuid.uuid4().hex[:8]
user = User(
- username=f"{prefix}_{suffix}",
+ username=f"{prefix[:11]}_{suffix}",
email=f"{prefix}_{suffix}@local.test",
password="x",
)
diff --git a/tests/test_label_urls.py b/tests/test_label_urls.py
index 94d3a93c..5b756d4c 100644
--- a/tests/test_label_urls.py
+++ b/tests/test_label_urls.py
@@ -333,6 +333,9 @@ def teardown_module(module):
for r in Recording.query.filter_by(user_id=u.id).all():
RecordingTag.query.filter_by(recording_id=r.id).delete()
db.session.delete(r)
+ tag_ids = [t.id for t in Tag.query.filter_by(user_id=u.id).all()]
+ if tag_ids:
+ RecordingTag.query.filter(RecordingTag.tag_id.in_(tag_ids)).delete(synchronize_session=False)
Tag.query.filter_by(user_id=u.id).delete()
GroupMembership.query.filter_by(user_id=u.id).delete()
db.session.delete(u)
diff --git a/tests/test_merge_export_features.py b/tests/test_merge_export_features.py
index 1ca0b442..45756682 100644
--- a/tests/test_merge_export_features.py
+++ b/tests/test_merge_export_features.py
@@ -31,7 +31,7 @@ app.config["WTF_CSRF_ENABLED"] = False
def _mk_user(prefix="mx"):
suffix = uuid.uuid4().hex[:8]
- user = User(username=f"{prefix}_{suffix}", email=f"{prefix}_{suffix}@local.test", password="x")
+ user = User(username=f"{prefix[:11]}_{suffix}", email=f"{prefix}_{suffix}@local.test", password="x")
db.session.add(user)
db.session.commit()
return user
diff --git a/tests/test_prefix_cache_prompts.py b/tests/test_prefix_cache_prompts.py
index 6407ce1c..83c3d3ca 100644
--- a/tests/test_prefix_cache_prompts.py
+++ b/tests/test_prefix_cache_prompts.py
@@ -39,10 +39,10 @@ def app_with_recording():
from src.models import User, Recording
with app.app_context():
- user = User.query.filter_by(username="prefix_cache_test_user").first()
+ user = User.query.filter_by(username="prefix_cache_user").first()
created_user = False
if not user:
- user = User(username="prefix_cache_test_user", email="[email protected]")
+ user = User(username="prefix_cache_user", email="[email protected]")
user.password = "unused"
db.session.add(user)
db.session.commit()
diff --git a/tests/test_recording_error_persistence.py b/tests/test_recording_error_persistence.py
index d68eb95c..a7da2f46 100644
--- a/tests/test_recording_error_persistence.py
+++ b/tests/test_recording_error_persistence.py
@@ -23,7 +23,7 @@ from src.models import User, Recording
def _make_user(prefix):
suffix = uuid.uuid4().hex[:8]
user = User(
- username=f"{prefix}_{suffix}",
+ username=f"{prefix[:11]}_{suffix}",
email=f"{prefix}_{suffix}@local.test",
password='placeholder-bcrypt-hash',
)
diff --git a/tests/test_recording_sessions.py b/tests/test_recording_sessions.py
index 66ee171f..bd030977 100644
--- a/tests/test_recording_sessions.py
+++ b/tests/test_recording_sessions.py
@@ -35,7 +35,7 @@ app.config["WTF_CSRF_ENABLED"] = False
def _setup_user(prefix):
suffix = uuid.uuid4().hex[:8]
user = User(
- username=f"{prefix}_{suffix}",
+ username=f"{prefix[:11]}_{suffix}",
email=f"{prefix}_{suffix}@local.test",
password="x",
)
diff --git a/tests/test_reprocess_hotwords.py b/tests/test_reprocess_hotwords.py
index 6260bf81..f0aa0271 100644
--- a/tests/test_reprocess_hotwords.py
+++ b/tests/test_reprocess_hotwords.py
@@ -57,7 +57,7 @@ def setup_recording(*, owner_hotwords=None, owner_prompt=None,
"""Create a user, recording, optional tag, optional folder, and any default values."""
suffix = uuid.uuid4().hex[:10]
user = User(
- username=f"reprocess_test_{suffix}",
+ username=f"reproc_{suffix}",
email=f"reprocess_test_{suffix}@test.local",
password="x", # column is just a hash string; auth isn't exercised in this test
)
@@ -220,7 +220,7 @@ def cleanup_test_users():
user-management screens.
"""
with app.app_context():
- for u in User.query.filter(User.username.like('reprocess_test_%')).all():
+ for u in User.query.filter(User.username.like('reproc_%')).all():
db.session.delete(u)
db.session.commit()
diff --git a/tests/test_security_audit_fixes.py b/tests/test_security_audit_fixes.py
index 4e58e976..1cb8b95f 100644
--- a/tests/test_security_audit_fixes.py
+++ b/tests/test_security_audit_fixes.py
@@ -31,7 +31,7 @@ app.config["WTF_CSRF_ENABLED"] = False
def _make_user(suffix):
- username = f"secfix_{suffix}_{secrets.token_hex(3)}"
+ username = f"sf_{suffix}_{secrets.token_hex(3)}"
user = User(username=username, email=f"{username}@local.test")
db.session.add(user)
db.session.commit()
diff --git a/tests/test_shares_authz.py b/tests/test_shares_authz.py
index cf5a7df4..5c468bf2 100644
--- a/tests/test_shares_authz.py
+++ b/tests/test_shares_authz.py
@@ -80,7 +80,7 @@ def _setup_user(prefix, can_share_publicly=True):
context closes)."""
suffix = uuid.uuid4().hex[:8]
user = User(
- username=f"{prefix}_{suffix}",
+ username=f"{prefix[:11]}_{suffix}",
email=f"{prefix}_{suffix}@local.test",
password="x",
can_share_publicly=can_share_publicly,
diff --git a/tests/test_webhooks.py b/tests/test_webhooks.py
index 1cf1a4ee..e467fc3a 100644
--- a/tests/test_webhooks.py
+++ b/tests/test_webhooks.py
@@ -41,7 +41,7 @@ app.config["WTF_CSRF_ENABLED"] = False
def _make_user(prefix):
suffix = uuid.uuid4().hex[:8]
user = User(
- username=f"{prefix}_{suffix}",
+ username=f"{prefix[:11]}_{suffix}",
email=f"{prefix}_{suffix}@local.test",
password="x",
)