class GetContactInfo(unittest.TestCase): def setUp(self): self.ADMIN = Administrator("*****@*****.**", "adminPass") self.ADMIN.change_name("Dave Brubeck") self.ADMIN.change_phone(4141234567) self.SUPER = Supervisor("*****@*****.**", "superPass") self.SUPER.change_name("Donna Summer") self.SUPER.change_phone(4149876543) self.INSTR = Instructor("*****@*****.**", "instrPass") self.INSTR.change_name("Dean Martin") self.INSTR.change_phone(2621234567) self.T_AYY = TA("*****@*****.**", "t_ayyPass") self.T_AYY.change_name("Daniel Craig") self.T_AYY.change_phone(2629876543) def test_get_info_admin(self): self.ui.command("Login [email protected] adminPass") self.assertEqual( self.ui.command("get_contact_info"), "NAME PHONE EMAIL" "Dave Brubeck 414.123.4567 [email protected]" "Donna Summer 414.987.6543 [email protected]" "Dean Martin 262.123.4567 [email protected]" "Daniel Craig 262.987.6543 [email protected]") def test_get_info_super(self): self.ui.command("Login [email protected] adminPass") self.assertEqual( self.ui.command("get_contact_info"), "NAME PHONE EMAIL" "Dave Brubeck 414.123.4567 [email protected]" "Donna Summer 414.987.6543 [email protected]" "Dean Martin 262.123.4567 [email protected]" "Daniel Craig 262.987.6543 [email protected]") def test_get_info_inst(self): self.ui.command("Login [email protected] instrPass") self.assertEqual( self.ui.command("get_contact_info"), "NAME PHONE EMAIL" "Dave Brubeck 414.123.4567 [email protected]" "Donna Summer 414.987.6543 [email protected]" "Dean Martin 262.123.4567 [email protected]" "Daniel Craig 262.987.6543 [email protected]") def test_get_info_ta(self): self.ui.command("Login [email protected] t_ayyPass") self.assertEqual( self.ui.command("get_contact_info"), "NAME PHONE EMAIL" "Dave Brubeck 414.123.4567 [email protected]" "Donna Summer 414.987.6543 [email protected]" "Dean Martin 262.123.4567 [email protected]" "Daniel Craig 262.987.6543 [email protected]")
class AccessInfoTests(unittest.TestCase): def setUp(self): self.ADMIN = Administrator("*****@*****.**", "adminPass") self.ADMIN.change_name("Dave Brubeck") self.ADMIN.change_phone(4141234567) self.SUPER = Supervisor("*****@*****.**", "superPass") self.SUPER.change_name("Donna Summer") self.SUPER.change_phone(4149876543) self.INSTR = Instructor("*****@*****.**", "instrPass") self.INSTR.change_name("Dean Martin") self.INSTR.change_phone(2621234567) self.T_AYY = TA("*****@*****.**", "t_ayyPass") self.T_AYY.change_name("Daniel Craig") self.T_AYY.change_phone(2629876543) def test_valid_access_admin(self): self.ui.command("Login [email protected] adminPass") self.assertEqual( self.ui.command("AccessInfo"), "NAME PHONE EMAIL PASSWORD" "Dave Brubeck 414.123.4567 [email protected] adminPass" "Donna Summer 414.987.6543 [email protected] superPass" "Dean Martin 262.123.4567 [email protected] instrPass" "Daniel Craig 262.987.6543 [email protected] t_ayyPass") def test_valid_access_super(self): self.ui.command("Login [email protected] superPass") self.assertEqual( self.ui.command("AccessInfo"), "NAME PHONE EMAIL PASSWORD" "Dave Brubeck 414.123.4567 [email protected] adminPass" "Donna Summer 414.987.6543 [email protected] superPass" "Dean Martin 262.123.4567 [email protected] instrPass" "Daniel Craig 262.987.6543 [email protected] t_ayyPass") def test_invalid_access_instr(self): self.ui.command("Login [email protected] instrPass") self.assertEqual(self.ui.command("AccessInfo"), "Access Denied") def test_invalid_access_ta(self): self.ui.command("Login [email protected] t_ayyPass") self.assertEqual(self.ui.command("AccessInfo"), "Access Denied")
class TestInstructor(TestCase): def setUp(self): # self.instructor1 = Instructor("*****@*****.**", "DEFAULT_PASSWORD") # self.instructor2 = Instructor("*****@*****.**", "DEFAULT_PASSWORD") # fake TA # self.ta1 = ("*****@*****.**", "DEFAULT_PASSWORD") # self.ta2 = ("*****@*****.**", "DEFAULT_PASSWORD") # fake Course # self.course1 = ("Course 1", 2, self.instructor1, [self.ta1]) # self.course2 = ("Course 2", 2, self.instructor2, [self.ta2]) self.inst0 = Instructor("*****@*****.**", "password", "instructor") self.ta0 = TA("*****@*****.**", "password", "ta") self.ta1 = TA("*****@*****.**", "password", "ta") self.ta2 = TA("*****@*****.**", "password", "ta") self.ta3 = TA("*****@*****.**", "password", "ta") self.course1 = Course("CS101", 0) self.course2 = Course("CS201", 0) self.course3 = Course("CS301", 0) def test___init__(self): self.assertEquals(self.instructor1.email, "DEFAULT_EMAIL") self.assertEquals(self.instructor1.password, "DEFAULT_PASSWORD") self.assertEquals(self.instructor1.name, "DEFAULT") self.assertEquals(self.instructor1.phone_number, "DEFAULT") def test_edit_contact(self): # still using instructor1 self.instructor1.edit_contact_info("name", "Bob Ross") self.assertNotEquals(self.instructor1.name, "DEFAULT") self.assertEquals(self.instructor1.name, "Bob Ross") self.instructor1.edit_contact_info("phone", "4145459999") self.assertNotEquals(self.instructor1.phone_number, "0000000000") self.assertEquals(self.instructor1.phone_number, "4145459999") self.instructor1.edit_contact_info("email", "*****@*****.**") self.assertNotEquals(self.instructor1.email, "*****@*****.**") self.assertEquals(self.instructor1.email, "*****@*****.**") with self.assertRaises(TypeError): self.instructor1.edit_contact_info(2, "Ted") with self.assertRaises(TypeError): self.instructor1.edit_contact_info("name", 41.6) def test_read_public_contact(self): self.assertNotEquals(self.instructor1.read_public_contact(), "DEFAULT, [email protected]") self.assertEquals(self.instructor1.read_public_contact(), "Bob Ross, [email protected]") def test_send_notification_ta(self): self.assertTrue(self.instructor1.send_notification_ta("Hi!")) def test_view_course(self): self.assertEquals(self.instructor1.view_course_assign(), "Course 1") self.assertNotEquals(self.instructor1.view_course_assign(), "Course 2") def test_view_ta_assign1(self): mod_course1 = models.ModelCourse.objects.get(course_id="CS101") 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() self.assertEqual(self.inst0.view_ta_assign()[0], "Course: CS101 TA: DEFAULT, [email protected]") def test_view_ta_assign2(self): mod_course2 = models.ModelCourse.objects.get(course_id="CS201") 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() self.assertEqual(self.inst0.view_ta_assign()[0], "Course: CS201 TA: DEFAULT, [email protected]") def test_view_ta_assign3(self): mod_course3 = models.ModelCourse.objects.get(course_id="CS301") mod_ta_course3 = models.ModelTACourse() mod_ta_course3.course = mod_course3 mod_ta3 = models.ModelPerson.objects.get(email="*****@*****.**") mod_ta_course3.TA = mod_ta3 mod_ta_course3.save() self.assertEqual(self.inst0.view_ta_assign()[0], "Course: CS301 TA: DEFAULT, [email protected]") def test_view_ta_assign4(self): mod_course1 = models.ModelCourse.objects.get(course_id="CS101") 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_course2 = models.ModelCourse.objects.get(course_id="CS201") 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() mod_course3 = models.ModelCourse.objects.get(course_id="CS301") mod_ta_course3 = models.ModelTACourse() mod_ta_course3.course = mod_course3 mod_ta3 = models.ModelPerson.objects.get(email="*****@*****.**") mod_ta_course3.TA = mod_ta3 mod_ta_course3.save() self.assertEqual(self.inst0.view_ta_assign()[0], "Course: CS101 TA: DEFAULT, [email protected]") self.assertEqual(self.inst0.view_ta_assign()[1], "Course: CS201 TA: DEFAULT, [email protected]") self.assertEqual(self.inst0.view_ta_assign()[2], "Course: CS301 TA: DEFAULT, [email protected]") self.assertEqual(self.inst0.view_ta_assign(), [ 'Course: CS101 TA: DEFAULT, [email protected]', 'Course: CS201 TA: DEFAULT, [email protected]', 'Course: CS301 TA: DEFAULT, [email protected]' ]) def test_change_password(self): self.Instructor1 = Instructor("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.assertTrue(self.Instructor1.change_password("password")) self.assertEquals(self.Instructor1.password, "password") self.assertNotEquals(self.Instructor1.password, "DEFAULT_PASSWORD") model_person1 = models.ModelPerson.objects.get( email=self.Instructor1.email) self.assertEquals(model_person1.password, "password") def test_change_email(self): self.Instructor1 = Instructor("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.person2 = Person("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.Instructor1.change_email("*****@*****.**") model_person1 = models.ModelPerson.objects.get( email=self.Instructor1.email) self.assertEquals(model_person1.email, "*****@*****.**") self.assertEquals(self.Instructor1.email, "*****@*****.**") self.assertNotEquals(self.Instructor1.email, "*****@*****.**") self.assertFalse(self.Instructor1.change_email("*****@*****.**")) self.assertFalse( self.Instructor1.change_email("no_at_symbol_or_dot_something")) self.assertFalse(self.Instructor1.change_email("*****@*****.**")) def test_change_phone(self): self.Instructor1 = Instructor("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.Instructor1.change_phone("414.414.4141") model_person1 = models.ModelPerson.objects.get( email=self.Instructor1.email) self.assertEquals(model_person1.phone, "414.414.4141") self.assertEquals(self.Instructor1.phone_number, "414.414.4141") self.assertNotEquals(self.Instructor1.phone_number, "000.000.0000") self.assertFalse(self.Instructor1.change_phone("1234567890")) self.assertFalse(self.Instructor1.change_phone("414-414-4141")) self.assertFalse(self.Instructor1.change_phone("(414)414-4141")) self.assertFalse(self.Instructor1.change_phone("abc.abc.abcd")) self.assertFalse(self.Instructor1.change_phone("1234.1234.1234")) def test_change_name(self): self.Instructor1 = Instructor("*****@*****.**", "DEFAULT_PASSWORD", "DEFAULT") self.Instructor1.change_name("Snoop Doggy Dog") model_person1 = models.ModelPerson.objects.get( email=self.Instructor1.email) self.assertEquals(model_person1.name, "Snoop Doggy Dog") self.assertEquals(self.Instructor1.name, "Snoop Doggy Dog") self.assertNotEquals(self.Instructor1.name, "DEFAULT")