Пример #1
0
    def test_validate_one_week_day(self):
        """A school year must run on at least one day per week."""
        school = SchoolFactory()
        data = {
            "school": str(school.id),
            "start_date": "9/1/2020",
            "end_date": "6/1/2021",
        }
        form = SchoolYearForm(user=school.admin, data=data)

        is_valid = form.is_valid()

        assert not is_valid
        assert ("A school year must run on at least one week day."
                in form.non_field_errors())
Пример #2
0
    def test_invalid_start_date(self):
        """An invalid start date records a form error."""
        school = SchoolFactory()
        data = {
            "school": str(school.id),
            "start_date": "bogus",
            "end_date": "6/1/2021",
            "monday": True,
        }
        form = SchoolYearForm(user=school.admin, data=data)

        is_valid = form.is_valid()

        assert not is_valid
        assert "start_date" in form.errors
Пример #3
0
    def test_school_year_overlap_with_itself(self):
        """A school year is permitted to overlap with itself when updating."""
        school = SchoolFactory()
        school_year = SchoolYearFactory(school=school)

        data = {
            "school": str(school.id),
            "start_date": str(school_year.start_date - datetime.timedelta(days=1)),
            "end_date": str(school_year.end_date),
            "monday": True,
        }
        form = SchoolYearForm(user=school.admin, instance=school_year, data=data)

        is_valid = form.is_valid()

        assert is_valid
Пример #4
0
    def test_max_length(self):
        """A school year has a maximum allowed length."""
        school = SchoolFactory()
        data = {
            "school": str(school.id),
            "start_date": "1/1/2020",
            "end_date": "12/31/2022",
            "monday": True,
        }
        form = SchoolYearForm(user=school.admin, data=data)

        is_valid = form.is_valid()

        assert not is_valid
        assert ("A school year may not be longer than 500 days."
                in form.non_field_errors())
Пример #5
0
    def test_no_overlapping_school_years(self):
        """A school year's dates may not overlap with another."""
        school = SchoolFactory()
        school_year = SchoolYearFactory(school=school)
        cases = [
            (
                "surround",
                str(school_year.start_date - datetime.timedelta(days=1)),
                str(school_year.end_date + datetime.timedelta(days=1)),
            ),
            (
                "inside",
                str(school_year.start_date + datetime.timedelta(days=1)),
                str(school_year.end_date - datetime.timedelta(days=1)),
            ),
            (
                "overlap_start",
                str(school_year.start_date - datetime.timedelta(days=1)),
                str(school_year.end_date - datetime.timedelta(days=1)),
            ),
            (
                "overlap_end",
                str(school_year.start_date + datetime.timedelta(days=1)),
                str(school_year.end_date + datetime.timedelta(days=1)),
            ),
        ]

        for case in cases:
            with self.subTest(case[0]):
                data = {
                    "school": str(school.id),
                    "start_date": case[1],
                    "end_date": case[2],
                    "monday": True,
                }
                form = SchoolYearForm(user=school.admin, data=data)

                is_valid = form.is_valid()

                assert not is_valid
                assert (
                    "School years may not have overlapping dates."
                    in form.non_field_errors()[0]
                )
Пример #6
0
    def test_no_date_change_with_breaks(self):
        """A school year must contain any breaks."""
        school = SchoolFactory()
        school_year = SchoolYearFactory(school=school)
        start = school_year.start_date
        end = school_year.end_date
        SchoolBreakFactory(school_year=school_year, start_date=start, end_date=start)
        SchoolBreakFactory(school_year=school_year, start_date=end, end_date=end)
        data = {
            "school": str(school.id),
            "start_date": str(start + datetime.timedelta(days=1)),
            "end_date": str(end - datetime.timedelta(days=1)),
            "monday": True,
        }
        form = SchoolYearForm(user=school.admin, instance=school_year, data=data)

        is_valid = form.is_valid()

        assert not is_valid
        errors = form.non_field_errors()
        assert "You have a school break before the school year's start date." in errors
        assert "You have a school break after the school year's end date." in errors
Пример #7
0
    def test_school_year_days_superset_of_courses_days(self):
        """The days of a school year must be a superset of each course's days."""
        school = SchoolFactory()
        school_year = SchoolYearFactory(school=school)
        grade_level = GradeLevelFactory(school_year=school_year)
        course = CourseFactory(
            grade_levels=[grade_level], days_of_week=Course.MONDAY + Course.TUESDAY
        )
        data = {
            "school": str(school.id),
            "start_date": "1/1/2020",
            "end_date": "12/31/2020",
            "monday": True,
        }
        form = SchoolYearForm(user=school.admin, instance=school_year, data=data)

        is_valid = form.is_valid()

        assert not is_valid
        assert (
            "The school year days must include any days that a course runs."
            " The following courses run on more days than the school year:"
            f" {course}" in form.non_field_errors()
        )