from django.test import TestCase

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.learnpath.models import LearningContentPlaceholder


class SaveSlugTestCase(TestCase):
    def setUp(self) -> None:
        create_default_users()
        create_test_course(include_uk=False)

    def test_save_willHandleSlug(self):
        lc_fachcheck = LearningContentPlaceholder.objects.get(title="Fachcheck Reisen")
        self.assertEqual(
            lc_fachcheck.slug, "test-lehrgang-lp-circle-reisen-lc-fachcheck-reisen"
        )

        # only changing minutes should not change slug
        lc_fachcheck.minutes = 135
        lc_fachcheck.save()
        lc_fachcheck = LearningContentPlaceholder.objects.get(id=lc_fachcheck.id)
        self.assertEqual(
            lc_fachcheck.slug, "test-lehrgang-lp-circle-reisen-lc-fachcheck-reisen"
        )

        # changing title should change slug
        lc_fachcheck.title = "Fachcheck Foobar"
        lc_fachcheck.save()
        lc_fachcheck = LearningContentPlaceholder.objects.get(id=lc_fachcheck.id)
        self.assertEqual(
            lc_fachcheck.slug, "test-lehrgang-lp-circle-reisen-lc-fachcheck-foobar"
        )
