Skip to content

Commit

Permalink
Added test for incorrect OTP
Browse files Browse the repository at this point in the history
  • Loading branch information
djamg committed Nov 22, 2023
1 parent 5d95cbb commit 50a78e8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/e2e/account/register_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test account registration."""
# pylint: disable=redefined-outer-name

import random
import re

import pytest
Expand Down Expand Up @@ -219,3 +220,35 @@ def then_submit_recaptcha_validation_passes(live_server, page: Page) -> None:
page.click('#use-password-login')
page.wait_for_selector('input[name=password]').fill(TWOFLOWER_PASSWORD)
page.click('#login-btn')


@given("Twoflower visitor is on the login page")
def given_twoflower_visits_login_page(
user_twoflower_with_password_and_contact,
published_project,
db_session,
live_server,
page: Page,
) -> None:
page.goto(live_server.url + 'login')


@when("they enter an twoflower's email address")
def when_enter_twoflower_email(page: Page) -> None:
page.wait_for_selector('input[name=username]').fill(TWOFLOWER_EMAIL)
page.click('#get-otp-btn')


@when("they enter the wrong OTP")
def when_enter_wrong_otp(page: Page) -> None:
page.wait_for_selector('input[name=otp]').fill(
str(random.randint(1000, 9999)) # nosec
)
page.click('#form-otp button')


@then("they are prompted to enter the OTP again")
def then_prompted_enter_otp_again(page: Page) -> None:
page.wait_for_selector('input[name=otp]')
assert page.wait_for_selector('.alert__text').inner_text() == "Invalid OTP"
# TODO: Fix the assert for the right element
6 changes: 6 additions & 0 deletions tests/features/account/register.feature
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ Feature: Account creation
When twoflower visits the login page, Recaptcha is required
Then they submit and Recaptcha validation passes
And they are logged in

Scenario: Twoflower tries to login with an email address and the wrong OTP
Given Twoflower visitor is on the login page
When they enter an twoflower's email address
And they enter the wrong OTP
Then they are prompted to enter the OTP again

0 comments on commit 50a78e8

Please sign in to comment.