feat(main): commit

This commit is contained in:
2026-03-08 16:48:58 -04:00
parent 567766eaed
commit f37382d2b8
29 changed files with 3735 additions and 223 deletions

View File

@@ -1,6 +1,9 @@
import pytest
from django.test import Client
from core.models import AppUser, Library, Channel
from core.models import AppUser, Library, Channel, MediaSource, MediaItem, Airing
from django.utils import timezone
from datetime import timedelta
import uuid
@pytest.fixture
def client():
@@ -63,5 +66,68 @@ def test_create_channel(client, user, library):
assert data["slug"] == "new-api-ch"
# Verify it hit the DB
assert Channel.objects.count() == 1
assert Channel.objects.get(id=data["id"]).name == "New API Channel"
@pytest.fixture
def media_source(db, library):
return MediaSource.objects.create(
library=library,
name="Test Source",
source_type="local_directory",
uri="/mock/test"
)
@pytest.fixture
def media_item_youtube(db, media_source):
return MediaItem.objects.create(
media_source=media_source,
title="YT Test Video",
item_kind="video",
runtime_seconds=600,
file_path="https://www.youtube.com/watch?v=dQw4w9WgXcQ",
)
@pytest.mark.django_db
def test_channel_now_playing_uncached_media_path(client, channel, media_item_youtube):
now = timezone.now()
Airing.objects.create(
channel=channel,
media_item=media_item_youtube,
starts_at=now - timedelta(minutes=5),
ends_at=now + timedelta(minutes=5),
slot_kind="program",
status="playing",
generation_batch_uuid=uuid.uuid4()
)
response = client.get(f"/api/channel/{channel.id}/now")
assert response.status_code == 200
data = response.json()
assert data["media_item_title"] == "YT Test Video"
# Should use the raw file_path since there is no cached_file_path
assert data["media_item_path"] == "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
@pytest.mark.django_db
def test_channel_now_playing_cached_media_path(client, channel, media_item_youtube):
from django.conf import settings
import os
media_item_youtube.cached_file_path = os.path.join(settings.MEDIA_ROOT, "dQw4w9WgXcQ.mp4")
media_item_youtube.save()
now = timezone.now()
Airing.objects.create(
channel=channel,
media_item=media_item_youtube,
starts_at=now - timedelta(minutes=5),
ends_at=now + timedelta(minutes=5),
slot_kind="program",
status="playing",
generation_batch_uuid=uuid.uuid4()
)
response = client.get(f"/api/channel/{channel.id}/now")
assert response.status_code == 200
data = response.json()
assert data["media_item_title"] == "YT Test Video"
# Should resolve the cached_file_path to a web-accessible MEDIA_URL
assert data["media_item_path"] == "/dQw4w9WgXcQ.mp4"