"""Database level utility class for testing against transcoding related tebles. 1. transcoding_order 2. transcoding_job 3. preset 4. transcoding_rule """ from functools import wraps from typing import Any, Callable from sqlalchemy.sql import text from transcoding.connectors import mysql from transcoding.models.preset import Preset from transcoding.models.transcoding_job import TranscodingJob from transcoding.models.transcoding_order import TranscodingOrder from transcoding.models.transcoding_rule import TranscodingRule from tests.testutils import seed def seed_tables() -> None: """Seed the transcoding tables.""" with mysql.db_session(turn_off_foreign_key_checks=True) as session: session.execute(text("TRUNCATE TABLE transcoding_job")) session.execute(text("TRUNCATE TABLE transcoding_rule")) session.execute(text("TRUNCATE TABLE transcoding_order")) session.execute(text("TRUNCATE TABLE preset")) session.execute( TranscodingOrder.__table__.insert().values(seed.transcoding_order_seed_data) ) session.execute( TranscodingJob.__table__.insert().values(seed.transcoding_job_seed_data) ) session.execute(Preset.__table__.insert().values(seed.preset_seed_data)) session.execute( TranscodingRule.__table__.insert().values(seed.transcoding_rule_seed_data) ) def test_schema(function: Callable[..., Any]) -> Callable[..., Any]: """This function just seed data. Args: function (callable): function to be called to seed data. Returns: function (callable): The decorated function. """ @wraps(function) def call_function_within_db_context(*args: Any, **kwargs: Any) -> Any: seed_tables() function_return = function(*args, **kwargs) return function_return return call_function_within_db_context