From 50a78e8acba70afc9895268d1c384fb258fd36f7 Mon Sep 17 00:00:00 2001 From: Amogh M Aradhya Date: Wed, 22 Nov 2023 13:43:23 +0530 Subject: [PATCH] Added test for incorrect OTP --- tests/e2e/account/register_test.py | 33 +++++++++++++++++++++++++ tests/features/account/register.feature | 6 +++++ 2 files changed, 39 insertions(+) diff --git a/tests/e2e/account/register_test.py b/tests/e2e/account/register_test.py index cabce120c..3762b6f32 100644 --- a/tests/e2e/account/register_test.py +++ b/tests/e2e/account/register_test.py @@ -1,6 +1,7 @@ """Test account registration.""" # pylint: disable=redefined-outer-name +import random import re import pytest @@ -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 diff --git a/tests/features/account/register.feature b/tests/features/account/register.feature index dd9d37bba..e8ef5f3d5 100644 --- a/tests/features/account/register.feature +++ b/tests/features/account/register.feature @@ -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