def assign_ta(self, parse_cmd): if len(parse_cmd) != 3: return "Incorrect Command" temp = self.whos_logged_in() if temp is None: return "Incorrect Command" if temp.type != "supervisor": return "Access Denied" try: check_ta = models.ModelPerson.objects.get(email=parse_cmd[1], type="ta") except models.ModelPerson.DoesNotExist: check_ta = None if check_ta is None: return "no such ta" try: check_course = models.ModelCourse.objects.get( course_id=parse_cmd[2]) except models.ModelCourse.DoesNotExist: check_course = None if check_course is None: return "no such course" some_guy = Supervisor(temp.email, temp.password, temp.type) if some_guy.assign_ta_course(check_ta, check_course): return "command successful" else: return "command unsuccessful"
class TestSupervisor(TestCase): def setUp(self): self.ad1 = Administrator("*****@*****.**", "ad1pass", "administrator") self.sup1 = Supervisor("*****@*****.**", "sup1pass", "supervisor") def test_assign_instructor_course(self): # fake instructors self.ins1 = Instructor("*****@*****.**", "blah", "instructor") self.ins2 = Instructor("*****@*****.**", "inspass", "instructor") # fake course self.course1 = Course("CS101", 2) self.course2 = Course("CS202", 0) # instructor 1 is assigned CS101 self.assertTrue(self.sup1.assign_instructor(self.ins1, self.course1)) # self.assertEqual(self.ins1.courses[0], self.course1) self.assertEqual(self.course1.instructor.email, "*****@*****.**") # assign instructor 1 another course self.assertTrue(self.sup1.assign_instructor(self.ins1, self.course2)) # self.assertEqual(self.ins1.courses[1], self.course2) self.assertEqual(self.course2.instructor.email, "*****@*****.**") # instructor 2 is assigned CS101 self.assertTrue(self.sup1.assign_instructor(self.ins2, self.course1)) # self.assertEqual(self.ins2.courses[0], self.course1) self.assertEqual(self.course1.instructor.email, "*****@*****.**") # self.assertNotEqual(self.ins1.courses[0], self.course1) self.ta1 = TA("*****@*****.**", "beh", "TA") with self.assertRaises(TypeError): self.sup1.assign_instructor(self.ta1, self.course1) self.admin1 = Administrator("*****@*****.**", "admin1", "administrator") with self.assertRaises(TypeError): self.sup1.assign_instructor(self.admin1, self.course1) with self.assertRaises(TypeError): self.sup1.assign_instructor(self.sup1, self.course1) with self.assertRaises(AttributeError): self.sup1.assign_instructor(self.ins1, "CS301-111") with self.assertRaises(AttributeError): self.sup1.assign_instructor("*****@*****.**", self.course1) self.sup1.create_course("CS337-401", 3) da_course = models.ModelCourse.objects.get(course_id="CS337-401") # self.test_course = Course(da_course.course_id, da_course.num_labs) # self.sup.assign_instructor(self.ins1, self.test_course) da_courseaa = models.ModelCourse.objects.get(course_id="CS337-401") self.assertEquals(da_courseaa.num_labs, da_course.num_labs) self.assertEquals(da_courseaa.course_id, da_course.course_id) # self.assertEquals(da_courseaa.instructor, self.ins1.email) def test_assign_ta_course(self): # TA 1 is assigned CS101 # fake instructors self.ta1 = TA("*****@*****.**", "blah", "ta") self.ta2 = TA("*****@*****.**", "inspass", "ta") self.ta3 = TA("*****@*****.**", "pass3", "ta") # fake course self.course1 = Course("CS101-301", 2) self.course2 = Course("CS202-201", 0) # instructor 1 is assigned CS101 self.assertTrue(self.sup1.assign_ta_course(self.ta1, self.course1)) # self.assertEqual(self.course1.tee_ays[0], "*****@*****.**") db_ta_course = models.ModelTACourse.objects.get(course=models.ModelCourse.objects.get(course_id="CS101-301"), TA=models.ModelPerson.objects.get(email="*****@*****.**")) self.assertEqual(db_ta_course.TA, models.ModelPerson.objects.get(email="*****@*****.**")) self.assertEqual(db_ta_course.course, models.ModelCourse.objects.get(course_id="CS101-301")) # assign TA 1 another course self.assertTrue(self.sup1.assign_ta_course(self.ta1, self.course2)) #self.assertEqual(self.course1.tee_ays[0], "*****@*****.**") db_ta_course = models.ModelTACourse.objects.get(course=models.ModelCourse.objects.get(course_id="CS202-201"), TA=models.ModelPerson.objects.get(email="*****@*****.**")) self.assertEqual(db_ta_course.TA, models.ModelPerson.objects.get(email="*****@*****.**")) self.assertEqual(db_ta_course.course, models.ModelCourse.objects.get(course_id="CS202-201")) # TA 2 is assigned CS101 self.assertTrue(self.sup1.assign_ta_course(self.ta2, self.course1)) #self.assertEqual(self.course1.tee_ays[0], "*****@*****.**") db_ta_course = models.ModelTACourse.objects.get(course=models.ModelCourse.objects.get(course_id="CS101-301"), TA=models.ModelPerson.objects.get(email="*****@*****.**")) self.assertEqual(db_ta_course.TA, models.ModelPerson.objects.get(email="*****@*****.**")) self.assertEqual(db_ta_course.course, models.ModelCourse.objects.get(course_id="CS101-301")) # Try to assign a third TA to CS101 self.assertTrue(self.sup1.assign_ta_course(self.ta3, self.course1)) #self.assertEqual(self.course1.tee_ays[0], "*****@*****.**") db_ta_course = models.ModelTACourse.objects.get(course=models.ModelCourse.objects.get(course_id="CS101-301"), TA=models.ModelPerson.objects.get(email="*****@*****.**")) self.assertEqual(db_ta_course.TA, models.ModelPerson.objects.get(email="*****@*****.**")) self.assertEqual(db_ta_course.course, models.ModelCourse.objects.get(course_id="CS101-301")) self.admin1 = Administrator("*****@*****.**", "admin1", "administrator") with self.assertRaises(TypeError): self.sup1.assign_ta_course(self.admin1, self.course1) with self.assertRaises(TypeError): self.sup1.assign_ta_course(self.sup1, self.course1) self.ins1 = Instructor("*****@*****.**", "ins11111", "instructor") with self.assertRaises(TypeError): self.sup1.assign_ta_course(self.ins1, self.course1) with self.assertRaises(AttributeError): self.sup1.assign_ta_course(self.ta1, "CS301-111") with self.assertRaises(AttributeError): self.sup1.assign_ta_course("*****@*****.**", self.course1) def test_assign_ta_lab(self): # TA 1 is assigned CS101 - 801 self.sup1.assign_ta_lab(self.ta1, "CS101", 801) self.assertEqual(self.ta1_sections[0], 801) # TA 2 is assigned CS101 - 802 self.sup1.assign_ta_lab(self.ta2, 802) self.assertEqual(self.ta2_sections[0], "CS101") # Try to assign TA 1 another lab section self.assertRaises(self.sup1.assign_ta_lab(self.ta1, self.course2[0]), OverflowError) self.assertRaises(self.sup1.assign_ta_lab(self.ins1, self.course1[0]), TypeError) def test_create_course_as_supervisor(self): # create a new course as admin self.assertTrue(self.sup1.create_course("CS361-401", 3)) # get the added course from the db da_course = models.ModelCourse.objects.get(course_id="CS361-401") # make sure found course is the same self.assertEqual(da_course.course_id, "CS361-401") self.assertEqual(da_course.num_labs, 3) self.assertEqual(da_course.instructor, "*****@*****.**") def test_create_course_again(self): self.assertTrue(self.sup1.create_course("CS361-401", 3)) # create the same course again with no changes self.assertFalse(self.sup1.create_course("CS361-401", 3)) # create the same course with a different number of labs self.assertFalse(self.sup1.create_course("CS361-401", 2)) # create the same course with a different section number (technically a new course) self.assertTrue(self.sup1.create_course("CS361-402", 3)) da_course = models.ModelCourse.objects.get(course_id="CS361-402") # make sure found course is the same self.assertEqual(da_course.course_id, "CS361-402") self.assertEqual(da_course.num_labs, 3) self.assertEqual(da_course.instructor, "*****@*****.**") def test_create_course_missing_parameters(self): with self.assertRaises(TypeError): self.sup1.create_course("CS101-401") # missing course_id/wrong type with self.assertRaises(TypeError): self.sup1.create_course(3) def test_create_course_long_course_id(self): # course_id too long and not right format self.assertFalse(self.sup1.create_course("totally_a_good_course_id", 2)) def test_create_course_course_id_incorrect(self): # course_id missing CS at beginning self.assertFalse(self.sup1.create_course("123456789", 2)) # course_id does not start with uppercase CS self.assertFalse(self.sup1.create_course("cs361-401", 2)) # course_id doesn't have only numbers for course number self.assertFalse(self.sup1.create_course("CS3F4-321", 2)) # course_id doesn't have a hyphen to separate course number and section number self.assertFalse(self.sup1.create_course("CS3611234", 2)) # course_id doesn't have only numbers for section number self.assertFalse(self.sup1.create_course("CS361-1F3", 2)) def test_create_course_bad_num_sections(self): # number of sections too big self.assertFalse(self.sup1.create_course("CS361-401", 99)) # number of sections is less than 0 self.assertFalse(self.sup1.create_course("CS361-401", -1)) # Create Account Tests Start # created by Jeff def test_create_account_instructor(self): # Create Instructor Tests # create unused instructor account self.assertTrue(self.sup1.create_account("*****@*****.**", "better_password", "instructor")) # get account that was just setup test_model_ins = models.ModelPerson.objects.get(email="*****@*****.**") # make sure email is equal self.assertEqual(test_model_ins.email, "*****@*****.**") # make sure password is equal self.assertEqual(test_model_ins.password, "better_password") # default name test self.assertEqual(test_model_ins.name, "DEFAULT") # default phone test self.assertEqual(test_model_ins.phone, "000.000.0000") # login false test self.assertFalse(test_model_ins.isLoggedOn) def test_create_account_TA(self): # Create TA Tests # create unused ta account self.assertTrue(self.sup1.create_account("*****@*****.**", "santa_bro", "ta")) # get account test_model_ta = models.ModelPerson.objects.get(email="*****@*****.**") # test email self.assertEqual(test_model_ta.email, "*****@*****.**") # test password self.assertEqual(test_model_ta.password, "santa_bro") # default name test self.assertEqual(test_model_ta.name, "DEFAULT") # default phone test self.assertEqual(test_model_ta.phone, "000.000.0000") # login false test self.assertFalse(test_model_ta.isLoggedOn) # Invalid account type tests def test_create_account_supervisor(self): # create supervisor test self.assertFalse(self.sup1.create_account("*****@*****.**", "super1", "supervisor")) # not in db with self.assertRaises(models.ModelPerson.DoesNotExist): models.ModelPerson.objects.get(email="*****@*****.**") def test_create_account_administrator(self): # create admin test self.assertFalse(self.sup1.create_account("*****@*****.**", "labyrinth", "administrator")) # not in db with self.assertRaises(models.ModelPerson.DoesNotExist): models.ModelPerson.objects.get(email="*****@*****.**") def test_create_account_other(self): # create whatever test self.assertFalse(self.sup1.create_account("*****@*****.**", "not_today", "horse")) # not in db with self.assertRaises(models.ModelPerson.DoesNotExist): models.ModelPerson.objects.get(email="*****@*****.**") # Invalid parameter tests def test_create_account_invalid_parameter_no_email(self): # no email with self.assertRaises(TypeError): self.sup1.create_account("password", "instructor") def test_create_account_invalid_parameter_no_password(self): # no password with self.assertRaises(TypeError): self.sup1.create_account("*****@*****.**", "instructor") def test_create_account_invalid_parameter_no_account_type(self): # no account type with self.assertRaises(TypeError): self.sup1.create_account("*****@*****.**", "password3") def test_create_account_invalid_parameter_non_uwm_email(self): # non uwm email self.assertFalse(self.sup1.create_account("*****@*****.**", "happy_trees", "instructor")) # not in db with self.assertRaises(models.ModelPerson.DoesNotExist): models.ModelPerson.objects.get(email="*****@*****.**") def test_create_account_invalid_parameter_weird_email(self): # weird email, props to Grant for this test self.assertFalse(self.sup1.create_account("[email protected]@uwm.edu", "lotta_bob", "instructor")) # not in db with self.assertRaises(models.ModelPerson.DoesNotExist): models.ModelPerson.objects.get(email="[email protected]@uwm.edu") def test_create_account_invalid_parameter_not_an_email_addy(self): # not really an email addy self.assertFalse(self.sup1.create_account("TRUST_ME_IM_EMAIL", "seriously_real_address", "ta")) # not in db with self.assertRaises(models.ModelPerson.DoesNotExist): models.ModelPerson.objects.get(email="TRUST_ME_IM_EMAIL") def test_create_account_invalid_parameter_wrong_arg_types(self): # int args self.assertFalse(self.sup1.create_account(7, 8, 9)) with self.assertRaises(models.ModelPerson.DoesNotExist): models.ModelPerson.objects.get(email=7) def test_create_account_invalid_parameter_taken_email(self): # email taken self.sup1.create_account("*****@*****.**", "santa_bro", "ta") self.assertFalse(self.sup1.create_account("*****@*****.**", "santa_bro", "ta")) # Create Account Tests End def test_edit_account_password(self): # create a test user in the system tester = models.ModelPerson() tester.email = "*****@*****.**" tester.password = "******" tester.save() # test edit password self.sup1.edit_account("*****@*****.**", "password", "new_pass") tester = models.ModelPerson.objects.get(email="*****@*****.**") self.assertEqual(tester.password, "new_pass") def test_edit_account_email(self): # create a test user in the system tester = models.ModelPerson() tester.email = "*****@*****.**" tester.password = "******" tester.save() # test edit email self.sup1.edit_account("*****@*****.**", "email", "*****@*****.**") with self.assertRaises(models.ModelPerson.DoesNotExist): models.ModelPerson.objects.get(email="*****@*****.**") tester = models.ModelPerson.objects.get(email="*****@*****.**") self.assertEqual(tester.email, "*****@*****.**") self.assertFalse(self.sup1.edit_account("*****@*****.**", "email", "[email protected]@uwm.edu")) self.assertFalse(self.sup1.edit_account("*****@*****.**", "email", "*****@*****.**")) self.assertFalse(self.sup1.edit_account("*****@*****.**", "email", "badEmail")) def test_edit_account_phone(self): # create a test user in the system tester = models.ModelPerson() tester.email = "*****@*****.**" tester.password = "******" tester.save() # test edit phone self.assertTrue(self.sup1.edit_account("*****@*****.**", "phone", "123.456.7890")) tester = models.ModelPerson.objects.get(email="*****@*****.**") self.assertEqual(tester.phone, "123.456.7890") self.assertFalse(self.sup1.edit_account("*****@*****.**", "phone_number", "not a number")) self.assertFalse(self.sup1.edit_account("*****@*****.**", "phone_number", "1234")) self.assertFalse(self.sup1.edit_account("*****@*****.**", "phone_number", "1234567890987654")) self.assertFalse(self.sup1.edit_account("*****@*****.**", "phone_number", "414-414-4141")) self.assertFalse(self.sup1.edit_account("*****@*****.**", "phone_number", "(414)414-4141")) self.assertFalse(self.sup1.edit_account("*****@*****.**", "phone_number", "abc.abc.abcd")) self.assertFalse(self.sup1.edit_account("*****@*****.**", "phone_number", "1234.1234.1234")) def test_edit_account_name(self): # create a test user in the system tester = models.ModelPerson() tester.email = "*****@*****.**" tester.password = "******" tester.save() # test edit name self.sup1.edit_account("*****@*****.**", "name", "Howard Stern") tester = models.ModelPerson.objects.get(email="*****@*****.**") self.assertEqual(tester.name, "Howard Stern") self.assertFalse(self.sup1.edit_account("*****@*****.**", "password", "new_pass")) self.assertFalse(self.sup1.edit_account("*****@*****.**", "wrong_field", "new_pass")) def test_delete_account(self): self.deleted_user = ("*****@*****.**", "delete_me_pass") self.sup1.delete_account("*****@*****.**") self.copy_user = ("*****@*****.**", "delete_me_pass") self.assertNotEqual(self.copy_user, self.deleted_user) def test_send_notification(self): self.assertTrue(self.sup1.send_notification("I Like To Eat French Fries In The Rain")) # Access Info Tests Start # Jeff's tests def test_access_info_admin_title(self): access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[0], "Administrator:") def test_access_info_admin_(self): access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[1], "DEFAULT | [email protected] | 000.000.0000") def test_access_info_blank_one(self): access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[2], "") def test_access_info_sup_title(self): access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[3], "Supervisor:") def test_access_info_sup(self): access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[4], "DEFAULT | [email protected] | 000.000.0000") def test_access_info_blank_two(self): access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[5], "") def test_access_info_inst_title(self): access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[6], "Instructors:") def test_access_info_blank_three(self): access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[7], "") def test_access_info_ta_title(self): access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[8], "TAs:") def test_access_info_blank_four(self): access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[9], "") def test_access_info_course_title(self): access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[10], "Courses:") def test_access_info_inst_no_course(self): # Add instructor, no course assignments self.inst1 = Instructor("*****@*****.**", "password", "instructor") access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[7], "DEFAULT | [email protected] | 000.000.0000") def test_access_info_ta_no_course(self): # Add TA, no course assignments self.ta1 = TA("*****@*****.**", "password", "ta") access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[9], "DEFAULT | [email protected] | 000.000.0000") def test_access_info_inst_one_course(self): # Instructor with a course self.inst1 = Instructor("*****@*****.**", "password", "instructor") self.course1 = Course("CS101", 0) self.course1.instructor = "*****@*****.**" mod_course1 = models.ModelCourse.objects.get(course_id="CS101") mod_course1.instructor = "*****@*****.**" mod_course1.save() access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[8], "\tCourse: CS101") def test_access_info_ta_one_course(self): # TA with a course self.ta1 = TA("*****@*****.**", "password", "ta") mod_ta_course1 = models.ModelTACourse() self.course1 = Course("CS101", 0) mod_course1 = models.ModelCourse.objects.get(course_id="CS101") mod_ta_course1.course = mod_course1 mod_ta1 = models.ModelPerson.objects.get(email="*****@*****.**") mod_ta_course1.TA = mod_ta1 mod_ta_course1.save() access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[10], "\tCourse: CS101") def test_access_info_course(self): # just a course self.course1 = Course("CS101", 0) access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[11], "CS101") def test_access_info_all_the_things(self): # ALL THE THINGS self.inst1 = Instructor("*****@*****.**", "password", "instructor") self.inst2 = Instructor("*****@*****.**", "password", "instructor") self.ta1 = TA("*****@*****.**", "password", "ta") self.ta2 = TA("*****@*****.**", "password", "ta") self.course1 = Course("CS101", 0) self.course2 = Course("CS102", 0) self.course1.instructor = "*****@*****.**" mod_course1 = models.ModelCourse.objects.get(course_id="CS101") mod_course1.instructor = "*****@*****.**" mod_course1.save() self.course2.instructor = "*****@*****.**" mod_course2 = models.ModelCourse.objects.get(course_id="CS102") mod_course2.instructor = "*****@*****.**" mod_course2.save() mod_ta_course1 = models.ModelTACourse() mod_ta_course1.course = mod_course1 mod_ta1 = models.ModelPerson.objects.get(email="*****@*****.**") mod_ta_course1.TA = mod_ta1 mod_ta_course1.save() mod_ta_course2 = models.ModelTACourse() mod_ta_course2.course = mod_course2 mod_ta2 = models.ModelPerson.objects.get(email="*****@*****.**") mod_ta_course2.TA = mod_ta2 mod_ta_course2.save() access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[0], "Administrator:") self.assertEqual(parse_info[1], "DEFAULT | [email protected] | 000.000.0000") self.assertEqual(parse_info[2], "") self.assertEqual(parse_info[3], "Supervisor:") self.assertEqual(parse_info[4], "DEFAULT | [email protected] | 000.000.0000") self.assertEqual(parse_info[5], "") self.assertEqual(parse_info[6], "Instructors:") self.assertEqual(parse_info[7], "DEFAULT | [email protected] | 000.000.0000") self.assertEqual(parse_info[8], "\tCourse: CS101") self.assertEqual(parse_info[9], "") self.assertEqual(parse_info[10], "DEFAULT | [email protected] | 000.000.0000") self.assertEqual(parse_info[11], "\tCourse: CS102") self.assertEqual(parse_info[12], "") self.assertEqual(parse_info[13], "") self.assertEqual(parse_info[14], "TAs:") self.assertEqual(parse_info[15], "DEFAULT | [email protected] | 000.000.0000") self.assertEqual(parse_info[16], "\tCourse: CS101") self.assertEqual(parse_info[17], "") self.assertEqual(parse_info[18], "DEFAULT | [email protected] | 000.000.0000") self.assertEqual(parse_info[19], "\tCourse: CS102") self.assertEqual(parse_info[20], "") self.assertEqual(parse_info[21], "") self.assertEqual(parse_info[22], "Courses:") self.assertEqual(parse_info[23], "CS101") self.assertEqual(parse_info[24], "CS102") # Access Info Tests End # Person tests def test_init_(self): self.Supervisor1 = Supervisor("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.assertEquals(self.Supervisor1.email, "*****@*****.**") self.assertEquals(self.Supervisor1.password, "DEFAULT_PASSWORD") def test_change_password(self): self.Supervisor1 = Supervisor("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.assertTrue(self.Supervisor1.change_password("password")) self.assertEquals(self.Supervisor1.password, "password") self.assertNotEquals(self.Supervisor1.password, "DEFAULT_PASSWORD") model_person1 = models.ModelPerson.objects.get(email=self.Supervisor1.email) self.assertEquals(model_person1.password, "password") def test_change_email(self): self.Supervisor1 = Supervisor("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.person2 = Person("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.Supervisor1.change_email("*****@*****.**") model_person1 = models.ModelPerson.objects.get(email=self.Supervisor1.email) self.assertEquals(model_person1.email, "*****@*****.**") self.assertEquals(self.Supervisor1.email, "*****@*****.**") self.assertNotEquals(self.Supervisor1.email, "*****@*****.**") self.assertFalse(self.Supervisor1.change_email("*****@*****.**")) self.assertFalse(self.Supervisor1.change_email("no_at_symbol_or_dot_something")) self.assertFalse(self.Supervisor1.change_email("*****@*****.**")) def test_change_phone(self): self.Supervisor1 = Supervisor("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.Supervisor1.change_phone("414.414.4141") model_person1 = models.ModelPerson.objects.get(email=self.Supervisor1.email) self.assertEquals(model_person1.phone, "414.414.4141") self.assertEquals(self.Supervisor1.phone_number, "414.414.4141") self.assertNotEquals(self.Supervisor1.phone_number, "000.000.0000") self.assertFalse(self.Supervisor1.change_phone("1234567890")) self.assertFalse(self.Supervisor1.change_phone("414-414-4141")) self.assertFalse(self.Supervisor1.change_phone("(414)414-4141")) self.assertFalse(self.Supervisor1.change_phone("abc.abc.abcd")) self.assertFalse(self.Supervisor1.change_phone("1234.1234.1234")) def test_change_name(self): self.Supervisor1 = Supervisor("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.Supervisor1.change_name("Snoop Doggy Dog") model_person1 = models.ModelPerson.objects.get(email=self.Supervisor1.email) self.assertEquals(model_person1.name, "Snoop Doggy Dog") self.assertEquals(self.Supervisor1.name, "Snoop Doggy Dog") self.assertNotEquals(self.Supervisor1.name, "DEFAULT") def test_get_contact_info(self): self.Supervisor1 = Supervisor("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.assertEquals(self.Supervisor1.get_contact_info(), "Snoop Doggy Dog, [email protected], 4144244343") self.assertNotEquals(self.Supervisor1.get_contact_info(), "DEFAULT, [email protected], 0000000000") def test_login(self): self.Supervisor1 = Supervisor("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.assertEquals(Supervisor.login("*****@*****.**", "DEFAULT_PASSWORD"), "Login successful") model_supervisor1 = models.ModelPerson.objects.get(email=self.Supervisor1.email) self.assertTrue(model_supervisor1.isLoggedOn) self.assertEquals(Supervisor.login("*****@*****.**", "DEFAULT_PASSWORD"), "User already logged in") self.assertEquals(Supervisor.login("*****@*****.**", "password"), "User already logged in") def test_logout(self): self.Supervisor1 = Supervisor("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.assertEquals(Supervisor.login("*****@*****.**", "DEFAULT_PASSWORD"), "Login successful") self.assertTrue(self.Supervisor1.logout())
class TestSupervisor(TestCase): def setUp(self): self.sup = Supervisor("*****@*****.**", "sup_pass") # fake instructors self.ins1_courses = [] self.ins1 = "*****@*****.**" self.ins2_courses = [] self.ins2 = "*****@*****.**" # fake course self.course1_tas = [] self.course1_instructor = "" self.course1 = ("CS101", 2) self.course2_tas = [] self.course2_instructor = "" self.course2 = ("CS202", 0) # fake ta self.ta1_sections = [] self.ta1_course = "" self.ta1 = "*****@*****.**" self.ta2_sections = [] self.ta2_course = "" self.ta2 = "*****@*****.**" self.ta3 = "ta3.uwm.edu" self.ta3_course = "" def test_assign_instructor_course(self): # instructor 1 is assigned CS101 self.sup.assign_instructor(self.ins1, self.course1[0]) self.assertEqual(self.ins1_courses[0], "CS101") self.assertEqual(self.course1_instructor, "*****@*****.**") # assign instructor 1 another course self.sup.assign_instructor(self.ins1, self.course2[0]) self.assertEqual(self.ins1_courses[1], "CS202") self.assertEqual(self.course2_instructor, "*****@*****.**") # instructor 2 is assigned CS101 self.sup.assign_instructor(self.ins2, self.course1[0]) self.assertEqual(self.ins2_courses[0], "CS101") self.assertEqual(self.course1_instructor, "*****@*****.**") self.assertNotEqual(self.ins1_courses[0], "CS101") self.assertRaises(self.sup.assign_instructor(self.ta1, self.course1[0]), TypeError) def test_assign_ta_course(self): # TA 1 is assigned CS101 self.sup.assign_ta_course(self.ta1, self.course1[0]) self.assertEqual(self.ta1_course, "CS101") self.assertEqual(self.course1_tas[0], "*****@*****.**") # assign TA 1 another course self.sup.assign_ta_course(self.ta1, self.course2[0]) self.assertEqual(self.ta1_course, "CS202") self.assertEqual(self.course2_tas[0], "*****@*****.**") # TA 2 is assigned CS101 self.sup.assign_ta_course(self.ta2, self.course1[0]) self.assertEqual(self.ta2_course, "CS101") self.assertEqual(self.course1_tas[1], "*****@*****.**") self.assertEqual(self.course1_tas[0], "*****@*****.**") # Try to assign a third TA to CS101 self.sup.assign_ta_course(self.ta3, self.course1[0]) self.assertNotEqual(self.ta3_course, "CS101") self.assertNotEqual(self.course1_tas[2], "*****@*****.**") self.assertRaises(self.sup.assign_ta_course(self.ins1, self.course1[0]), TypeError) def test_assign_ta_lab(self): # TA 1 is assigned CS101 - 801 self.sup.assign_ta_lab(self.ta1, "CS101", 801) self.assertEqual(self.ta1_sections[0], 801) # TA 2 is assigned CS101 - 802 self.sup.assign_ta_lab(self.ta2, 802) self.assertEqual(self.ta2_sections[0], "CS101") # Try to assign TA 1 another lab section self.assertRaises(self.sup.assign_ta_lab(self.ta1, self.course2[0]), OverflowError) self.assertRaises(self.sup.assign_ta_lab(self.ins1, self.course1[0]), TypeError)