From 3d3bd917009cde7d29e558e8108a72114269d55d Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sat, 3 Apr 2021 14:06:53 -0700 Subject: [PATCH] Expand "we run" step to handling input better - Use regex parser in pytest-bdd to support "we run" steps that also have user input ("and enter") Co-authored-by: Micah Jerome Ellison --- tests/features/password.feature | 17 +++++++++++++++++ tests/step_defs/conftest.py | 6 ++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/features/password.feature b/tests/features/password.feature index 6cd2d2b6..d3116fed 100644 --- a/tests/features/password.feature +++ b/tests/features/password.feature @@ -103,3 +103,20 @@ Feature: Using the installed keyring 2013-06-09 15:39 My first entry. 2013-06-10 15:40 Life is good. + + Scenario: Mistyping your password, then getting it right + Given we use the config "simple.yaml" + When we run "jrnl --encrypt" and enter + swordfish + sordfish + swordfish + swordfish + n + Then we should be prompted for a password + And we should see the message "Passwords did not match" + And we should see the message "Journal encrypted" + And the config for journal "default" should have "encrypt" set to "bool:True" + When we run "jrnl -1" and enter "swordfish" + Then we should be prompted for a password + And the output should contain "2013-06-10 15:40 Life is good" + diff --git a/tests/step_defs/conftest.py b/tests/step_defs/conftest.py index 47aa7882..dd08502f 100644 --- a/tests/step_defs/conftest.py +++ b/tests/step_defs/conftest.py @@ -16,6 +16,7 @@ from pytest_bdd import given from pytest_bdd import then from pytest_bdd import when from pytest_bdd.parsers import parse +from pytest_bdd import parsers from pytest import fixture import toml @@ -205,11 +206,12 @@ def use_password_forever(pw): return pw +@when(parse('we run "jrnl {command}" and enter\n{user_input}')) +@when(parsers.re('we run "jrnl (?P[^"]+)" and enter "(?P[^"]+)"')) @when(parse('we run "jrnl {command}"')) +@when(parse('we run "jrnl" and enter "{user_input}"')) @when('we run "jrnl "') @when('we run "jrnl"') -@when(parse('we run "jrnl" and enter "{user_input}"')) -@when(parse('we run "jrnl {command}" and enter\n{user_input}')) def we_run(command, config_path, user_input, cli_run, capsys, password, keyring): args = split_args(command) status = 0