def test_login_email_integer_as_email(self): with self.assertRaises( TypeError, msg= "The login() function must take an email as its first parameter" ): login(123, "password")
def test_login_nobody(self): self.assertEqual( login('*****@*****.**', 'password1'), "The username that you used does not exist. Please retry.") self.assertEqual( login('*****@*****.**', 'NobodyPassword'), "The username that you used does not exist. Please retry.")
def test_login_email_without_at_symbol(self): with self.assertRaises( TypeError, msg= "The login() function must take an email as its first parameter" ): login("instructoruwm.edu", "password")
def test_login_ta(self): self.assertEqual(login('*****@*****.**', 'password1'), "Valid") self.assertEqual( login('*****@*****.**', 'password2'), "The password that you entered is not correct. Please retry.") self.assertEqual( login('*****@*****.**', 'NobodyPassword'), "The password that you entered is not correct. Please retry.")
def post(self, request): x = request.POST['uname'] message = login(x, request.POST['psw']) if message == "Valid": u = get_user(x) request.session['name'] = u.email request.session['role'] = u.role request.session.set_expiry(0) if u.is_supervisor(): request.session['supervisor'] = True else: request.session['supervisor'] = False return redirect("/course/", request) else: return render(request, "login.html", {"message": message})
def test_login_email_no_arguments(self): with self.assertRaises( TypeError, msg="The login() function must take 2 parameters"): login()
def test_login_email_one_argument(self): with self.assertRaises( TypeError, msg="The login() function must take 2 parameters"): login("*****@*****.**")
def test_login_email_too_many_arguments(self): with self.assertRaises( TypeError, msg="The login() function must take 2 parameters"): login(123, "password", "string")