Exemple #1
0
 def test_get_all_course_instructors(self):
     course = Course("CS4500", "Software Dev", self.department.name)
     course.save()
     user = User(username="******",
                 email="*****@*****.**",
                 password="******")
     user.save()
     semester = Semester(name="sem",
                         start_date=datetime.now(),
                         end_date=datetime.now(),
                         is_active=True)
     semester.save()
     enrollment = Enrollment(user=user,
                             course=course,
                             semester=semester,
                             meeting_days="MWF",
                             meeting_start_time=datetime.now().time(),
                             meeting_end_time=datetime.now().time(),
                             crn="12345")
     enrollment.save()
     get_instructors = self.client.get('/course/' + course.id +
                                       '/instructors/')
     self.assertEqual(get_instructors.status_code, 200)
     json_string = json.loads(get_instructors.content.decode('utf-8'))
     self.assertEqual(json_string[0]['email'], user.email)
Exemple #2
0
 def test_get_all_courses(self):
     course = Course("CS4500", "Software Dev", self.department.name)
     course.save()
     get_courses = self.client.get('/courses/')
     self.assertEqual(get_courses.status_code, 200)
     c_json_string = json.loads(get_courses.content.decode('utf-8'))
     self.assertEqual(c_json_string[0]['id'], course.id)
Exemple #3
0
def make_course(request):
    if request.POST:
        form = MakeCourseForm(request.POST)
        if form.is_valid():
            course = Course(department=form.data['department'], name=form.data['name'],
                            course_number=form.data['course_number'],
                            group_number=form.data['group_number'], teacher=form.data['teacher'],
                            start_time=form.data['start_time'],
                            end_time=form.data['end_time'], first_day=form.data['first_day'],
                            second_day=form.data['second_day'])
            course.save()
            redirect('panel')
    else:
        form = MakeCourseForm()
    return render(request, 'new_course.html', {'form': form, 'authen': request.user.is_authenticated})
Exemple #4
0
 def test_get_all_course_projects(self):
     course = Course("CS4500", "Software Dev", self.department.name)
     course.save()
     community_partner = CommunityPartner(name="partner")
     community_partner.save()
     project = Project(name="project",
                       course=course,
                       community_partner=community_partner,
                       start_date=datetime.now(),
                       end_date=datetime.now())
     project.save()
     get_projects = self.client.get('/course/' + course.id + '/projects/')
     self.assertEqual(get_projects.status_code, 200)
     json_string = json.loads(get_projects.content.decode('utf-8'))
     self.assertEqual(json_string[0]['name'], project.name)
 def setUp(self):
     self.client = Client()
     self.college = College("hello")
     self.college.save()
     self.department = Department("test", self.college.name)
     self.department.save()
     self.course = Course("CS4500", "Software Dev", self.department.name)
     self.course.save()
     self.user = User(username="******",
                      email="*****@*****.**",
                      password="******")
     self.user.save()
     self.semester = Semester(name="sem",
                              start_date=datetime.now(),
                              end_date=datetime.now(),
                              is_active=True)
     self.semester.save()
