Example #1
0
    def command(self, inStr):
        command = ' '.join(inStr.split(' '))

        command = command.split()

        if command[0].lower() == "login":
            login = LoginHelper()
            return login.login(command)

        elif command[0].lower() == "logout":
            logout = LoginHelper()
            return logout.logout()

        elif command[0].lower() == "createaccount":
            CUH = CurrentUserHelper()
            if CUH.getCurrentUserTitle() < 3:
                return "You do not have the credentials to create an account. Permission denied"

            CA = CreateAccount()
            return CA.createAccount(command)

        elif command[0].lower() == "createlab":
            CUH = CurrentUserHelper()
            if CUH.getCurrentUserTitle() < 3:
                return "You do not have the credentials to create a lab. Permission denied"

            create = CreateLab()
            return create.createLab(command)

        elif command[0].lower() == "createcourse":
            CUH = CurrentUserHelper()
            if CUH.getCurrentUserTitle() < 3:
                return "You do not have the credentials to create a course. Permission denied"

            create = CreateCourse()
            return create.createCourse(command)

        elif command[0].lower() == "assigninstructorcourse":
            CUH = CurrentUserHelper()
            if CUH.getCurrentUserTitle() < 3:
                return "You do not have the credentials to assign an instructor to a course. Permission denied"

            AIC = assignInst()

            return AIC.assignInst(command)

        elif command[0].lower() == "assigntalab":
            CUH = CurrentUserHelper()
            if CUH.getCurrentUserTitle() < 2:
                return "You do not have the credentials to assign a ta to a lab. Permission denied"

            atl = AssignTaLab()

            return atl.assignTaLab(command)

        elif command[0].lower() == "assigntacourse":
            CUH = CurrentUserHelper()
            if CUH.getCurrentUserTitle() < 3:
                return "You do not have the credentials to assign a ta to a course. Permission denied"

            TAC = AssignTACourse()

            return TAC.assignTACourse(command)

        elif command[0].lower() == "viewcourseassign":
            CUH = CurrentUserHelper()
            if CUH.getCurrentUserTitle() < 1:
                return "You must log in to View Course Assignment"

            return viewTaAssignments(command)

        elif command[0].lower() == "deleteaccount":
            CUH = CurrentUserHelper()
            if CUH.getCurrentUserTitle() < 3:
                return "You do not have the credentials to delete an account. Permission denied"

            DA = DeleteAccount()
            return DA.createAccount(command)

        else:
            return command[0] + " is an unsupported command"
Example #2
0
class TestIntegration(TestCase):
    def setUp(self):
        self.login = LoginHelper()
        self.CUH = CurrentUserHelper()
        self.CA = CreateAccount()
        self.CC = CreateCourse()
        self.CL = CreateLab()
        self.account1 = Account.objects.create(firstName='Homer',
                                               userName='******',
                                               password='******')
        self.account2 = Account.objects.create(firstName='Stu',
                                               userName='******',
                                               password='******')
        self.course1 = Course.objects.create(name='Eng',
                                             number='101',
                                             onCampus='True',
                                             classDays='W')

    def test00(self):
        # test login
        self.assertEqual(self.login.login(["login", "Homer", "123456"]),
                         "Account Not Found")

        self.assertFalse(self.CUH.isCurrent())

        self.assertEqual(self.login.login(["login", "hsimpson", "123456"]),
                         "Logged in as hsimpson")

        self.assertTrue(self.CUH.isCurrent())

    def test01(self):
        # test login with logout
        self.assertFalse(self.CUH.isCurrent())

        self.assertEqual(self.login.login(["login", "hsimpson", '123456']),
                         "Logged in as hsimpson")

        self.assertTrue(self.CUH.isCurrent())

        self.assertEqual(self.login.logout(), "Successfully logged out")

        self.assertFalse(self.CUH.isCurrent())

    def test02(self):
        # test create account login
        self.assertEqual(Account.objects.count(), 2)

        self.assertEqual(
            self.CA.createAccount(
                ["createaccount", "taman", "ta", "*****@*****.**"]),
            "Account successfully created.  Temporary password is: taman456")

        self.assertEqual(Account.objects.count(), 3)

        self.assertFalse(self.CUH.isCurrent())

        self.assertEqual(self.login.login(["login", "taman", "taman456"]),
                         "Logged in as taman")

        self.assertEqual(self.CUH.getCurrentUser(),
                         Account.objects.get(userName='******'))

        self.assertTrue(self.CUH.isCurrent())

        self.assertEqual(self.CUH.getCurrentUserTitle(), 1)

        self.assertEqual(self.login.logout(), "Successfully logged out")

        self.assertFalse(self.CUH.isCurrent())

    def test03(self):
        # test creating accounts with same username
        self.assertEqual(Account.objects.count(), 2)

        self.assertEqual(
            self.CA.createAccount(
                ["createaccount", "hsimpson", "password", "*****@*****.**"]),
            "Account already exists")

        self.assertEqual(Account.objects.count(), 2)

        self.assertEqual(
            self.CA.createAccount(
                ["createaccount", "spidface", "password", "*****@*****.**"]),
            "Account already exists")

        self.assertEqual(Account.objects.count(), 2)

    def test04(self):
        # test creating Courses
        self.assertEqual(Course.objects.count(), 1)

        self.assertEqual(
            self.CC.createCourse(
                ["createCourse", "Eng", "101", "Campus", "TR", "1000",
                 "1050"]), "Course already exists")

        self.assertEqual(Course.objects.count(), 1)

        self.assertEqual(
            self.CC.createCourse(
                ["createCourse", "Eng", "102", "Campus", "TR", "1000",
                 "1050"]), "Course successfully created")

        self.assertEqual(Course.objects.count(), 2)

    def test05(self):
        # test creating Labs
        self.assertEqual(Lab.objects.count(), 0)

        self.assertEqual(
            self.CL.createLab(["", "101", "801", "R", "1200", "1201"]),
            "Lab successfully created")

        self.assertEqual(Lab.objects.count(), 1)

        self.assertEqual(
            self.CL.createLab(["", "101", "801", "R", "1200", "1201"]),
            "Lab already exists, lab not added")

        self.assertEqual(Lab.objects.count(), 1)

    def test06(self):
        # test creating Labs and Courses

        self.assertEqual(Lab.objects.count(), 0)

        self.assertEqual(
            self.CL.createLab(["", "351", "801", "R", "1200", "1201"]),
            "The Course you are trying to create a lab for does not exist")

        self.assertEqual(Lab.objects.count(), 0)
        self.assertEqual(Course.objects.count(), 1)

        self.assertEqual(
            self.CC.createCourse([
                "createCourse", "DataStructures", "351", "Campus", "TR",
                "1000", "1050"
            ]), "Course successfully created")

        self.assertEqual(Course.objects.count(), 2)

        self.assertEqual(
            self.CL.createLab(["", "351", "801", "R", "1200", "1201"]),
            "Lab successfully created")
        self.assertEqual(Lab.objects.count(), 1)
