-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3402 from rebeccacremona/another-trap
Tweak form submission flow
- Loading branch information
Showing
11 changed files
with
139 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
def test_contact(page, urls, mailoutbox) -> None: | ||
"""The Contact form should submit""" | ||
msg = "I've got important things to say." | ||
email = "functional_test_user@example.com" | ||
|
||
page.goto(urls.contact) | ||
|
||
email_field = page.locator('#id_email') | ||
email_field.focus() | ||
email_field.type(email) | ||
message_field = page.locator('#id_box2') | ||
message_field.focus() | ||
message_field.type(msg) | ||
|
||
page.locator('.contact-form button[type=submit]').click() | ||
|
||
assert page.title() == "Perma.cc | Thanks" | ||
assert len(mailoutbox) == 1 | ||
m = mailoutbox[0] | ||
assert msg in m.body | ||
|
||
|
||
def test_contact_no_js(page, urls, mailoutbox, caplog) -> None: | ||
"""The Contact form should submit, but be rejected.""" | ||
msg = "I've got important things to say." | ||
email = "functional_test_user@example.com" | ||
|
||
page.goto(urls.contact) | ||
# Remove the form's submit event listener | ||
page.evaluate('() => {let elem = document.querySelector(".contact-form"); elem.innerHTML = elem.innerHTML;}') | ||
|
||
email_field = page.locator('#id_email') | ||
email_field.focus() | ||
email_field.type(email) | ||
message_field = page.locator('#id_box2') | ||
message_field.focus() | ||
message_field.type(msg) | ||
|
||
page.locator('.contact-form button[type=submit]').click() | ||
|
||
assert page.title() == "Perma.cc | Thanks" | ||
assert any("Suppressing invalid form submission" in msg for msg in caplog.messages) | ||
assert len(mailoutbox) == 0 | ||
|
||
|
||
def test_contact_no_js_logged_in(logged_in_user, urls, mailoutbox, caplog) -> None: | ||
"""The Contact form should submit, and not be rejected despite no JS.""" | ||
msg = "I've got important things to say." | ||
|
||
logged_in_user.goto(urls.contact) | ||
# Remove the form's submit event listener | ||
logged_in_user.evaluate('() => {let elem = document.querySelector(".contact-form"); elem.innerHTML = elem.innerHTML;}') | ||
|
||
message_field = logged_in_user.locator('#id_box2') | ||
message_field.focus() | ||
message_field.type(msg) | ||
|
||
logged_in_user.locator('.contact-form button[type=submit]').click() | ||
|
||
assert len(mailoutbox) == 1 | ||
m = mailoutbox[0] | ||
assert msg in m.body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.