Example #1
0
    def test_assignInstructorToCourse(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)
        userdata4 = USER.objects.get(username="******")
        user4 = User.User(userdata4.permission, userdata4.username,
                          userdata4.password, userdata4.id, userdata4.email,
                          userdata4.firstName, userdata4.lastName,
                          userdata4.contactPhone, userdata4.officePhone,
                          userdata4.extension)
        self.assertTrue((user.permission[1] == '1'),
                        "Not Authorized To Use This Command")
        self.assertTrue((user2.permission[1] != '1'),
                        "Not Authorized To Use This Command")
        self.assertTrue((user3.permission[1] != '1'),
                        "Not Authorized To Use This Command")
        self.assertTrue((user4.permission[1] != '1'),
                        "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.assignInstructorToCourse(self, course.databaseID,
                                              user.databaseID),
            user.firstName + " " + user.lastName + " was added to " +
            course.name)
        self.assertEqual(
            Terminal.assignInstructorToCourse(self, '234', user.databaseID),
            "Course not found")
        self.assertEqual(
            Terminal.assignInstructorToCourse(self, course.databaseID, '23'),
            "User not found")
Example #2
0
 def post(self, request):
     terminalInstance = Terminal()
     user = USER.objects.get(id=int(request.session['userid']))
     terminalInstance.login(user.username, user.password)
     ret, success = terminalInstance.assignInstructorToCourse(
         int(request.POST['courseID']), int(request.POST['instructorID']))
     if success == True:
         return redirect('/commands/')
     if success == False:
         return render(request, 'shell/error.html/', {"message": ret})