from datetime import datetime

from django.test import TestCase
from django.utils import timezone

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.course_session.models import CourseSessionAttendanceCourse
from vbv_lernwelt.duedate.models import DueDate


class CourseSessionModelsTestCase(TestCase):
    def setUp(self) -> None:
        create_default_users()
        create_test_course(with_sessions=True)

    def test_course_session_attendance_course(self):
        csac = CourseSessionAttendanceCourse.objects.all().first()

        due_date = csac.due_date

        deadline_date = datetime(
            2023, 7, 6, 8, 30, tzinfo=timezone.get_current_timezone()
        )
        due_date.start = deadline_date
        due_date.save()

        this_date = DueDate.objects.get(pk=due_date.pk)
        self.assertEqual(this_date.start, deadline_date)
