def post(self, request): first_name = request.POST['name'] last_name = request.POST['lastName'] user_name = request.POST['user_name'] user_id = request.POST['user_id'] number = request.POST['phone_number'] role = request.POST['role'] assignment_id = request.POST['assignment_id'] email = request.POST['email'] password = request.POST['password'] user = User(first_name=first_name, user_name=user_name, last_name=last_name, password=password, user_id=user_id, number=number, role=role, assignment_ID=assignment_id, email=email) error_dict = [] error_dict = validate_user(user) valid = ["User successfully created"] if not error_dict: try: user.save() except IntegrityError: error_dict.append("user_name / user_id already exists") return render(request, "create_user.html", {"errors": error_dict}) else: return render(request, "create_user.html", {"errors": valid}) else: return render(request, "create_user.html", {"errors": error_dict})
def test_no_email(self): user = User(first_name="test", last_name="last test", id="badger", number="414", role="Supervisor", assignment_ID="42", email="",user_id="lucky") self.assertEqual(["Enter a valid email"], validate_user(user))
def test_no_role(self): user = User(first_name="test", last_name="last test", id="badger", number="414", role="", assignment_ID="42", email="*****@*****.**",user_id="lucky") self.assertEqual(["User must be given a role"], validate_user(user))
def test_no_number(self): user = User(first_name="test", last_name="last test", id="badger", number="", role="Supervisor", assignment_ID="42", email="*****@*****.**",user_id="lucky") self.assertEqual(["Please enter a valid phone number"], validate_user(user))
def test_no_lastname(self): user = User(first_name="test", last_name="", id="badger", number="414", role="Supervisor", assignment_ID="42", email="*****@*****.**",user_id="lucky") self.assertEqual(["Last name can't be empty"], validate_user(user))
def test_good_input(self): user = User(first_name="test", last_name="last test", id="badger", number="414", role="Supervisor", assignment_ID="42", email="*****@*****.**", user_id="lucky") self.assertEqual([], validate_user(user))