def test_proposal_basic(client): u = User("[email protected]", "password") ui = UserInfo("[email protected]", 'User', 'Name', '+01234567890', 'admin') location = UserLocation(u.user_id, "IND", "KARNATAKA", "560093") p = Proposal("[email protected]", "TDD with C++", QuickProposalType(), "AABBCC") presenter = ProposalPresenter(p.id, u.user_id, True, ui.first_name, ui.last_name, location.country, location.state) state = ProposalStatus(p.id, NewProposal()) p.presenters = [presenter] p.status = state p.session_proposer = u p.lead_presenter = u u.user_info = ui u.location = location u.proposal = p db.session.add(u) db.session.add(ui) db.session.add(location) db.session.add(p) db.session.add(presenter) db.session.add(state) db.session.commit() p = User.query.filter_by(user_id="[email protected]").first().proposal assert p.status.state == NewProposal().state()
def test_basic(database): u = User(email, password) ui = UserInfo(*user_data) u.user_info = ui database.session.add(u) database.session.add(ui) database.session.commit() assert User.query.filter_by(user_id=email).first() == u
def test_basic(client): u = User('[email protected]', 'password') ui = UserInfo('[email protected]', 'User', 'Name', '+01234567890', 'admin') u.user_info = ui db.session.add(u) db.session.add(ui) db.session.commit() assert User.query.filter_by(user_id='[email protected]').first() == u
def test_userinfo_fkey(database): u = User(email, password) ui = UserInfo(*user_data) u.user_info = ui database.session.add(u) database.session.add(ui) database.session.commit() old_user = User.query.filter_by(user_id=email).first() old_user_info = old_user.user_info assert old_user_info.user_id == email
def test_userinfo_fkey(self): u = User('*****@*****.**', 'password') ui = UserInfo('[email protected]', 'User', 'Name', '+01234567890', 'admin') u.user_info = ui db.session.add(u) db.session.add(ui) db.session.commit() oldU = User.query.filter_by(user_id="*****@*****.**").first() oldUI = oldU.user_info assert oldUI.userid == "*****@*****.**"
def test_basic(self): u = User('[email protected]', 'password') ui = UserInfo('[email protected]', 'Mr.', 'User', 'Name', '', '+01234567890', 'admin' ) u.user_info = ui db.session.add(u) db.session.add(ui) db.session.commit() assert User.query.filter_by(user_id='[email protected]').first() == u
def test_userinfo_fkey(self): u = User('*****@*****.**', 'password') ui = UserInfo('[email protected]', 'Mr.', 'User', 'Name', '', '+01234567890', 'admin') u.user_info = ui db.session.add(u) db.session.add(ui) db.session.commit() oldU = User.query.filter_by(user_id="*****@*****.**").first() oldUI = oldU.user_info assert oldUI.userid == "*****@*****.**"
def test_user_basic(self): user = User('[email protected]', 'password') assert user.user_id == '[email protected]'
def test_user_short_password(): with pytest.raises(AttributeError) as ex: User(email, 'pass') assert 'Password should have at least 8 letters/numbers.' in str(ex.value)
def test_user_whitespace_user(): with pytest.raises(AttributeError) as ex: User(' ', password) assert 'Email cannot be empty' in str(ex.value)
def test_user_whitespace_password(): with pytest.raises(AttributeError) as ex: user = User('[email protected]', ' ') assert 'Password should have at least 8 letters/numbers.' in str(ex.value)
def test_user_empty_user(): with pytest.raises(AttributeError) as ex: user = User('', 'password') assert 'Email cannot be empty' in str(ex.value)
def register(): if proposals.config.get("MAINTENANCE"): return redirect(url_for("proposals.maintenance")) if request.method == "POST": # Process registration data user_email = request.form["email"] user_pass = request.form["user_pass"] first_name = request.form["firstname"] last_name = request.form["lastname"] country = request.form["country"] state = request.form["state"] phone = request.form["phone"] postal_code = request.form["pincode"] town_city = request.form['towncity'] street_address = request.form['streetaddress'] bio = request.form['bio'] encoded_pass = "" if type(user_pass) == str and len(user_pass): encoded_pass = hashlib.sha256( user_pass.encode('utf-8')).hexdigest() page = {} if not validate_email(user_email): page["title"] = "Registration failed" page["data"] = "Registration failed: Invalid/Duplicate user id." page["data"] += "Please register again" return render_template("registration_failure.html", page=page) elif not validate_password(user_pass): page["title"] = "Registration failed" page["data"] = "Registration failed: Password did not meet checks." page["data"] += "Please register again" return render_template("registration_failure.html", page=page) else: new_user = User(user_email, encoded_pass) user_info = UserInfo(new_user.user_id, first_name, last_name, phone, bio, Role.user.get("name", "user")) user_location = UserLocation(new_user.user_id, country, state, postal_code, town_city, street_address) new_user.user_info = user_info new_user.location = user_location db.session.add(new_user) db.session.add(user_info) db.session.add(user_location) db.session.commit() page["title"] = "Registration successful" page["data"] = "You have successfully registered for submitting " page["data"] += "proposals for the ACCU Conf. Please login and " page["data"] += "start preparing your proposal for the conference." return render_template("registration_success.html", page=page) elif request.method == "GET": num_a = randint(10, 99) num_b = randint(10, 99) sum = num_a + num_b question = MathPuzzle(sum) db.session.add(question) db.session.commit() return render_template( "register.html", page={ "title": "Register", "data": "Register here for submitting proposals to ACCU Conference", "question": question.id, "puzzle": "%d + %d" % (num_a, num_b) })
def test_user_whitespace_user(self): with pytest.raises(AttributeError) as ex: user = User(" ", 'password') assert "Email cannot be empty" in str(ex.value)
def test_user_basic(): user = User(email, password) assert user.user_id == email assert user.user_pass == password
def test_user_short_password(self): with pytest.raises(AttributeError) as ex: user = User("[email protected]", "pass") assert "Password should have at least 8 letters/numbers." in str( ex.value)
def test_user_null_user(): with pytest.raises(AttributeError) as ex: User(None, password) assert 'Email cannot be empty' in str(ex.value)
def register(): if app.config.get("MAINTENANCE"): return redirect(url_for("maintenance")) if request.method == "POST": # Process registration data user_email = request.form["email"] user_pass = request.form["password"] salutation = request.form["salutation"] suffix = request.form["suffix"] first_name = request.form["firstname"] last_name = request.form["lastname"] country = request.form["country"] state = request.form["state"] #states = request.form["states"] phone = request.form["phone"] postal_code = request.form["pincode"] encoded_pass = "" if type(user_pass) == str and len(user_pass): encoded_pass = hashlib.sha256(user_pass.encode('utf-8')).hexdigest() page = {} if not validateEmail(user_email): page["title"] = "Registration failed" page["data"] = "Registration failed: Invalid/Duplicate user id." page["data"] += "Please register again" return render_template("registration_failure.html", page=page) elif not validatePassword(user_pass): page["title"] = "Registration failed" page["data"] = "Registration failed: Password did not meet checks." page["data"] += "Please register again" return render_template("registration_failure.html", page=page) else: newuser = User(user_email, encoded_pass) userinfo = UserInfo(newuser.user_id, salutation, first_name, last_name, suffix, phone, Role.user.get("name", "user") ) userlocation = UserLocation(newuser.user_id, country, state, postal_code) newuser.user_info = userinfo newuser.location = userlocation db.session.add(newuser) db.session.add(userinfo) db.session.add(userlocation) db.session.commit() page["title"] = "Registration successful" page["data"] = "You have successfully registered for submitting " page["data"] += "proposals for the ACCU Conf. Please login and " page["data"] += "start preparing your proposal for the conference." return render_template("registration_success.html", page=page) elif request.method == "GET": question_id = randint(1, 1000) question = MathPuzzle.query.filter_by(id=question_id).first() register = { "title": "Register", "data": "Register here for submitting proposals to ACCU Conference", "question": question.id, "puzzle": question.question } return render_template("register.html", page=register)
def register(): if proposals.config.get("MAINTENANCE"): return redirect(url_for("proposals.maintenance")) edit_mode = False user = None if session.get("user_id", False): user = User.query.filter_by(user_id=session["user_id"]).first() if user is not None: edit_mode = True if request.method == "POST": # Process registration data if not edit_mode: # it is not allowed to change the email address at the moment, because this is used as key user_email = request.form["email"] # In case that no user pass was provided, we don't update the field user_pass = None if len(request.form["user_pass"].strip()) > 0: user_pass = request.form["user_pass"] first_name = request.form["firstname"] last_name = request.form["lastname"] country = request.form["country"] state = request.form["state"] phone = request.form["phone"] postal_code = request.form["pincode"] town_city = request.form['towncity'] street_address = request.form['streetaddress'] bio = request.form['bio'] encoded_pass = None if type(user_pass) == str and len(user_pass): encoded_pass = hashlib.sha256( user_pass.encode('utf-8')).hexdigest() page = {} if edit_mode: user.user_info.first_name = first_name user.user_info.last_name = last_name if encoded_pass: user.user_pass = encoded_pass user.user_info.phone = phone user.user_info.bio = bio user.location.country = country user.location.state = state user.location.postal_code = postal_code user.location.town_city = town_city user.location.street_address = street_address if encoded_pass: User.query.filter_by(user_id=user.user_id).update( {'user_pass': encoded_pass}) UserInfo.query.filter_by(user_id=user.user_id).update({ 'first_name': first_name, 'last_name': last_name, 'phone': phone, 'bio': bio }) UserLocation.query.filter_by(user_id=user.user_id).update({ 'country': country, 'state': state, 'postal_code': postal_code, 'town_city': town_city, 'street_address': street_address }) page["title"] = "Account update successful" page["data"] = "Your account details were successful updated." else: if not validate_email(user_email): page["title"] = "Registration failed" page[ "data"] = "Registration failed: Invalid/Duplicate user id." page["data"] += "Please register again" return render_template("registration_failure.html", page=page) elif not validate_password(user_pass): page["title"] = "Registration failed" page[ "data"] = "Registration failed: Password did not meet checks." page["data"] += "Please register again" return render_template("registration_failure.html", page=page) else: new_user = User(user_email, encoded_pass) user_info = UserInfo(new_user.user_id, first_name, last_name, phone, bio, Role.user.get("name", "user")) user_location = UserLocation(new_user.user_id, country, state, postal_code, town_city, street_address) new_user.user_info = user_info new_user.location = user_location db.session.add(new_user) db.session.add(user_info) db.session.add(user_location) page["title"] = "Registration successful" page["data"] = "You have successfully registered for submitting " page["data"] += "proposals for the ACCU Conf. Please login and " page["data"] += "start preparing your proposal for the conference." db.session.commit() return render_template("registration_success.html", page=page) elif request.method == "GET": page = {} page["mode"] = "edit_mode" if edit_mode else "register" page["email"] = user.user_id if edit_mode else "" page["first_name"] = user.user_info.first_name if edit_mode else "" page["last_name"] = user.user_info.last_name if edit_mode else "" page["phone"] = user.user_info.phone if edit_mode else "" page["bio"] = user.user_info.bio if edit_mode else "" page[ "country"] = user.location.country if edit_mode else "GBR" # UK shall be the default page["state"] = user.location.state if edit_mode else "GB-ENG" page["postal_code"] = user.location.postal_code if edit_mode else "" page["town_city"] = user.location.town_city if edit_mode else "" page[ "street_address"] = user.location.street_address if edit_mode else "" num_a = randint(10, 99) num_b = randint(10, 99) sum = num_a + num_b question = MathPuzzle(sum) db.session.add(question) db.session.commit() page["title"] = "Account Information" if edit_mode else "Register" page[ "data"] = "Here you can edit your account information" if edit_mode else "Register here for submitting proposals to ACCU Conference" page["question"] = question.id page["puzzle"] = "%d + %d" % (num_a, num_b) page["submit_button"] = "Save" if edit_mode else "Register" return render_template("register.html", page=page)