user can update profile
This commit is contained in:
parent
ec7504fb20
commit
f3c3332127
@ -1,5 +1,6 @@
|
|||||||
from flask import Blueprint, render_template, g, redirect, session, url_for, request
|
from flask import Blueprint, render_template, g, redirect, url_for, request as http_request
|
||||||
from atst.forms.edit_user import EditUserForm
|
from atst.forms.edit_user import EditUserForm
|
||||||
|
from atst.domain.users import Users
|
||||||
|
|
||||||
|
|
||||||
bp = Blueprint("users", __name__)
|
bp = Blueprint("users", __name__)
|
||||||
@ -14,4 +15,11 @@ def user():
|
|||||||
|
|
||||||
@bp.route("/user", methods=["POST"])
|
@bp.route("/user", methods=["POST"])
|
||||||
def update_user():
|
def update_user():
|
||||||
return redirect(url_for(".home"))
|
user = g.current_user
|
||||||
|
form = EditUserForm(http_request.form)
|
||||||
|
if form.validate():
|
||||||
|
Users.update(user, form.data)
|
||||||
|
return redirect(url_for("atst.home"))
|
||||||
|
else:
|
||||||
|
return render_template("user/edit.html", form=form, user=user)
|
||||||
|
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
{% from "components/options_input.html" import OptionsInput %}
|
{% from "components/options_input.html" import OptionsInput %}
|
||||||
{% from "components/date_input.html" import DateInput %}
|
{% from "components/date_input.html" import DateInput %}
|
||||||
|
|
||||||
<form action='{{ form_action }}'>
|
<form method="POST" action='{{ form_action }}'>
|
||||||
|
{{ form.csrf_token }}
|
||||||
<div class='panel'>
|
<div class='panel'>
|
||||||
<div class='panel__content'>
|
<div class='panel__content'>
|
||||||
<div class='form-row'>
|
<div class='form-row'>
|
||||||
|
@ -48,6 +48,17 @@ class UserFactory(Base):
|
|||||||
last_name = factory.Faker("last_name")
|
last_name = factory.Faker("last_name")
|
||||||
atat_role = factory.SubFactory(RoleFactory)
|
atat_role = factory.SubFactory(RoleFactory)
|
||||||
dod_id = factory.LazyFunction(lambda: "".join(random.choices(string.digits, k=10)))
|
dod_id = factory.LazyFunction(lambda: "".join(random.choices(string.digits, k=10)))
|
||||||
|
phone_number = factory.LazyFunction(
|
||||||
|
lambda: "".join(random.choices(string.digits, k=10))
|
||||||
|
)
|
||||||
|
service_branch = factory.LazyFunction(
|
||||||
|
lambda: random.choices([k for k, v in SERVICE_BRANCHES if k is not None])[0]
|
||||||
|
)
|
||||||
|
citizenship = "United States"
|
||||||
|
designation = "military"
|
||||||
|
date_latest_training = factory.LazyFunction(
|
||||||
|
lambda: datetime.date.today() + datetime.timedelta(days=-(random.randrange(1,365)))
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_atat_role(cls, atat_role_name, **kwargs):
|
def from_atat_role(cls, atat_role_name, **kwargs):
|
||||||
|
22
tests/routes/test_users.py
Normal file
22
tests/routes/test_users.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from flask import url_for
|
||||||
|
|
||||||
|
from atst.domain.users import Users
|
||||||
|
|
||||||
|
from tests.factories import UserFactory
|
||||||
|
|
||||||
|
def test_user_can_view_profile(user_session, client):
|
||||||
|
user = UserFactory.create()
|
||||||
|
user_session(user)
|
||||||
|
response = client.get(url_for("users.user"))
|
||||||
|
assert user.email in response.data.decode()
|
||||||
|
|
||||||
|
|
||||||
|
def test_user_can_update_profile(user_session, client):
|
||||||
|
user = UserFactory.create()
|
||||||
|
user_session(user)
|
||||||
|
new_data = {**user.to_dictionary(), "first_name": "chad", "last_name": "vader"}
|
||||||
|
new_data["date_latest_training"] = new_data["date_latest_training"].strftime("%m/%d/%Y")
|
||||||
|
client.post(url_for("users.user"), data=new_data)
|
||||||
|
updated_user = Users.get_by_dod_id(user.dod_id)
|
||||||
|
assert updated_user.first_name == "chad"
|
||||||
|
assert updated_user.last_name == "vader"
|
Loading…
x
Reference in New Issue
Block a user