def test_invalidCourse(self): course1 = Course(title="Course 14", instructor=self.instructor) course1.save() course2 = Course(title="Course 15") course2.save() response = self.client.post("/ViewAllCourses/", {"currentCourse": "a;lsdkfja"}) self.assertEqual(response.context["courses"], ["Course 14", "Course 15"], msg="Entering an invalid course fails" "to post all courses") self.assertEqual(response.context["instructor"], "Course Does not Exist", msg="Entering invalid coures fails to " "post error message through " "currentCourse") self.assertEqual(response.context["allSections"], [], msg="Entering invalid course fails to post empty list" "of sections") self.assertEqual( response.context["allTA"], [], msg="Entering invalid course fails to post empty list of TA") self.assertEqual( response.context["currentCourse"], "Please Enter Valid Course", msg= "Entering an invalid course fails to return currentCourse as correct message" )
def test_manyOfEach(self): course1 = Course(title="Course 14", instructor=self.instructor) course1.save() course2 = Course(title="Course 15") course2.save() section1 = Section(title="Section 14", course=course1, emp=self.ta1) section1.save() section2 = Section(title="Section 15", course=course1, emp=self.ta2) section2.save() response = self.client.post("/ViewAllCourses/", {"currentCourse": "Course 14"}) self.assertEqual(response.context["courses"], ["Course 14", "Course 15"], msg="Entering an invalid course fails" "to post all courses") self.assertEqual( response.context["instructor"], "Jim Rachminoff", msg= "instructor value is invalid after entering course with instructor" ) self.assertEqual( response.context["allSections"], [("Section 14", "Hungarian", "Waltz"), ("Section 15", "Max", "Volume")], msg= "Entering a course with multiple sections and TAs fails to return correct list" ) self.assertEqual( response.context["allTA"], [("Hungarian", "Waltz"), ("Max", "Volume")], msg="Entering a course with multiple TAs fails to post correct list" )
def test_oneOfEach(self): course1 = Course(title="Course 14", instructor=self.instructor) course1.save() course2 = Course(title="Course 15") course2.save() section = Section(title="Section 14", course=course1, emp=self.ta1) section.save() response = self.client.post("/ViewAllCourses/", {"currentCourse": "Course 14"}) self.assertEqual(response.context["courses"], ["Course 14", "Course 15"], msg="Entering a valid course fails" "to post all courses") self.assertEqual( response.context["instructor"], "Jim Rachminoff", msg= "instructor value is invalid after entering course with instructor" ) self.assertEqual( response.context["allSections"], [("Section 14", "Hungarian", "Waltz")], msg= "allSections value is invalid after entering course with one TA and one section" ) self.assertEqual( response.context["allTA"], [("Hungarian", "Waltz")], msg= "allTA value is invalid after entering course with one TA and one section" )
def test_noTA(self): course1 = Course(title="Course 14", instructor=self.instructor) course1.save() section1 = Section(title="Section 14", course=course1) section1.save() course2 = Course(title="Course 15") course2.save() response = self.client.post("/ViewAllCourses/", {"currentCourse": "Course 14"}) self.assertEqual(response.context["courses"], ["Course 14", "Course 15"], msg="Entering a valid course fails" "to post all courses") self.assertEqual( response.context["instructor"], "Jim Rachminoff", msg= "Instructor value invalid after entering course with no instructor" ) self.assertEqual( response.context["allSections"], [("Section 14", "No one", "assigned")], msg= "Entering a course with sections and no TA fails to procure correct list" ) self.assertEqual( response.context["allTA"], [], msg="Entering a course with no TAs fails to post empty list of TA")
def test_someCourses(self): class5 = Course(title="Class 5") class5.save() class6 = Course(title="Class 6") class6.save() self.assertEqual( courseList(), [class5.title, class6.title], msg="Making a list of courses when the DB has some entries " "return a list of every element")
class TestCreateCourse(TestCase): def setUp(self): self.employeeList = { "*****@*****.**": ["Jim", "Gaffigan", "Instructor", "T", "123"], "*****@*****.**": ["Bert", "Kreischer", "Supervisor", "A", "456"] } self.empObj = list() self.empObj = createEmp(self.employeeList, self.empObj) self.course = Course(title="Comedy 251", instructor=self.empObj[0]) self.course.save() def test_noTitle(self): self.assertEqual( "Course must have title", createCourse("", "*****@*****.**"), msg= "Entering a course without a title fails to return message \"Course must have title\"" ) def test_courseExists(self): self.assertEqual( "Course already exists", createCourse("Comedy 251", "*****@*****.**"), msg="Entering a course that already exists fails to return message " "\"Course already exists\"") def test_instructorDNE(self): self.assertEqual( "Instructor does not exist, or employee is not an Instructor", createCourse("Comedy 361", "*****@*****.**"), msg= "Entering an instructor that does not exist fails to return message" "\"Instructor does not exist, or employee is not an Instructor\"") def test_employeeNotInstructor(self): self.assertEqual( "Instructor does not exist, or employee is not an Instructor", createCourse("Comedy 361", "*****@*****.**"), msg= "Entering an employee who is not an instructor does not return message, " "\"Instructor does not exist, or employee is not an Instructor\"") def test_validInput(self): self.assertEqual( "Course Successfully Created", createCourse("Comedy 680", "*****@*****.**"), msg= "Entering an untaken course title and instructor fails to return message " "\"Course successfully created\"")
def test_getCourses(self): course1 = Course(title="Course 14", instructor=self.instructor) course1.save() course2 = Course(title="Course 15") course2.save() response = self.client.get("/ViewAllCourses/") self.assertEqual( response.context["courses"], ["Course 14", "Course 15"], msg= "Rendering View Courses page fails to return an empty list when there are no course in the " "DB") self.assertEqual( response.context["currentCourse"], "Select a Course", msg= "Rendering the View Courses page for the first time fails to have message " "\"Select a Course\"")
class TestAssignInstructor(TestCase): def setUp(self): self.employeeList = { "*****@*****.**": ["Jim", "Gaffigan", "Instructor", "T", "123"], "*****@*****.**": ["Bill", "Burr", "Instructor", "B", "789"], "*****@*****.**": ["Bert", "Kreischer", "TA", "A", "456"] } self.empObj = list() self.empObj = createEmp(self.employeeList, self.empObj) self.course1 = Course(title="Comedy 251", instructor=self.empObj[0]) self.course1.save() self.course2 = Course(title="Comedy 351") self.course2.save() def test_courseDNE(self): self.assertEqual("Course does not exist", assignInstructor("*****@*****.**", "Comedy 457")) def test_instructorDNE(self): self.assertEqual( "Instructor does not exist, or employee is not an instructor", assignInstructor("*****@*****.**", "Comedy 251")) def test_empNotInstructor(self): self.assertEqual( "Instructor does not exist, or employee is not an instructor", assignInstructor("*****@*****.**", "Comedy 251")) def test_allExistNoPrev(self): self.assertEqual("Instructor successfully assigned to course", assignInstructor("*****@*****.**", "Comedy 351")) def test_allExistPrev(self): self.assertEqual( "Instructor successfully assigned to course", assignInstructor("*****@*****.**", "Comedy 251"), msg= "Entering valid inputs for a course that already had an instructor fails to return " "message \"Instructor successfully assigned to course\"")
class TestMakeInstructor(TestCase): def setUp(self): self.employeeList = {"*****@*****.**":["Fleetwood","Mac","Instructor","J","123"], "":["","","Instructor","",""]} self.empObj = list() self.empObj = createEmp(self.employeeList, self.empObj) self.course1 = Course(title="Class 7", instructor=self.empObj[0]) self.course1.save() self.course2 = Course(title="Class 8") self.course2.save() self.course3 = Course(title="Class 9", instructor=self.empObj[1]) self.course3.save() def test_invalidCourse(self): self.assertEqual(makeInstructor("a;slkdfjapsoifjas"), "Course Does not Exist", msg="Entering a course that DNE fails to return proper message") def test_validCourseWTeach(self): self.assertEqual(makeInstructor("Class 7"), "Fleetwood Mac", msg="Entering a valid course with a valid instructor fails to return proper name") def test_validCourseWOTeach(self): self.assertEqual(makeInstructor("Class 8"), "Instructor Not Assigned Yet", msg="Entering a course without " "an instructor fails to " "return correct message") def test_emptyStrings(self): self.assertEqual(makeInstructor("Class 9"), " ", msg="Entering a course with an instructor who has no " "information fails to return and empty string")
def test_noInstructor(self): course1 = Course(title="Course 14", instructor=self.instructor) course1.save() course2 = Course(title="Course 15") course2.save() response = self.client.post("/ViewAllCourses/", {"currentCourse": "Course 15"}) self.assertEqual(response.context["courses"], ["Course 14", "Course 15"], msg="Entering a valid course fails" "to post all courses") self.assertEqual( response.context["instructor"], "Instructor Not Assigned Yet", msg= "Instructor value invalid after entering course with no instructor" ) self.assertEqual( response.context["allSections"], [], msg="Entering course with no sections fails to procure" "the appropriate list") self.assertEqual( response.context["allTA"], [], msg="Entering course with no TA fails to procure an empty list")
def test_sameName(self): class5 = Course(title="Class 5") class5.save() class6 = Course(title="Class 6") class6.save() class7_1 = Course(title="Class 7") class7_1.save() class7_2 = Course(title="Class 7") class7_2.save() class7_3 = Course(title="Class 7") class7_3.save() class7_4 = Course(title="Class 7") class7_4.save() self.assertEqual( courseList(), [ class5.title, class6.title, class7_1.title, class7_1.title, class7_1.title, class7_1.title ], msg= "Making a list courses when some names have repeats fails to return correct list" )
class TestAssignTA(TestCase): def setUp(self): self.employeeList = { "*****@*****.**": ["Jim", "Gaffigan", "Instructor", "T", "123"], "*****@*****.**": ["Bert", "Kreischer", "TA", "A", "456"] } self.empObjects = list() self.empObjects = createEmp(self.employeeList, self.empObjects) self.course = Course(title="Comedy 252", instructor=self.empObjects[0]) self.course.save() self.course2 = Course(title="Comedy 351") self.course.save() self.section = Section(title="Lab 101", course=self.course, emp=self.empObjects[1]) self.section.save() def test_courseDNE(self): self.assertEqual( "Course does not exist, or Instructor does not teach course", assignTA("*****@*****.**", "Comedy 458", "Lab 101", "*****@*****.**"), msg="Entering a course that does not exist fails to return message, " "\"Course does not exist\"") def test_sectionDNE(self): self.assertEqual( "Section does not exist", assignTA("*****@*****.**", "Comedy 252", "Lab 103", "*****@*****.**"), msg= "Entering a section that DNE fails to return message \"Section does not exist\"" ) def test_taDNE(self): self.assertEqual("TA does not exist, or employee is not a TA", assignTA("*****@*****.**", "Comedy 252", "Lab 101", "*****@*****.**"), msg="Entering a ta that DNE fails to return message " "\"TA does not exist, or employee is not TA\"") def test_courseIsNotTaughtByInstructor(self): self.assertEqual( "Course does not exist, or Instructor does not teach course", assignTA("*****@*****.**", "Comedy 351", "Lab 101", "*****@*****.**"), msg= "Entering a course that the instructor does not teach fails to return message, " "\"Course does not exist, or Instructor does not teach course\"") def test_allExistEmpNotTA(self): self.assertEqual( "TA does not exist, or employee is not a TA", assignTA("*****@*****.**", "Comedy 252", "Lab 801", "*****@*****.**"), msg="Entering an employee that is not ta fails to return message" "\"TA does not exist, or employee is not TA\"") def test_allExistNoPrev(self): self.assertEqual( "TA successfully assigned to section", assignTA("*****@*****.**", "Comedy 252", "Lab 101", "*****@*****.**"), msg= "Entering valid inputs with no previous ta assigned to the section fails to return " "\"TA successfully assigned to section\"") # If this test, or any other test in test_assign_ta, doesn't work, clear out the data base by going to admin page # and clearing out all previous entries. It will not run correctly if there are duplicate entries in the database def test_allExistPrev(self): self.assertEqual( "TA successfully assigned to section", assignTA("*****@*****.**", "Comedy 252", "Lab 101", "*****@*****.**"), msg= "Entering valid inputs with a previous ta assigned to the section returns message " "\"TA successfully assigned to section\"")
class TestAssignEmployeeToSection(TestCase): def setUp(self): self.employeeList = { "*****@*****.**": ["john", "doe", "Instructor", "a", "123"], "*****@*****.**": ["james", "doe", "Instructor", "a", "123"], "*****@*****.**": ["jane", "doe", "TA", "a", "123"], "*****@*****.**": ["jack", "doe", "Supervisor", "a", "123"] } self.empObj = list() self.empObj = createEmp(self.employeeList, self.empObj) self.courseNoInstructor = Course(title="Class 1", instructor=None) self.courseNoInstructor.save() self.courseHasInstructor = Course.objects.create( title="Class 2", instructor=self.empObj[0]) self.section1 = Section.objects.create(title="Section 1", course=self.courseNoInstructor) self.section2 = Section.objects.create(title="Section 2", course=self.courseHasInstructor) def test_courseDNE(self): self.assertEqual( "Course does not exist", assignEmployeeToSection("*****@*****.**", "Section 1", "Class 0"), msg="Entering a course that DNE fails to return correct message") def test_sectionDNE(self): self.assertEqual( "Section does not exist", assignEmployeeToSection("*****@*****.**", "Section 0", "Class 1"), msg="Entering a section that DNE fails to return message") def test_employeeDNE(self): self.assertEqual( "Employee does not exist", assignEmployeeToSection("*****@*****.**", "Section 1", "Class 1"), msg="Entering an employee that DNE fails to return correct message" ) def test_employeeSupervisor(self): self.assertEqual( "You cannot assign a supervisor to a section", assignEmployeeToSection("*****@*****.**", "Section 1", "Class 1"), msg="Entering a supervisor fails to return correct message") def test_assignInsNotCourseIns(self): self.assertEqual( "Course has different Instructor assigned to it, cannot assign new instructor to section", assignEmployeeToSection("*****@*****.**", "Section 2", "Class 2"), msg= "Entering an instruction different from the instructor already assigned to the course " "fails to return the correct message") def test_validTA(self): self.assertEqual( "Employee successfully assigned to section", assignEmployeeToSection("*****@*****.**", "Section 1", "Class 1"), msg= "Successfully assigning a valid TA to a course fails to return correct message" ) def test_validInsCourseHasIns(self): self.assertEqual( "Employee successfully assigned to section", assignEmployeeToSection("*****@*****.**", "Section 1", "Class 1"), msg= "Entering a valid Instructor for a course they are already assigned to fails to return the" " correct message") def test_validInsCourseDNHIns(self): self.assertEqual( "Employee successfully assigned to section", assignEmployeeToSection("*****@*****.**", "Section 1", "Class 1"), msg= "Entering a valid instructor for a course that does not have an instructor assigned to " "it fails to return the correct message")
class TestSupervisorAssign(TestCase): def setUp(self): self.client = Client() self.employeeList = {"*****@*****.**":["john","doe","Instructor","a","123"], "*****@*****.**":["james","doe","Instructor","a","123"], "*****@*****.**":["jane","doe","TA","a","123"], "*****@*****.**":["jack","doe","Supervisor","a","123"]} self.empObj = list() self.empObj = createEmp(self.employeeList, self.empObj) self.courseNoInstructor = Course(title="Class 3") self.courseNoInstructor.save() self.courseHasInstructor = Course(title="Class 4", instructor=self.empObj[0]) self.courseHasInstructor.save() self.section1 = Section(title="Section 3", course=self.courseNoInstructor) self.section1.save() self.section2 = Section(title="Section 4", course=self.courseHasInstructor) self.section2.save() self.courses = ["Class 3", "Class 4"] def test_get(self): response = self.client.get("/assignTA/") self.assertEqual(response.context["courses"], self.courses, "The incorrect course's list gets loaded when " "the assignTA page is rendered") def test_invalidCourse(self): response = self.client.post("/assignTA/", {"email": "*****@*****.**", "section": "Section 3", "course": "Class 0"}) self.assertEqual(response.context["message"], "Course does not exist", msg="Entering a course that DNE fails to post correct message") self.assertEqual(response.context["courses"], self.courses, "Entering a course that DNE fails to post correct" "list of all courses") def test_invalidSection(self): response = self.client.post("/assignTA/", {"email": "*****@*****.**", "section": "Section 0", "course": "Class 3"}) self.assertEqual(response.context["message"], "Section does not exist", msg="Entering a section that DNE fails to post correct message") self.assertEqual(response.context["courses"], self.courses, msg="Entering a section that DNE fails to post " "correct list of all courses") def test_empDNE(self): response = self.client.post("/assignTA/", {"email": "oops!", "section": "Section 3", "course": "Class 3"}) self.assertEqual(response.context["message"], "Employee does not exist", msg="Entering an employee that DNE fails to post correct message") self.assertEqual(response.context["courses"], self.courses, msg="Entering an employee that DNE fails to post " "correct list of all courses") def test_empIsSupervisor(self): response = self.client.post("/assignTA/", {"email": "*****@*****.**", "section": "Section 3", "course": "Class 3"}) self.assertEqual(response.context["message"], "You cannot assign a supervisor to a section", msg="Entering a supervisor fails to post correct message") self.assertEqual(response.context["courses"], self.courses, msg="Entering a supervisor fails to post " "correct list of all courses") def test_validTA(self): response = self.client.post("/assignTA/", {"email": "*****@*****.**", "section": "Section 3", "course": "Class 3"}) self.assertEqual(response.context["message"], "Employee successfully assigned to section", msg="Successfully assigning a ta to a section fails to post correct message") self.assertEqual(response.context["courses"], self.courses, msg="Successfully assigning a ta to a section " "fails correct list of all courses") def test_courseNoInstructor(self): response = self.client.post("/assignTA/", {"email": "*****@*****.**", "section": "Section 3", "course": "Class 3"}) self.assertEqual(response.context["message"], "Employee successfully assigned to section", msg="Successfully assigning an instructor to a section in a course without an instructor" " fails to post correct message") self.assertEqual(response.context["courses"], self.courses, msg="Successfully assigning an instructor to a section in a course without an instructor" "fails correct list of all courses") def test_courseInstructorIsInstructor(self): response = self.client.post("/assignTA/", {"email": "*****@*****.**", "section": "Section 4", "course": "Class 4"}) self.assertEqual(response.context["message"], "Employee successfully assigned to section", msg="Successfully assigning an instructor to a section in their own course" " fails to post correct message") self.assertEqual(response.context["courses"], self.courses, msg="Successfully assigning an instructor to a section in their own course" "fails correct list of all courses") def test_courseInstructorNotInstructor(self): response = self.client.post("/assignTA/", {"email": "*****@*****.**", "section": "Section 4", "course": "Class 4"}) self.assertEqual(response.context["message"], "Course has different Instructor assigned to it, cannot assign new instructor to section", msg="Trying to assign a instructor to a section in a course they are not assigned to" " fails to post correct message") self.assertEqual(response.context["courses"], self.courses, msg="Trying to assign a instructor to a section in a course they are not assigned to" "fails correct list of all courses")
class TestTAForCourse(TestCase): def setUp(self): self.employeeList = { "*****@*****.**": ["Bob", "Dog", "TA", "B", "Bark"], "*****@*****.**": ["Hannah", "Dog", "TA", "B", "Bark"] } self.empObj = list() self.empObj = createEmp(self.employeeList, self.empObj) self.course = Course(title="Class 11") self.course.save() self.ta1 = self.empObj[0] self.ta2 = self.empObj[1] def test_noSectionNoTAs(self): self.assertEqual( taForCourse(self.course.title), [], "Entering course with no sections fails to return None") def test_sectionNoTAs(self): section = Section(title="Section 12", course=self.course) section.save() self.assertEqual( taForCourse(self.course.title), [], "Entering course with sections that have no TA fails to " "return None") def test_uniqueTAs(self): section1 = Section(title="Section 12", course=self.course, emp=self.ta1) section1.save() section2 = Section(title="Section 13", course=self.course, emp=self.ta2) section2.save() self.assertEqual( taForCourse(self.course.title), [(self.ta1.EMP_FNAME, self.ta1.EMP_LNAME), (self.ta2.EMP_FNAME, self.ta2.EMP_LNAME)], msg= "Entering a course with sections that have unique teachers for each class fails to return" " the correct list") def test_duplicateTAs(self): section1 = Section(title="Section 12", course=self.course, emp=self.ta1) section1.save() section2 = Section(title="Section 13", course=self.course, emp=self.ta1) section2.save() self.assertEqual( taForCourse(self.course.title), [(self.ta1.EMP_FNAME, self.ta1.EMP_LNAME)], msg= "Entering a course with duplicate ta's fails to return correct list" ) def test_invalidCourse(self): with self.assertRaises( TypeError, msg="Entering an invalid course fails to raise type error"): taForCourse("poasidfjposaij")