"""Test track video.""" from sqlalchemy import func, select from video.connectors import mysql from video.models.sql.classes import track_video from tests.unit import ar_db_utils @ar_db_utils.test_schema def test_upsert() -> None: """Test upsert.""" with mysql.ar_db_session(turn_off_foreign_key_constraint=True) as session: track_video_entry = track_video.upsert( { "track_id": 44556, "color": "color", "channel": "2", "fps": "25", "resolution": "SD", "aspect_ratio": "4:3", }, session=session, ) assert track_video_entry["track_id"] == 44556 assert track_video_entry["color"] == "color" assert track_video_entry["channel"] == "2" assert track_video_entry["fps"] == "25" assert track_video_entry["resolution"] == "SD" assert track_video_entry["aspect_ratio"] == "4:3" @ar_db_utils.test_schema def test_upsert_defaults() -> None: """Test upsert creates.""" with mysql.ar_db_session(turn_off_foreign_key_constraint=True) as session: track_video_entry = track_video.upsert( { "track_id": 44556, }, session=session, ) assert track_video_entry["track_id"] == 44556 assert track_video_entry["color"] == "color" @ar_db_utils.test_schema def test_upsert_updates() -> None: """Test upsert updates.""" with mysql.ar_db_session(turn_off_foreign_key_constraint=True) as session: track_video.upsert( { "track_id": 44556, "color": "color", "channel": "2", "fps": "25", "resolution": "SD", "aspect_ratio": "4:3", }, session=session, ) track_video_entry = track_video.upsert( { "track_id": 44556, "color": "black_and_white", }, session=session, ) assert track_video_entry["color"] == "black_and_white" with mysql.ar_db_session(turn_off_foreign_key_constraint=True) as session: count = session.execute( select(func.count()).select_from(track_video.TrackVideo) ).scalar() assert count == 1