mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
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:
parent
c76ee8cd4f
commit
e720430aa4
2 changed files with 49 additions and 7 deletions
|
@ -89,3 +89,17 @@ Feature: Using the installed keyring
|
|||
And the output should contain "Failed to retrieve keyring"
|
||||
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.
|
||||
|
||||
|
|
|
@ -118,11 +118,21 @@ def password():
|
|||
return ""
|
||||
|
||||
|
||||
@fixture
|
||||
def str_value():
|
||||
return ""
|
||||
|
||||
|
||||
@fixture
|
||||
def command():
|
||||
return ""
|
||||
|
||||
|
||||
@fixture
|
||||
def should_not():
|
||||
return False
|
||||
|
||||
|
||||
@fixture
|
||||
def user_input():
|
||||
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)
|
||||
try:
|
||||
cli(args)
|
||||
except StopIteration:
|
||||
# This happens when input is expected, but don't have any input left
|
||||
pass
|
||||
except SystemExit as e:
|
||||
status = e.code
|
||||
# fmt: on
|
||||
|
@ -308,22 +321,37 @@ def should_see_the_message(text, cli_run):
|
|||
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 "{value}"'))
|
||||
@then(parse('the config should have "{key}" set to\n{str_value}'))
|
||||
@then(parse('the config should have "{key}" set to "{str_value}"'))
|
||||
@then(
|
||||
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):
|
||||
value = read_value_from_string(value)
|
||||
@then(parse('the config should {should_not} have "{key}" set'))
|
||||
@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
|
||||
if journal_name:
|
||||
configuration = configuration["journals"][journal_name]
|
||||
|
||||
assert key in configuration
|
||||
assert configuration[key] == value
|
||||
# is the config a string?
|
||||
# @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")
|
||||
|
|
Loading…
Add table
Reference in a new issue