class TestAdministrator(TestCase): def setUp(self): self.ad1 = Administrator("*****@*****.**", "ad1pass") def test_create_course(self): self.assertTrue(self.ad1.create_course("CS361", 3)) self.course1 = ("CS337", 1) # course already exists self.assertFalse(self.ad1.create_course("CS337", 2)) def test_create_account(self): self.assertTrue(self.ad1.create_account("*****@*****.**", "better_password")) self.ad2 = Administrator("*****@*****.**", "ad2pass") # taken email self.assertFalse(self.ad1.create_account("*****@*****.**", "new_pass")) # taken password self.assertFalse(self.ad1.create_account("*****@*****.**", "better_password")) def test_edit_account(self): self.random_user = ("*****@*****.**", "im_random", 1234567, "Jerry Seinfeld") # test edit password self.ad1.edit_account("*****@*****.**", "password", "new_pass") self.assertEqual(self.random_user[2], "new_pass") # test edit email self.ad1.edit_account("*****@*****.**", "email", "*****@*****.**") self.assertEqual(self.random_user[1], "*****@*****.**") # test edit phone self.ad1.edit_account("*****@*****.**", "phone", 3456789) self.assertEqual(self.random_user[3], 3456789) # test edit name self.ad1.edit_account("*****@*****.**", "name", "Howard Stern") self.assertEqual(self.random_user[4], "Howard Stern") self.assertFalse(self.ad1.edit_account("*****@*****.**", "password")) self.assertFalse(self.ad1.edit_account("*****@*****.**")) self.assertFalse(self.ad1.edit_account("*****@*****.**", "password", "new_pass")) self.assertFalse(self.ad1.edit_account("*****@*****.**", "wrong_field", "new_pass")) self.assertFalse(self.ad1.edit_account("*****@*****.**", "password", ";\"π /\\# bad ` pass ' chars")) def test_delete_account(self): self.deleted_user = ("*****@*****.**", "delete_me_pass") self.ad1.delete_account("*****@*****.**") self.copy_user = ("*****@*****.**", "delete_me_pass") self.assertNotEqual(self.copy_user, self.deleted_user) def test_send_notification(self): self.assertTrue(self.ad1.send_notification("I Like To Eat French Fries In The Rain")) def test_access_info(self): # creating stuff in the system self.user = ("*****@*****.**", "pass") self.system_stuff = ([self.ad1, self.ad2, self.user], ["*****@*****.**", "*****@*****.**", "*****@*****.**"], ["ad1pass", "ad2pass", "pass"]) self.assertEqual(self.ad1.access_info(), self.system_stuff)
class TestAdministrator(TestCase): def setUp(self): self.ad1 = Administrator("*****@*****.**", "ad1pass", "administrator") self.sup1 = Supervisor("*****@*****.**", "sup1pass", "supervisor") def test_create_course_as_administrator(self): # create a new course as admin self.assertTrue(self.ad1.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.ad1.create_course("CS361-401", 3)) # create the same course again with no changes self.assertFalse(self.ad1.create_course("CS361-401", 3)) # create the same course with a different number of labs self.assertFalse(self.ad1.create_course("CS361-401", 2)) # create the same course with a different section number (technically a new course) self.assertTrue(self.ad1.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.ad1.create_course("CS101-401") # missing course_id/wrong type with self.assertRaises(TypeError): self.ad1.create_course(3) def test_create_course_long_course_id(self): # course_id too long and not right format self.assertFalse(self.ad1.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.ad1.create_course("123456789", 2)) # course_id does not start with uppercase CS self.assertFalse(self.ad1.create_course("cs361-401", 2)) # course_id doesn't have only numbers for course number self.assertFalse(self.ad1.create_course("CS3F4-321", 2)) # course_id doesn't have a hyphen to separate course number and section number self.assertFalse(self.ad1.create_course("CS3611234", 2)) # course_id doesn't have only numbers for section number self.assertFalse(self.ad1.create_course("CS361-1F3", 2)) def test_create_course_bad_num_sections(self): # number of sections too big self.assertFalse(self.ad1.create_course("CS361-401", 99)) # number of sections is less than 0 self.assertFalse(self.ad1.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.ad1.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.ad1.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.ad1.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.ad1.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.ad1.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.ad1.create_account("password", "instructor") def test_create_account_invalid_parameter_no_password(self): # no password with self.assertRaises(TypeError): self.ad1.create_account("*****@*****.**", "instructor") def test_create_account_invalid_parameter_no_account_type(self): # no account type with self.assertRaises(TypeError): self.ad1.create_account("*****@*****.**", "password3") def test_create_account_invalid_parameter_non_uwm_email(self): # non uwm email self.assertFalse( self.ad1.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.ad1.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.ad1.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.ad1.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.ad1.create_account("*****@*****.**", "santa_bro", "ta") self.assertFalse( self.ad1.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.ad1.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.ad1.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.ad1.edit_account("*****@*****.**", "email", "[email protected]@uwm.edu")) self.assertFalse( self.ad1.edit_account("*****@*****.**", "email", "*****@*****.**")) self.assertFalse( self.ad1.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.ad1.edit_account("*****@*****.**", "phone", "123.456.7890")) tester = models.ModelPerson.objects.get(email="*****@*****.**") self.assertEqual(tester.phone, "123.456.7890") self.assertFalse( self.ad1.edit_account("*****@*****.**", "phone_number", "not a number")) self.assertFalse( self.ad1.edit_account("*****@*****.**", "phone_number", "1234")) self.assertFalse( self.ad1.edit_account("*****@*****.**", "phone_number", "1234567890987654")) self.assertFalse( self.ad1.edit_account("*****@*****.**", "phone_number", "414-414-4141")) self.assertFalse( self.ad1.edit_account("*****@*****.**", "phone_number", "(414)414-4141")) self.assertFalse( self.ad1.edit_account("*****@*****.**", "phone_number", "abc.abc.abcd")) self.assertFalse( self.ad1.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.ad1.edit_account("*****@*****.**", "name", "Howard Stern") tester = models.ModelPerson.objects.get(email="*****@*****.**") self.assertEqual(tester.name, "Howard Stern") self.assertFalse( self.ad1.edit_account("*****@*****.**", "password", "new_pass")) self.assertFalse( self.ad1.edit_account("*****@*****.**", "wrong_field", "new_pass")) def test_delete_account(self): self.deleted_user = ("*****@*****.**", "delete_me_pass") self.ad1.delete_account("*****@*****.**") self.copy_user = ("*****@*****.**", "delete_me_pass") self.assertNotEqual(self.copy_user, self.deleted_user) def test_send_notification(self): self.assertTrue( self.ad1.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.ad1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[0], "Administrator:") def test_access_info_admin_(self): access_info = self.ad1.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.ad1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[2], "") def test_access_info_sup_title(self): access_info = self.ad1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[3], "Supervisor:") def test_access_info_sup(self): access_info = self.ad1.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.ad1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[5], "") def test_access_info_inst_title(self): access_info = self.ad1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[6], "Instructors:") def test_access_info_blank_three(self): access_info = self.ad1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[7], "") def test_access_info_ta_title(self): access_info = self.ad1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[8], "TAs:") def test_access_info_blank_four(self): access_info = self.ad1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[9], "") def test_access_info_course_title(self): access_info = self.ad1.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.ad1.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.ad1.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.ad1.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.ad1.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.ad1.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.ad1.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.Administrator1 = Administrator("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.assertEquals(self.Administrator1.email, "*****@*****.**") self.assertEquals(self.Administrator1.password, "DEFAULT_PASSWORD") def test_change_password(self): self.Administrator1 = Administrator("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.assertTrue(self.Administrator1.change_password("password")) self.assertEquals(self.Administrator1.password, "password") self.assertNotEquals(self.Administrator1.password, "DEFAULT_PASSWORD") model_person1 = models.ModelPerson.objects.get( email=self.Administrator1.email) self.assertEquals(model_person1.password, "password") def test_change_email(self): self.Administrator1 = Administrator("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.person2 = Person("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.Administrator1.change_email("*****@*****.**") self.assertEquals(self.Administrator1.email, "*****@*****.**") self.assertNotEquals(self.Administrator1.email, "*****@*****.**") model_person1 = models.ModelPerson.objects.get( email=self.Administrator1.email) self.assertEquals(model_person1.email, "*****@*****.**") self.assertFalse(self.Administrator1.change_email("*****@*****.**")) self.assertFalse( self.Administrator1.change_email("no_at_symbol_or_dot_something")) self.assertFalse(self.Administrator1.change_email("*****@*****.**")) def test_change_phone(self): self.Administrator1 = Administrator("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.Administrator1.change_phone("414.414.4141") model_person1 = models.ModelPerson.objects.get( email=self.Administrator1.email) self.assertEquals(model_person1.phone, "414.414.4141") self.assertEquals(self.Administrator1.phone_number, "414.414.4141") self.assertNotEquals(self.Administrator1.phone_number, "000.000.0000") self.assertFalse(self.Administrator1.change_phone("1234567890")) self.assertFalse(self.Administrator1.change_phone("414-414-4141")) self.assertFalse(self.Administrator1.change_phone("(414)414-4141")) self.assertFalse(self.Administrator1.change_phone("abc.abc.abcd")) self.assertFalse(self.Administrator1.change_phone("1234.1234.1234")) def test_change_name(self): self.Administrator1 = Administrator("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.Administrator1.change_name("Snoop Doggy Dog") model_person1 = models.ModelPerson.objects.get( email=self.Administrator1.email) self.assertEquals(model_person1.name, "Snoop Doggy Dog") self.assertEquals(self.Administrator1.name, "Snoop Doggy Dog") self.assertNotEquals(self.Administrator1.name, "DEFAULT") def test_get_contact_info(self): self.Administrator1 = Administrator("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.assertEquals(self.Administrator1.get_contact_info(), "Snoop Doggy Dog, [email protected], 4144244343") self.assertNotEquals(self.Administrator1.get_contact_info(), "DEFAULT, [email protected], 0000000000") def test_login(self): self.Administrator1 = Administrator("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.assertEquals( Administrator.login("*****@*****.**", "DEFAULT_PASSWORD"), "Login successful") model_administrator1 = models.ModelPerson.objects.get( email=self.Administrator1.email) self.assertTrue(model_administrator1.isLoggedOn) self.assertEquals( Administrator.login("*****@*****.**", "DEFAULT_PASSWORD"), "User already logged in") self.assertEquals(Administrator.login("*****@*****.**", "password"), "User already logged in") def test_logout(self): self.Administrator1 = Administrator("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.assertEquals( Administrator.login("*****@*****.**", "DEFAULT_PASSWORD"), "Login successful") self.assertTrue(self.Administrator1.logout())