Example #1
0
    def post(self, request):
        terminalInstance = Terminal()
        user = USER.objects.get(id=request.session['userid'])
        terminalInstance.login(user.username, user.password)

        ret, success = terminalInstance.createCourse(
            request.POST['name'], request.POST['courseNumber'],
            request.POST['classNumber'], request.POST['time'],
            request.POST['location'])

        if success is False:
            return render(request, 'shell/error.html', {"message": ret})

        return redirect('/commands/')
Example #2
0
    def test_createCourse(self):
        userdata = USER.objects.get(username="******")
        user = User.User(userdata.permission, userdata.username,
                         userdata.password, userdata.id, userdata.email,
                         userdata.firstName, userdata.lastName,
                         userdata.contactPhone, userdata.officePhone,
                         userdata.extension)
        userdata2 = USER.objects.get(username="******")
        user2 = User.User(userdata2.permission, userdata2.username,
                          userdata2.password, userdata2.id, userdata2.email,
                          userdata2.firstName, userdata2.lastName,
                          userdata2.contactPhone, userdata2.officePhone,
                          userdata2.extension)
        userdata3 = USER.objects.get(username="******")
        user3 = User.User(userdata3.permission, userdata3.username,
                          userdata3.password, userdata3.id, userdata3.email,
                          userdata3.firstName, userdata3.lastName,
                          userdata3.contactPhone, userdata3.officePhone,
                          userdata3.extension)

        self.assertTrue(user.permission[1] == '1')
        self.assertTrue(user2.permission[1] == '2')

        self.assertTrue(
            (user3.permission[1] != '1' and user2.permission[1] == '2'),
            "Not Authorized To Use This Command")

        courseData = COURSE.objects.get(courseNumber=500)
        course = Course.Course(courseData.id, courseData.name,
                               courseData.courseNumber, courseData.classNumber,
                               courseData.time, courseData.location)
        self.user = user
        self.assertEqual(
            Terminal.createCourse(self, course.name, course.courseNumber,
                                  course.classNumber, course.time,
                                  course.location), "Course Has Been Created")

        self.assertEqual(
            Terminal.createCourse(self, course.name, course.courseNumber,
                                  course.classNumber, course.time,
                                  course.location), "Course Already Exists")

        self.assertEqual(
            Terminal.createCourse(self, 'sdfs)gfsfw:::::', course.courseNumber,
                                  course.classNumber, course.time,
                                  course.location), "Invalid name")

        self.assertEqual(
            Terminal.createCourse(self, course.name, 'sdkjfbdf',
                                  course.classNumber, course.time,
                                  course.location), "Invalid Course Number")

        self.assertEqual(
            Terminal.createCourse(self, course.name, course.courseNumber,
                                  '34kb23id', course.time, course.location),
            "Invalid Class Number")

        self.assertEqual(
            Terminal.createCourse(self, course.name, course.courseNumber,
                                  course.classNumber, 'sdffw',
                                  course.location), "Invalid Time")

        self.assertEqual(
            Terminal.createCourse(self, course.name, course.courseNumber,
                                  course.classNumber, course.time, 'eq2"kbt'),
            "Invalid Location")
        #Have in order error reports
        self.assertEqual(
            Terminal.createCourse(self, 'eiufb23]]u', 'sdfsdf', 'wefwvfwe',
                                  'wergewrg', 'wefwefwef"'),
            "Multiple Invalid Info")