Implement "should" and "should not" handling

- Handling should and should not like this should reduce the amount of
  fixtures we need for the test suite
- Add more password tests

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
This commit is contained in:
Jonathan Wren 2021-03-20 15:52:23 -07:00
parent c76ee8cd4f
commit e720430aa4
2 changed files with 49 additions and 7 deletions

View file

@ -89,3 +89,17 @@ Feature: Using the installed keyring
And the output should contain "Failed to retrieve keyring" And the output should contain "Failed to retrieve keyring"
And the output should contain "2013-06-10 15:40 Life is good" And the output should contain "2013-06-10 15:40 Life is good"
Scenario: Mistyping your password
Given we use the config "simple.yaml"
When we run "jrnl --encrypt" and enter
swordfish
sordfish
Then we should be prompted for a password
And we should see the message "Passwords did not match"
And the config for journal "default" should not have "encrypt" set
When we run "jrnl --short"
Then the output should be
2013-06-09 15:39 My first entry.
2013-06-10 15:40 Life is good.

View file

@ -118,11 +118,21 @@ def password():
return "" return ""
@fixture
def str_value():
return ""
@fixture @fixture
def command(): def command():
return "" return ""
@fixture
def should_not():
return False
@fixture @fixture
def user_input(): def user_input():
return "" return ""
@ -225,6 +235,9 @@ def we_run(command, config_path, user_input, cli_run, capsys, password, keyring)
: # @TODO: single point of truth for get_config_path (move from all calls from install to config) : # @TODO: single point of truth for get_config_path (move from all calls from install to config)
try: try:
cli(args) cli(args)
except StopIteration:
# This happens when input is expected, but don't have any input left
pass
except SystemExit as e: except SystemExit as e:
status = e.code status = e.code
# fmt: on # fmt: on
@ -308,22 +321,37 @@ def should_see_the_message(text, cli_run):
assert text in out, [text, out] assert text in out, [text, out]
@then(parse('the config should have "{key}" set to\n{value}')) @then(parse('the config should have "{key}" set to\n{str_value}'))
@then(parse('the config should have "{key}" set to "{value}"')) @then(parse('the config should have "{key}" set to "{str_value}"'))
@then( @then(
parse( parse(
'the config for journal "{journal_name}" should have "{key}" set to "{value}"' 'the config for journal "{journal_name}" should have "{key}" set to "{str_value}"'
) )
) )
def config_var(config_data, key, value, journal_name): @then(parse('the config should {should_not} have "{key}" set'))
value = read_value_from_string(value) @then(parse('the config should {should_not} have "{key}" set'))
@then(
parse(
'the config for journal "{journal_name}" should {should_not} have "{key}" set'
)
)
def config_var(config_data, key, str_value, journal_name, should_not):
str_value = read_value_from_string(str_value) if len(str_value) else str_value
configuration = config_data configuration = config_data
if journal_name: if journal_name:
configuration = configuration["journals"][journal_name] configuration = configuration["journals"][journal_name]
assert key in configuration # is the config a string?
assert configuration[key] == value # @todo this should probably be a function
if type(configuration) is str:
configuration = {"journal": configuration}
if should_not:
assert key not in configuration
else:
assert key in configuration
assert configuration[key] == str_value
@then("we should be prompted for a password") @then("we should be prompted for a password")