def test_registration_procedure(testapp, login_as, parse_latest_mail): response = testapp.get("/", status=302).follow(status=200) assert "Please Log In" in response response = testapp.get("/registration", status=200) assert "Register a new account" in response form = response.form form["user_name"] = "TestNew" form["first_name"] = "Eric" form["last_name"] = "Idle" form["email"] = "eric@example.com" form["password"] = "eric" response = form.submit("Create_Account").follow() assert "The account needs to be activated" in response response = login_as("TestNew", "eric") assert "Credentials are invalid" in response login_as("TestAdmin", "jane") response = testapp.get("/users/?role=new", status=200) assert "TestNew" in response response = testapp.get("/users/TestNew/edit", status=200) assert "Edit User" in response form = response.forms[1] form["role"].select(text="User") response = form.submit("Save_Changes").follow() assert "TestNew" in response response = testapp.get("/users/?role=new", status=200) assert "TestNew" not in response response = testapp.get("/users/?role=user", status=200) assert "TestNew" in response parsed = parse_latest_mail() assert "Your account was activated" in parsed.body response = login_as("TestNew", "eric").follow(status=200) assert "My Orders" in response def test_registration_procedure_form_error( testapp, login_as, parse_latest_mail ): response = testapp.get("/", status=302).follow(status=200) assert "Please Log In" in response response = testapp.get("/registration", status=200) assert "Register a new account" in response form = response.form response = form.submit("Create_Account") assert "There was a problem with your submission" in response def test_registration_procedure_not_unique_username( testapp, login_as, parse_latest_mail ): response = testapp.get("/", status=302).follow(status=200) assert "Please Log In" in response response = testapp.get("/registration", status=200) assert "Register a new account" in response form = response.form form["user_name"] = "TestAdmin" form["first_name"] = "Eric" form["last_name"] = "Idle" form["email"] = "eric@example.com" form["password"] = "eric" response = form.submit("Create_Account") assert "There was a problem with your submission" in response def test_registration_procedure_not_unique_email( testapp, login_as, parse_latest_mail ): response = testapp.get("/", status=302).follow(status=200) assert "Please Log In" in response response = testapp.get("/registration", status=200) assert "Register a new account" in response form = response.form form["user_name"] = "TestNew" form["first_name"] = "Eric" form["last_name"] = "Idle" form["email"] = "jane@example.com" form["password"] = "eric" response = form.submit("Create_Account") assert "There was a problem with your submission" in response def test_registration_procedure_bad_csrf_token( testapp, login_as, parse_latest_mail ): response = testapp.get("/", status=302).follow(status=200) assert "Please Log In" in response response = testapp.get("/registration", status=200) assert "Register a new account" in response form = response.form form["csrf_token"] = "bad token" form["user_name"] = "TestNew" form["first_name"] = "Eric" form["last_name"] = "Idle" form["email"] = "eric@example.com" form["password"] = "eric" form.submit("Create_Account", status=400) def test_registration_procedure_canceled(testapp, login_as, parse_latest_mail): response = testapp.get("/", status=302).follow(status=200) assert "Please Log In" in response response = testapp.get("/registration", status=200) assert "Register a new account" in response form = response.form form["user_name"] = "TestNew" form["first_name"] = "Eric" form["last_name"] = "Idle" form["email"] = "eric@example.com" form["password"] = "eric" response = form.submit("Cancel").follow(status=302).follow(status=200) assert "Please Log In" in response