from rest_framework.test import APITestCase

from vbv_lernwelt.competence.models import CompetenceProfilePage
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


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

    def test_get_compentence_page(self):
        slug = "test-lehrgang-competence"
        competence_profile = CompetenceProfilePage.objects.get(slug=slug)
        response = self.client.get(f"/api/course/page/{slug}/")

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

        self.assertEqual(competence_profile.title, data["title"])
        self.assertEqual(
            "Ich bin fähig zu Reisen eine Gesprächsführung zu machen",
            data["children"][1]["children"][0]["title"],
        )
