diff --git a/tests/features/delete.feature b/tests/features/delete.feature index 2fc3f8f7..0613c826 100644 --- a/tests/features/delete.feature +++ b/tests/features/delete.feature @@ -1,229 +1,53 @@ Feature: Delete entries from journal Scenario Outline: Delete flag allows deletion of single entry - Given we use the config ".yaml" + Given we use the config "" And we use the password "test" if prompted When we run "jrnl -1" Then the output should contain "2020-09-24 09:14 The third entry finally" When we run "jrnl --delete" and enter - """ - N - N - Y - """ - Then we flush the output + N + N + Y When we run "jrnl -99 --short" Then the output should be - """ - 2020-08-29 11:11 Entry the first. - 2020-08-31 14:32 A second entry in what I hope to be a long series. - """ + 2020-08-29 11:11 Entry the first. + 2020-08-31 14:32 A second entry in what I hope to be a long series. Examples: Configs - | config | - | basic_onefile | - | basic_encrypted | - # | basic_folder | @todo - # | basic_dayone | @todo - + | config_file | + | basic_onefile.yaml | + | basic_encrypted.yaml | + # | basic_folder.yaml | @todo + # | basic_dayone.yaml | @todo + Scenario Outline: Backing out of interactive delete does not change journal - Given we use the config ".yaml" + Given we use the config "" When we run "jrnl --delete -n 1" and enter - """ - N - """ - Then we flush the output + N When we run "jrnl -99 --short" Then the output should be - """ - 2020-08-29 11:11 Entry the first. - 2020-08-31 14:32 A second entry in what I hope to be a long series. - 2020-09-24 09:14 The third entry finally after weeks without writing. - """ + 2020-08-29 11:11 Entry the first. + 2020-08-31 14:32 A second entry in what I hope to be a long series. + 2020-09-24 09:14 The third entry finally after weeks without writing. Examples: Configs - | config | - | basic_onefile | - | basic_folder | - | basic_dayone | - + | config_file | + | basic_onefile.yaml | + | basic_folder.yaml | + | basic_dayone.yaml | + Scenario Outline: Delete flag with nonsense input deletes nothing (issue #932) - Given we use the config ".yaml" + Given we use the config "" When we run "jrnl --delete asdfasdf" - Then we flush the output When we run "jrnl -99 --short" Then the output should be - """ - 2020-08-29 11:11 Entry the first. - 2020-08-31 14:32 A second entry in what I hope to be a long series. - 2020-09-24 09:14 The third entry finally after weeks without writing. - """ + 2020-08-29 11:11 Entry the first. + 2020-08-31 14:32 A second entry in what I hope to be a long series. + 2020-09-24 09:14 The third entry finally after weeks without writing. Examples: Configs - | config | - | basic_onefile | - | basic_folder | - | basic_dayone | - - Scenario Outline: Delete flag with tag only deletes tagged entries - Given we use the config ".yaml" - When we run "jrnl --delete @ipsum" and enter - """ - Y - """ - Then we flush the output - When we run "jrnl -99 --short" - Then the output should be - """ - 2020-08-31 14:32 A second entry in what I hope to be a long series. - 2020-09-24 09:14 The third entry finally after weeks without writing. - """ - - Examples: Configs - | config | - | basic_onefile | - # | basic_folder | @todo - # | basic_dayone | @todo - - - Scenario Outline: Delete flag with multiple tags deletes all entries matching any of the tags - Given we use the config ".yaml" - When we run "jrnl --delete @ipsum @tagthree" and enter - """ - Y - Y - """ - Then we flush the output - When we run "jrnl -99 --short" - Then the output should be - """ - 2020-08-31 14:32 A second entry in what I hope to be a long series. - """ - - Examples: Configs - | config | - | basic_onefile | - # | basic_folder | @todo - # | basic_dayone | @todo - - Scenario Outline: Delete flag with -and deletes boolean AND of tagged entries - Given we use the config ".yaml" - When we run "jrnl --delete -and @tagone @tagtwo" and enter - """ - Y - """ - Then we flush the output - When we run "jrnl -99 --short" - Then the output should be - """ - 2020-08-31 14:32 A second entry in what I hope to be a long series. - 2020-09-24 09:14 The third entry finally after weeks without writing. - """ - - Examples: Configs - | config | - | basic_onefile | - # | basic_folder | @todo - # | basic_dayone | @todo - - Scenario Outline: Delete flag with -not does not delete entries from given tag - Given we use the config ".yaml" - When we run "jrnl --delete @tagone -not @ipsum" and enter - """ - Y - """ - Then we flush the output - When we run "jrnl -99 --short" - Then the output should be - """ - 2020-08-29 11:11 Entry the first. - 2020-08-31 14:32 A second entry in what I hope to be a long series. - """ - - Examples: Configs - | config | - | basic_onefile | - # | basic_folder | @todo - # | basic_dayone | @todo - - Scenario Outline: Delete flag with -from search operator only deletes entries since that date - Given we use the config ".yaml" - When we run "jrnl --delete -from 2020-09-01" and enter - """ - Y - """ - Then we flush the output - When we run "jrnl -99 --short" - Then the output should be - """ - 2020-08-29 11:11 Entry the first. - 2020-08-31 14:32 A second entry in what I hope to be a long series. - """ - - Examples: Configs - | config | - | basic_onefile | - # | basic_folder | @todo - # | basic_dayone | @todo - - Scenario Outline: Delete flag with -to only deletes entries up to specified date - Given we use the config ".yaml" - When we run "jrnl --delete -to 2020-08-31" and enter - """ - Y - Y - """ - Then we flush the output - When we run "jrnl -99 --short" - Then the output should be - """ - 2020-09-24 09:14 The third entry finally after weeks without writing. - """ - - Examples: Configs - | config | - | basic_onefile | - # | basic_folder | @todo - # | basic_dayone | @todo - - - Scenario Outline: Delete flag with -starred only deletes starred entries - Given we use the config ".yaml" - When we run "jrnl --delete -starred" and enter - """ - Y - """ - Then we flush the output - When we run "jrnl -99 --short" - Then the output should be - """ - 2020-08-29 11:11 Entry the first. - 2020-09-24 09:14 The third entry finally after weeks without writing. - """ - - Examples: Configs - | config | - | basic_onefile | - # | basic_folder | @todo - # | basic_dayone | @todo - - Scenario Outline: Delete flag with -contains only entries containing expression - Given we use the config ".yaml" - When we run "jrnl --delete -contains dignissim" and enter - """ - Y - """ - Then we flush the output - When we run "jrnl -99 --short" - Then the output should be - """ - 2020-08-31 14:32 A second entry in what I hope to be a long series. - 2020-09-24 09:14 The third entry finally after weeks without writing. - """ - - Examples: Configs - | config | - | basic_onefile | - # | basic_folder | @todo - # | basic_dayone | @todo - + | config_file | + | basic_onefile.yaml | + | basic_folder.yaml | + | basic_dayone.yaml | \ No newline at end of file diff --git a/tests/step_defs/conftest.py b/tests/step_defs/conftest.py index 4933a3eb..2f81cd02 100644 --- a/tests/step_defs/conftest.py +++ b/tests/step_defs/conftest.py @@ -46,6 +46,10 @@ def toml_version(working_dir): pyproject_contents = toml.load(pyproject) return pyproject_contents["tool"]["poetry"]["version"] +@fixture +def password(): + return '' + @fixture def command(): @@ -56,7 +60,6 @@ def command(): def user_input(): return '' - # ----- STEPS ----- # @given(parse('we use the config "{config_file}"'), target_fixture="config_path") @given('we use the config ""', target_fixture="config_path") @@ -85,11 +88,17 @@ def we_use_the_config(config_file, temp_dir, working_dir): return config_dest +@given(parse('we use the password "{pw}" if prompted'), target_fixture="password") +def use_password_forever(pw): + return pw + + @when(parse('we run "jrnl {command}"')) @when('we run "jrnl "') @when('we run "jrnl"') @when(parse('we run "jrnl" and enter "{user_input}"')) -def we_run(command, config_path, user_input, cli_run, capsys): +@when(parse('we run "jrnl {command}" and enter\n{user_input}')) +def we_run(command, config_path, user_input, cli_run, capsys, password): args = split_args(command) status = 0 @@ -97,7 +106,9 @@ def we_run(command, config_path, user_input, cli_run, capsys): # see: https://github.com/psf/black/issues/664 with \ patch("sys.argv", ['jrnl'] + args), \ - patch("sys.stdin.read", return_value=user_input) as mock_read, \ + patch("sys.stdin.read", side_effect=user_input.splitlines()) as mock_read, \ + patch("builtins.input", side_effect=user_input.splitlines()) as mock_read, \ + patch("getpass.getpass", side_effect=password.splitlines()) as mock_getpass, \ patch("jrnl.install.get_config_path", return_value=config_path), \ patch("jrnl.config.get_config_path", return_value=config_path) \ : # @TODO: single point of truth for get_config_path (move from all calls from install to config) diff --git a/tests/step_defs/test_features.py b/tests/step_defs/test_features.py index 5426d0c0..6afd5c84 100644 --- a/tests/step_defs/test_features.py +++ b/tests/step_defs/test_features.py @@ -3,7 +3,7 @@ from pytest_bdd import scenarios scenarios("../features/build.feature") scenarios("../features/core.feature") scenarios("../features/datetime.feature") -# scenarios("../features/delete.feature") +scenarios("../features/delete.feature") # scenarios("../features/encrypt.feature") # scenarios("../features/file_storage.feature") # scenarios("../features/format.feature")