class EnrollmentTests(TestCase):
    def setUp(self):
        self.client = Client()
        self.college = College("hello")
        self.college.save()
        self.department = Department("test", self.college.name)
        self.department.save()
        self.course = Course("CS4500", "Software Dev", self.department.name)
        self.course.save()
        self.user = User(username="******",
                         email="*****@*****.**",
                         password="******")
        self.user.save()
        self.semester = Semester(name="sem",
                                 start_date=datetime.now(),
                                 end_date=datetime.now(),
                                 is_active=True)
        self.semester.save()

    def test_good_get(self):
        enrollment = Enrollment(user=self.user,
                                course=self.course,
                                semester=self.semester,
                                meeting_days="MWF",
                                meeting_start_time=datetime.now().time(),
                                meeting_end_time=datetime.now().time(),
                                crn="12345")
        enrollment.save()
        get_enrollment = self.client.get('/enroll/' + str(enrollment.id) + '/')
        self.assertEqual(get_enrollment.status_code, 200)
        json_string = json.loads(get_enrollment.content.decode('utf-8'))
        self.assertEqual(json_string['is_active'], True)
        self.assertEqual(json_string['meeting_days'], enrollment.meeting_days)

    def test_bad_get(self):
        get_enrollment = self.client.get('/enroll/1337/')
        self.assertEqual(get_enrollment.status_code, 404)

    def test_good_post(self):
        post_enrollment = self.client.post(
            '/enroll/', {
                "user": self.user.id,
                "course": self.course.id,
                "semester": self.semester.name,
                "meeting_days": "MWF",
                "meeting_start_time": str(datetime.now().time()),
                "meeting_end_time": str(datetime.now().time()),
                "crn": "12345"
            })
        self.assertEqual(post_enrollment.status_code, 201)

    def test_bad_post_no_crn(self):
        post_enrollment = self.client.post(
            '/enroll/', {
                "user": self.user.id,
                "course": self.course.id,
                "semester": self.semester.name,
                "meeting_days": "MWF",
                "meeting_start_time": str(datetime.now().time()),
                "meeting_end_time": str(datetime.now().time())
            })
        self.assertEqual(post_enrollment.status_code, 400)

    def test_bad_post_no_meeting_times(self):
        post_enrollment = self.client.post(
            '/enroll/', {
                "user": self.user.id,
                "course": self.course.id,
                "semester": self.semester.name,
                "crn": "12345"
            })
        self.assertEqual(post_enrollment.status_code, 400)

    def test_good_put(self):
        enrollment = Enrollment(user=self.user,
                                course=self.course,
                                semester=self.semester,
                                meeting_days="MWF",
                                meeting_start_time=datetime.now().time(),
                                meeting_end_time=datetime.now().time(),
                                crn="12345")
        enrollment.save()
        temp_dict = {"crn": "98765"}
        put_enrollment = self.client.put('/enroll/' + str(enrollment.id) + '/',
                                         json.dumps(temp_dict),
                                         content_type="application/json")
        self.assertEqual(put_enrollment.status_code, 200)
        enrollment.refresh_from_db()
        self.assertEqual(enrollment.crn, "98765")

    def test_bad_put(self):
        enrollment = Enrollment(user=self.user,
                                course=self.course,
                                semester=self.semester,
                                meeting_days="MWF",
                                meeting_start_time=datetime.now().time(),
                                meeting_end_time=datetime.now().time(),
                                crn="12345")
        enrollment.save()
        temp_dict = {"user": "******"}
        put_enrollment = self.client.put('/enroll/' + str(enrollment.id) + '/',
                                         json.dumps(temp_dict),
                                         content_type="application/json")
        self.assertEqual(put_enrollment.status_code, 400)

    def test_delete(self):
        enrollment = Enrollment(user=self.user,
                                course=self.course,
                                semester=self.semester,
                                meeting_days="MWF",
                                meeting_start_time=datetime.now().time(),
                                meeting_end_time=datetime.now().time(),
                                crn="12345")
        enrollment.save()
        delete_enrollment = self.client.delete('/enroll/' +
                                               str(enrollment.id) + '/')
        self.assertEqual(delete_enrollment.status_code, 204)
        get_enrollment = self.client.get('/enroll/' + str(enrollment.id) + '/')
        self.assertEqual(get_enrollment.status_code, 404)

    def test_get_all(self):
        enrollment = Enrollment(user=self.user,
                                course=self.course,
                                semester=self.semester,
                                meeting_days="MWF",
                                meeting_start_time=datetime.now().time(),
                                meeting_end_time=datetime.now().time(),
                                crn="12345")
        enrollment.save()
        get_enrollments = self.client.get('/enrollments/')
        self.assertEqual(get_enrollments.status_code, 200)
        json_string = json.loads(get_enrollments.content.decode('utf-8'))
        self.assertEqual(json_string[0]['is_active'], True)

    def test_get_all_for_course(self):
        enrollment = Enrollment(user=self.user,
                                course=self.course,
                                semester=self.semester,
                                meeting_days="MWF",
                                meeting_start_time=datetime.now().time(),
                                meeting_end_time=datetime.now().time(),
                                crn="12345")
        enrollment.save()
        get_enrollments = self.client.get('/enrollments/' + self.course.id +
                                          '/')
        self.assertEqual(get_enrollments.status_code, 200)
        json_string = json.loads(get_enrollments.content.decode('utf-8'))
        self.assertEqual(json_string[0]['is_active'], True)

    def test_get_all_for_crn(self):
        enrollment = Enrollment(user=self.user,
                                course=self.course,
                                semester=self.semester,
                                meeting_days="MWF",
                                meeting_start_time=datetime.now().time(),
                                meeting_end_time=datetime.now().time(),
                                crn="12345")
        enrollment.save()
        get_enrollments = self.client.get('/enrollments/crn/' +
                                          enrollment.crn + '/')
        self.assertEqual(get_enrollments.status_code, 200)
        json_string = json.loads(get_enrollments.content.decode('utf-8'))
        self.assertEqual(json_string[0]['is_active'], True)
