def test_more_enrollable(self): """When more students can be enrolled, show the enroll button.""" user = self.make_user() school_year = SchoolYearFactory(school=user.school) StudentFactory(school=user.school) student = StudentFactory(school=user.school) EnrollmentFactory(student=student, grade_level__school_year=school_year) with self.login(user): self.get_check_200("schools:school_year_detail", uuid=school_year.uuid) assert self.get_context("enroll_url") == self.reverse( "students:enrollment_create", school_year_uuid=school_year.uuid )
def test_start_before_end(self): """The start date must be before the end date.""" school = SchoolFactory() school_year = SchoolYearFactory(school=school) data = { "school_year": str(school_year.id), "start_date": str(school_year.end_date + datetime.timedelta(days=3)), "end_date": str(school_year.start_date), } form = SchoolBreakForm(user=school.admin, data=data) is_valid = form.is_valid() assert not is_valid assert "The start date must be before the end date." in form.non_field_errors()
def test_grade_level_info(self): """The context has the grade level structure expected by the template.""" user = self.make_user() school_year = SchoolYearFactory(school=user.school) grade_level = GradeLevelFactory(school_year=school_year) course = CourseFactory(grade_levels=[grade_level]) with self.login(user): self.get_check_200("schools:school_year_detail", uuid=school_year.uuid) assert self.get_context("grade_levels") == [{ "grade_level": grade_level, "courses": [course] }]
def test_ok(self): user = self.make_user() today = timezone.localdate() SchoolYearFactory(school=user.school) StudentFactory(school=user.school) with self.login(user): self.get_check_200("core:daily") assert self.get_context("nav_link") == "daily" assert self.get_context("day") == today first_day = Week(today).first_day assert self.get_context("weekly_url") == self.reverse( "core:weekly", first_day.year, first_day.month, first_day.day )
def test_create(self): """A school break is created.""" school = SchoolFactory() school_year = SchoolYearFactory(school=school) data = { "school_year": str(school_year.id), "start_date": str(school_year.start_date), "end_date": str(school_year.start_date), } form = SchoolBreakForm(user=school.admin, data=data) is_valid = form.is_valid() form.save() assert is_valid assert school_year.breaks.count() == 1
def test_next_course_day_all_breaks(self): """When all school days are breaks, get the last possible course day.""" school_year = SchoolYearFactory(days_of_week=SchoolYear.ALL_DAYS) grade_level = GradeLevelFactory(school_year=school_year) course = CourseFactory(grade_levels=[grade_level], days_of_week=SchoolYear.ALL_DAYS) SchoolBreakFactory( school_year=school_year, start_date=school_year.start_date, end_date=school_year.end_date, ) next_course_day = school_year.get_next_course_day( course, school_year.start_date, student=None) assert next_course_day == school_year.end_date
def test_only_school_year_for_user(self): user = self.make_user() school_year = SchoolYearFactory() data = {"school_year": str(school_year.id), "name": "Kindergarten"} with self.login(user): response = self.post("core:start-grade-level", data=data) self.response_200(response) form = self.get_context("form") self.assertEqual( form.non_field_errors(), [ "A grade level cannot be created for a different user's school year." ], )
def test_get_week_dates_for(self): school_year = SchoolYearFactory() monday = datetime.date(2020, 1, 20) sunday = datetime.date(2020, 1, 26) week = (monday, sunday) self.assertEqual( school_year.get_week_dates_for(week), [ datetime.date(2020, 1, 20), datetime.date(2020, 1, 21), datetime.date(2020, 1, 22), datetime.date(2020, 1, 23), datetime.date(2020, 1, 24), ], )
def test_next_course_day_with_break(self): """A break affects when the next course day is.""" school_year = SchoolYearFactory(days_of_week=SchoolYear.ALL_DAYS) grade_level = GradeLevelFactory(school_year=school_year) course = CourseFactory(grade_levels=[grade_level], days_of_week=SchoolYear.ALL_DAYS) SchoolBreakFactory( school_year=school_year, start_date=school_year.start_date + datetime.timedelta(days=1), end_date=school_year.start_date + datetime.timedelta(days=1), ) next_course_day = school_year.get_next_course_day( course, school_year.start_date, student=None) assert next_course_day == school_year.start_date + datetime.timedelta( days=2)
def test_school_year_for_user_only(self, timezone): now = datetime.datetime(2020, 1, 26, tzinfo=pytz.utc) sunday = now.date() timezone.localdate.return_value = now.date() user = self.make_user() student, grade_level = self.make_student_enrolled_in_grade_level( user, sunday) SchoolYearFactory( start_date=sunday - datetime.timedelta(days=90), end_date=sunday + datetime.timedelta(days=90), ) CourseFactory(grade_levels=[grade_level]) with self.login(user): self.get("core:app") schedules = self.get_context("schedules") assert len(schedules[0]["courses"]) > 0
def test_surrounding_dates_no_current_school_year(self): """When there is no current school year, pull the dates from today.""" user = self.make_user() today = timezone.localdate() SchoolYearFactory( school=user.school, start_date=today - datetime.timedelta(days=5), end_date=today - datetime.timedelta(days=1), ) StudentFactory(school=user.school) with self.login(user): self.get("core:daily") self.assertContext("ereyesterday", today - datetime.timedelta(days=2)) self.assertContext("yesterday", today - datetime.timedelta(days=1)) self.assertContext("tomorrow", today + datetime.timedelta(days=1)) self.assertContext("overmorrow", today + datetime.timedelta(days=2))
def test_not_graded_work_from_other_school(self): user = self.make_user() student = StudentFactory(school=user.school) school_year = SchoolYearFactory(school=user.school) graded_work_1 = GradedWorkFactory( course_task__course__grade_level__school_year=school_year) CourseworkFactory(student=student, course_task=graded_work_1.course_task) graded_work_2 = GradedWorkFactory() CourseworkFactory(course_task=graded_work_2.course_task) with self.login(user): self.get("students:grade") self.assertContext("work_to_grade", [{ "student": student, "graded_work": [graded_work_1] }])