Example #3
0
 def test_invalid_location(self):
     self.assertEqual(
         CreateCourse.createCourse(
             self.CC, self.command_create_course_invalid_location),
         "Location is invalid, please enter campus or online.")
Example #4
0
    def setUp(self):
        self.CC = CreateCourse()

        # Create some courses to test against
        Course.objects.create(name="TemporalMechanics",
                              number=784,
                              onCampus=True,
                              classDays="MW",
                              classHoursStart=1000,
                              classHoursEnd=1100)

        Course.objects.create(name="WarpTheory",
                              number=633,
                              onCampus=False,
                              classDays="TR",
                              classHoursStart=1200,
                              classHoursEnd=1250)

        # Commands to tests that a course can successfully be created
        self.command_create_course = [
            "createCourse", "NebulaStudies", "432", "Campus", "MW", "1300",
            "1400"
        ]
        self.command_create_course2 = [
            "createCourse", "StarshipDesign", "275", "Online", "NN", "0000",
            "0000"
        ]

        # Command to make sure a course that already exists cannot be created
        self.command_course_already_exists = [
            "createCourse", "TemporalMechanics", "784", "Campus", "MW", "1000",
            "1100"
        ]

        # Commands to test missing command arguments
        self.command_create_course_missing_args1 = [
            "createCourse", "ReplicatorStudies", "809", "Campus", "MW", "2000"
        ]
        self.command_create_course_missing_args2 = [
            "createCourse", "ReplicatorStudies", "809", "Campus", "MW"
        ]
        self.command_create_course_missing_args3 = [
            "createCourse", "ReplicatorStudies", "809", "Campus"
        ]
        self.command_create_course_missing_args4 = [
            "createCourse", "ReplicatorStudies", "809"
        ]
        self.command_create_course_missing_args5 = [
            "createCourse", "ReplicatorStudies"
        ]
        self.command_create_course_missing_args6 = ["createCourse"]

        # Commands to test invalid course number
        self.command_create_course_invalid_courseNum = [
            "createCourse", "DilithiumHarvesting", "abc", "Campus", "MW",
            "1300", "1400"
        ]
        self.command_create_course_invalid_courseNum2 = [
            "createCourse", "DilithiumHarvesting", "12345", "Campus", "MW",
            "1300", "1400"
        ]
        self.command_create_course_invalid_courseNum3 = [
            "createCourse", "DilithiumHarvesting", "1", "Campus", "MW", "1300",
            "1400"
        ]
        self.command_create_course_invalid_courseNum4 = [
            "createCourse", "DilithiumHarvesting", "12", "Campus", "MW",
            "1300", "1400"
        ]
        self.command_create_course_invalid_courseNum5 = [
            "createCourse", "DilithiumHarvesting", "1a2", "Campus", "MW",
            "1300", "1400"
        ]
        # Commands to test invalid location
        self.command_create_course_invalid_location = [
            "createCourse", "DilithiumHarvesting", "450", "Mars", "MW", "1300",
            "1400"
        ]

        # Commands to test invalid course days
        self.command_create_course_invalid_days = [
            "createCourse", "InterspeciesEthics", "307", "Online", "q", "1200",
            "1300"
        ]
        self.command_create_course_invalid_days2 = [
            "createCourse", "InterspeciesEthics", "307", "Online", "123",
            "1200", "1300"
        ]
        self.command_create_course_invalid_days3 = [
            "createCourse", "InterspeciesEthics", "307", "Online", "My",
            "1200", "1300"
        ]

        # Commands to test invalid times
        self.command_create_course_invalid_time = [
            "createCourse", "InterspeciesEthics", "207", "Campus", "M", "abcd",
            "1400"
        ]
        self.command_create_course_invalid_time1 = [
            "createCourse", "InterspeciesEthics", "207", "Campus", "M", "1300",
            "abcd"
        ]
        self.command_create_course_invalid_time2 = [
            "createCourse", "InterspeciesEthics", "207", "Campus", "M", "9000",
            "1200"
        ]
        self.command_create_course_invalid_time3 = [
            "createCourse", "InterspeciesEthics", "207", "Campus", "M", "1200",
            "6079"
        ]
Example #5
0
 def test_create_course_already_exists(self):
     self.assertEqual((CreateCourse.createCourse(
         self.CC, self.command_course_already_exists)),
                      "Course already exists")