def test_admin_level_of_access(self): logout('localhost') user = login_user('z1', 'adminPass', 'localhost') self.assertEqual(has_access('localhost', Student), True) self.assertEqual(has_access('localhost', Staff), True) self.assertEqual(has_access('localhost', Admin), True)
def test_fail_enrollment(self): user = login_user('z100', 'student228', 'localhost') course = find_course('COMP15610', '17s2') #Course does not exist user.enrol(course) self.assertEqual(course, None) self.assertEqual(user.is_enrolled_in(course), False)
def test_student_level_of_access(self): logout('localhost') user = login_user('z100', 'student228', 'localhost') self.assertEqual(has_access('localhost', Student), True) self.assertEqual(has_access('localhost', Staff), False) self.assertEqual(has_access('localhost', Admin), False)
def test_student_login(self): user = login_user('z100', 'student228', 'localhost') self.assertNotEqual(user, None) self.assertEqual(type(user), Student) self.assertEqual(user, get_user('localhost')) self.assertEqual(has_access('localhost', Student), True)
def test_staff_login(self): user = login_user('z50', 'staff670', 'localhost') self.assertNotEqual(user, None) self.assertEqual(type(user), Staff) self.assertEqual(user, get_user('localhost')) self.assertEqual(has_access('localhost', Staff), True)
def test_admin_login(self): user = login_user('z1', 'adminPass', 'localhost') self.assertNotEqual(user, None) self.assertEqual(type(user), Admin) self.assertEqual(user, get_user('localhost')) self.assertEqual(has_access('localhost', Admin), True)
def login_page(request, role, page): if request.method == "GET": logged_in_as = None if (has_access(request.remote_addr, Student)): logged_in_as = 'Student' if (has_access(request.remote_addr, Staff)): logged_in_as = 'Staff' return render_template("login.html", page=page, role=role, logged_in_as=logged_in_as, attempt=request.args.get('attempt')) if request.method == "POST": user = login_user(request.form["username"], request.form["password"], request.remote_addr) if user == None: attempt = 1 if request.args.get('attempt'): attempt = int(request.args.get('attempt')) + 1 if page: return redirect("/login/" + page + "?attempt=" + str(attempt)) return redirect("/login" + "?attempt=" + str(attempt)) if type(user) is Admin: if page: return redirect(page.replace("@2F", "/")) return redirect("/adminHome") #Admin Homepage elif type(user) is Staff: if page: return redirect(page.replace("@2F", "/")) return redirect("/staffHome") #Staff Homepage elif type(user) is Student or type(user) is Guest: if page: return redirect(page.replace("@2F", "/")) return redirect("/studentHome") #Student Homepage else: return "Something went wrong"
def test_cancel_enrollment(self): user = login_user('z100', 'student228', 'localhost') course = find_course('COMP1531', '17s2') user.unenrol(course) self.assertEqual(user.is_enrolled_in(course), False)
def test_staff_incorrect_login(self): user = login_user('z10', 'adminPass', 'localhost') self.assertEqual(user, None) self.assertEqual(has_access('localhost', Admin), False)