def ReadPlanifWeek(department, book, feuille, semaine, an):
    sheet = book[feuille]
    period=Period.objects.get(name=feuille, department=department)

    # lookup week row:

    # lookup week column
    wc = 1
    for wr in [1, 5]:
        while wc < 50:
            wc += 1
            sem = sheet.cell(row=wr, column=wc).value
            if sem == float(semaine):
                WEEK_COL = wc
                break
    print("Semaine %s de %s : colonne %g" % (semaine, feuille, WEEK_COL))

    row = 2
    module_COL = 1
    nature_COL = 2
    prof_COL = 3
    salle_COL = 4
    groupe_COL = 6
    durée_COL = 5
    sumtotal = 0
    while 1:
        row += 1
        salle = sheet.cell(row=row, column=salle_COL).value
        module = sheet.cell(row=row, column=module_COL).value
        if salle is None:
            continue
        if salle.startswith("TOTAL"):
            # print "Sem %g de %s - TOTAL: %g"%(semaine, feuille,sumtotal)
            break

        Cell = sheet.cell(row=row, column=WEEK_COL)
        N = Cell.value
        if N is None:
            continue

        try:
            N = float(N)
            # handle dark green lines - Vert fonce
            assert isinstance(salle, str)
            if salle == "Salle":
                nominal = int(N)
                if N != nominal:
                    print('Valeur decimale ligne %g de %s, semaine %g : on la met a 1 !' % (row, feuille, semaine))
                    nominal = 1
                    # le nominal est le nombre de cours par groupe (de TP ou TD)
                if Cell.comment:
                    comments = Cell.comment.text.replace(' ', '').replace('\n', '').replace(',', ';').split(';')
                else:
                    comments = []

                sumtotal += nominal
                continue
            try:
                comments = comments
            except:
                comments = []
            # handle light green lines - Vert clair
            MODULE = Module.objects.get(abbrev=module, period=period)
            PROMO = MODULE.train_prog
            nature = sheet.cell(row=row, column=nature_COL).value
            salle = sheet.cell(row=row, column=salle_COL).value
            prof = sheet.cell(row=row, column=prof_COL).value
            grps = sheet.cell(row=row, column=groupe_COL).value
            COURSE_TYPE = CourseType.objects.get(name=nature, department=department)
            ROOMTYPE = RoomType.objects.get(name=salle, department=department)
            duration = int(duration)
            if prof is None:
                TUTOR, created = Tutor.objects.get_or_create(username='******')
                if created:
                    TUTOR.save()
                supp_profs=[]
            else:
                assert isinstance(prof, str) and prof is not None
                profs = prof.split(";")
                prof = profs[0]
                TUTOR = Tutor.objects.get(username=prof)
                supp_profs = profs[1:]
            SUPP_TUTORS = Tutor.objects.filter(username__in=supp_profs)

            if Cell.comment:
                local_comments = Cell.comment.text.replace(' ', '').replace('\n', '').replace(',', ';').split(';')
            else:
                local_comments = []

            if isinstance(grps, int) or isinstance(grps, float):
                grps = str(int(grps))
            if not grps:
                grps = []
            else:
                grps = grps.replace(' ', '').replace(',', ';').split(';')
            groupes = [str(g) for g in grps]

            GROUPS = list(Group.objects.filter(nom__in=groupes, train_prog=PROMO))

            N=int(N)
            Diff = N - len(groupes) * nominal
            if Diff != 0:
                print("Nombre incohérent ligne %g semaine %s de %s : %s \n" % (row, semaine, feuille, module))

            for i in range(N):
                GROUPE = GROUPS[i % len(groupes)]
                C = Course(tutor=TUTOR, type=COURSE_TYPE, module=MODULE, groupe=GROUPE, semaine=semaine, an=an,
                           room_type=ROOMTYPE, duration=duration)
                C.save()
                for sp in SUPP_TUTORS:
                    C.supp_tutor.add(sp)
                    C.save()
                for after_type in [x for x in comments + local_comments if x[0] == 'A']:
                    try:
                        n = int(after_type[1])
                        s = 2
                    except ValueError:
                        n = 1
                        s = 1
                    course_type = after_type[s:]
                    courses = Course.objects.filter(type__name=course_type, module=MODULE, semaine=semaine, an=an,
                                                   groupe__in = list(GROUPE.ancestor_groups()) + [GROUPE])
                    for course in courses[:n]:
                        P = Dependency(cours1=course, cours2=C)
                        P.save()

            if 'D' in comments or 'D' in local_comments  and N >= 2:
                for GROUPE in GROUPS:
                    Cours = Course.objects.filter(type=COURSE_TYPE, module=MODULE, groupe=GROUPE, an=an,
                                                  semaine=semaine)
                    for i in range(N//2):
                        P = Dependency(cours1=Cours[2*i], cours2=Cours[2*i+1], successifs=True)
                        P.save()
            if 'ND' in comments or 'ND' in local_comments  and N >= 2:
                for GROUPE in GROUPS:
                    Cours = Course.objects.filter(type=COURSE_TYPE, module=MODULE, groupe=GROUPE, an=an,
                                                  semaine=semaine)
                    P = Dependency(cours1=Cours[0], cours2=Cours[1], ND=True)
                    P.save()
        except Exception as e:
            print("Exception ligne %g semaine %s de %s : %s \n" % (row, semaine, feuille, module), e)
            raise