diff --git a/install/sample_db.py b/install/sample_db.py index ec5f0546..012d9c1d 100644 --- a/install/sample_db.py +++ b/install/sample_db.py @@ -7,7 +7,6 @@ sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) - def run(): from database import create_session from mod_auth.models import User @@ -50,8 +49,8 @@ def run(): entries.append(gen_data) regression_test_output = [ - RegressionTestOutput(1, "test1", "srt", "test1.srt"), - RegressionTestOutput(2, "test2", "srt", "test2.srt") + RegressionTestOutput(1, "test1", ".srt", "test1.srt"), + RegressionTestOutput(2, "test2", ".srt", "test2.srt") ] entries.extend(regression_test_output) @@ -63,5 +62,4 @@ def run(): print("Entry already exists!", entry, flush=True) db.rollback() - run() diff --git a/migrations/versions/eb7303e132c0_add_xmltv_regression_test.py b/migrations/versions/eb7303e132c0_add_xmltv_regression_test.py new file mode 100644 index 00000000..38c0c1f1 --- /dev/null +++ b/migrations/versions/eb7303e132c0_add_xmltv_regression_test.py @@ -0,0 +1,99 @@ +"""add_xmltv_regression_test + +Revision ID: eb7303e132c0 +Revises: 7793881905c5 +Create Date: 2026-01-06 21:43:46.009899 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'eb7303e132c0' +down_revision = '7793881905c5' +branch_labels = None +depends_on = None + + +def upgrade(): + conn = op.get_bind() + + # 1. Check if the XMLTV regression test already exists + existing_test = conn.execute( + sa.text( + "SELECT id FROM regression_test " + "WHERE sample_id = 187 AND command = '--xmltv=1 --out=null'" + ) + ).fetchone() + + if existing_test is not None: + # Already present, nothing to do + return + + # 2. Insert regression test + conn.execute( + sa.text( + """ + INSERT INTO regression_test + (sample_id, command, input_type, output_type, expected_rc, active) + VALUES + (187, '--xmltv=1 --out=null', 'file', 'null', 5, 0) + """ + ) + ) + + # 3. Fetch newly created test id + test_id = conn.execute( + sa.text( + "SELECT id FROM regression_test " + "WHERE sample_id = 187 AND command = '--xmltv=1 --out=null'" + ) + ).fetchone()[0] + + # 4. Insert expected XMLTV output (exit-code based validation) + conn.execute( + sa.text( + """ + INSERT INTO regression_test_output + (regression_id, correct, correct_extension, expected_filename, ignore_parse_errors) + VALUES + (:test_id, 'ch29FullTS', '.xml', '', 1) + """ + ), + {"test_id": test_id}, + ) + + + +def downgrade(): + conn = op.get_bind() + + test_row = conn.execute( + + sa.text( + "SELECT id FROM regression_test " + "WHERE sample_id = 187 AND command = '--xmltv=1 --out=null'" + ) + ).fetchone() + + if test_row is None: + return + + test_id = test_row[0] + + # Remove output first (FK dependency) + conn.execute( + sa.text( + "DELETE FROM regression_test_output WHERE regression_id = :test_id" + ), + {"test_id": test_id}, + ) + + # Remove regression test + conn.execute( + sa.text( + "DELETE FROM regression_test WHERE id = :test_id" + ), + {"test_id": test_id}, + ) diff --git a/tests/base.py b/tests/base.py index f15c81ab..174333ec 100644 --- a/tests/base.py +++ b/tests/base.py @@ -347,6 +347,7 @@ def setUp(self): categories[0].regression_tests.append(regression_tests[0]) categories[2].regression_tests.append(regression_tests[1]) + regression_test_outputs = [ RegressionTestOutput(1, "sample_out1", ".srt", ""), RegressionTestOutput(2, "sample_out2", ".srt", "")