from rest_framework.test import APITestCase

from vbv_lernwelt.core.admin import User
from vbv_lernwelt.core.create_default_users import create_default_users
from vbv_lernwelt.course.creators.test_course import create_test_course
from vbv_lernwelt.media_library.models import MediaLibraryPage


class MediaLibraryAPITestCase(APITestCase):
    def setUp(self) -> None:
        create_default_users()
        create_test_course()
        self.user = User.objects.get(username="admin")
        self.client.login(username="admin", password="test")

    def test_get_media_library_page(self):
        slug = "test-lehrgang-media"
        media_library = MediaLibraryPage.objects.get(slug=slug)
        response = self.client.get(f"/api/course/page/{slug}/")

        self.assertEqual(response.status_code, 200)
        data = response.json()

        self.assertEqual(media_library.title, data["title"])
        self.assertEqual("Fahrzeug", data["children"][1]["title"])
