Déclaration d’une première adresse email sur un compte existant (#79801) #112
|
@ -12,8 +12,15 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p>{% blocktrans trimmed with email=user.email %}Your current email is {{ email }}.
|
||||
An email will be sent to validate the new one.{% endblocktrans %}</p>
|
||||
{% with email=user.email %}
|
||||
{% if email %}
|
||||
<p>{% blocktrans trimmed %}Your current email is {{ email }}.
|
||||
An email will be sent to validate the new one.{% endblocktrans %}</p>
|
||||
{% else %}
|
||||
<p>{% blocktrans trimmed %}Your account currently doesn't declare any email address.
|
||||
An email will be sent at the address declared here, in order to validate it.{% endblocktrans %}</p>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
<form method="post" class="pk-mark-optional-fields">
|
||||
{% csrf_token %}
|
||||
{{ form|with_template }}
|
||||
|
|
|
@ -21,6 +21,10 @@ def change_email(app, user, email, mailoutbox):
|
|||
utils.login(app, user)
|
||||
l = len(mailoutbox)
|
||||
response = app.get('/accounts/change-email/')
|
||||
if not user.email:
|
||||
assert "Your account currently doesn't declare any email address." in response.text
|
||||
else:
|
||||
assert f'Your current email is {user.email}.' in response.text
|
||||
response.form.set('email', email)
|
||||
response.form.set('password', user.username)
|
||||
response = response.form.submit()
|
||||
|
@ -51,6 +55,29 @@ def test_change_email(app, simple_user, user_ou1, mailoutbox):
|
|||
assert simple_user.email == user_ou1.email
|
||||
|
||||
|
||||
def test_declare_first_email(app, nomail_user, user_ou1, mailoutbox):
|
||||
email = change_email(app, nomail_user, user_ou1.email, mailoutbox)
|
||||
utils.assert_event(
|
||||
'user.email.change.request',
|
||||
user=nomail_user,
|
||||
session=app.session,
|
||||
old_email=nomail_user.email,
|
||||
email=user_ou1.email,
|
||||
)
|
||||
link = utils.get_link_from_mail(email)
|
||||
app.get(link)
|
||||
utils.assert_event(
|
||||
'user.email.change',
|
||||
user=nomail_user,
|
||||
session=app.session,
|
||||
old_email=nomail_user.email,
|
||||
email=user_ou1.email,
|
||||
)
|
||||
nomail_user.refresh_from_db()
|
||||
# ok it worked
|
||||
assert nomail_user.email == user_ou1.email
|
||||
|
||||
|
||||
def test_change_email_email_is_unique(app, settings, simple_user, user_ou1, mailoutbox):
|
||||
settings.A2_EMAIL_IS_UNIQUE = True
|
||||
email = change_email(app, simple_user, user_ou1.email, mailoutbox)
|
||||
|
|
Loading…
Reference in New Issue