def test_get_user_integer_as_email(self): with self.assertRaises( TypeError, msg= "The get_user() function must take an email as its only parameter" ): get_user(123)
def test_get_user_email_with_space(self): with self.assertRaises( TypeError, msg= "The get_user() function must take an email as its only parameter" ): get_user("instructor@uwm. edu")
def test_get_user_without_at_symbol(self): with self.assertRaises( TypeError, msg= "The ger_user() function must take an email as its only parameter" ): get_user("instructoruwm.edu")
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 get(self, request): ValidSession = validate_session(request) if not ValidSession: return redirect("/") request.session['submitted'] = False accounts = MyUser.objects.all() email = request.session['name'] user = get_user(email) skills = user.skills.all() return render(request, "account.html", { "accounts": accounts, "skills": skills })
def test_get_user_too_many_arguments(self): with self.assertRaises( TypeError, msg="The get_user() function must only take one email parameter" ): get_user("*****@*****.**", "string2")
def test_get_user_no_arguments(self): with self.assertRaises( TypeError, msg="The get_user() function must take an email parameter"): get_user()
def test_get_user_doesnt_exist(self): self.assertIsNone( get_user('*****@*****.**'), msg="Nonexistent user should yield a None return type")
def test_get_user_from_ta(self): self.assertEqual( get_user('*****@*****.**'), self.user1, msg="Incorrect user object was obtained from the email")
def test_get_user_from_instructor(self): self.assertEqual( get_user('*****@*****.**'), self.user3, msg="Incorrect user object was obtained from the email")
def test_get_user_from_supervisor(self): self.assertEqual( get_user('*****@*****.**'), self.user2, msg="Incorrect user object was obtained from the email")
def post(self, request): request.session['submitted'] = True if request.method == 'POST' and 'create_butt' in request.POST: email = request.session['name'] user = get_user(email) skills = user.skills.all() accounts = MyUser.objects.all() user = request.POST['user'] user = MyUser(user) email = request.POST['email'] password = request.POST['password'] first_name = request.POST['first_name'] last_name = request.POST['last_name'] address = request.POST['address'] phone_number = request.POST['phone_number'] role = request.POST['role'] user.email = email user.password = password user.first_name = first_name user.last_name = last_name user.address = address user.phone_number = phone_number user.role = role message = CreateAccountsFunction(user.email, user.phone_number) request.session['error'] = True if message == "Valid": user.save() message = "Updated account successfully." request.session['error'] = False return render(request, "account.html", { "accounts": accounts, "skills": skills, "message": message }) if request.method == 'POST' and 'add_skill' in request.POST: email = request.session['name'] user = get_user(email) skills = user.skills.all() accounts = MyUser.objects.all() skill_exists = True input = request.POST['skill'] already_have = True try: Skill.objects.get(name=input) except: skill_exists = False try: skills.get(name=input) except: already_have = False request.session['error'] = False if not skill_exists: new_skill = Skill(name=input) new_skill.save() user.skills.add(new_skill) skills = user.skills.all() return render( request, "account.html", { "message": "New skill was added.", "accounts": accounts, "skills": skills }) if not already_have: skill_to_add = Skill.objects.filter(name=input) user.skills.add(skill_to_add) skills = user.skills.all() return render( request, "account.html", { "accounts": accounts, "skills": skills, "message": "New skill was added." }) else: request.session['error'] = True return render( request, "account.html", { "accounts": accounts, "skills": skills, "message": "You already have this skill!" })