mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 21:18:32 +02:00
add test, refactor solution
This commit is contained in:
parent
2bafc8023b
commit
2181d84545
2 changed files with 28 additions and 14 deletions
|
@ -1,6 +1,5 @@
|
|||
Feature: Upgrading Journals from 1.x.x to 2.x.x
|
||||
|
||||
@skip_win
|
||||
Scenario: Upgrade and parse journals with square brackets
|
||||
Given we use the config "upgrade_from_195.json"
|
||||
When we run "jrnl -9" and enter "Y"
|
||||
|
@ -12,7 +11,6 @@ Feature: Upgrading Journals from 1.x.x to 2.x.x
|
|||
"""
|
||||
Then the journal should have 2 entries
|
||||
|
||||
@skip_win
|
||||
Scenario: Upgrading a journal encrypted with jrnl 1.x
|
||||
Given we use the config "encrypted_old.json"
|
||||
When we run "jrnl -n 1" and enter
|
||||
|
@ -24,7 +22,6 @@ Feature: Upgrading Journals from 1.x.x to 2.x.x
|
|||
Then the output should contain "Password"
|
||||
and the output should contain "2013-06-10 15:40 Life is good"
|
||||
|
||||
@skip_win
|
||||
Scenario: Upgrade and parse journals with little endian date format
|
||||
Given we use the config "upgrade_from_195_little_endian_dates.json"
|
||||
When we run "jrnl -9" and enter "Y"
|
||||
|
@ -36,15 +33,21 @@ Feature: Upgrading Journals from 1.x.x to 2.x.x
|
|||
"""
|
||||
Then the journal should have 2 entries
|
||||
|
||||
@skip_win
|
||||
Scenario: Successful upgrade with missing journal
|
||||
Scenario: Upgrade with missing journal
|
||||
Given we use the config "upgrade_from_195_with_missing_journal.json"
|
||||
When we run "jrnl -ls" and enter "Y Y"
|
||||
Then we should see the message "Journal 'missing' created"
|
||||
Then we should see the message "We're all done here"
|
||||
When we run "jrnl -ls" and enter
|
||||
""""
|
||||
Y
|
||||
"""
|
||||
Then the output should contain "Error: features/journals/missing.journal does not exist."
|
||||
|
||||
@skip_win
|
||||
Scenario: Aborted upgrade with missing journal
|
||||
Given we use the config "upgrade_from_195_with_missing_journal.json"
|
||||
When we run "jrnl -ls" and enter "Y N"
|
||||
Then we should see the message "jrnl NOT upgraded, exiting."
|
||||
Scenario: Upgrade with missing encrypted journal
|
||||
Given we use the config "upgrade_from_195_with_missing_encrypted_journal.json"
|
||||
When we run "jrnl -ls" and enter
|
||||
"""
|
||||
Y
|
||||
bad doggie no biscuit
|
||||
bad doggie no biscuit
|
||||
"""
|
||||
Then the output should contain "Error: features/journals/missing.journal does not exist."
|
||||
and the output should contain "We're all done here"
|
|
@ -29,6 +29,13 @@ def backup(filename, binary=False):
|
|||
raise UserAbort("jrnl NOT upgraded, exiting.")
|
||||
|
||||
|
||||
def check_exists(path):
|
||||
"""
|
||||
Checks if a given path exists.
|
||||
"""
|
||||
return os.path.exists(path)
|
||||
|
||||
|
||||
def upgrade_jrnl_if_necessary(config_path):
|
||||
with open(config_path, "r", encoding="utf-8") as f:
|
||||
config_file = f.read()
|
||||
|
@ -68,7 +75,11 @@ older versions of jrnl anymore.
|
|||
encrypt = config.get("encrypt")
|
||||
path = journal_conf
|
||||
|
||||
if os.path.exists(os.path.expanduser(path)):
|
||||
path = os.path.expanduser(path)
|
||||
else:
|
||||
print(f"\nError: {path} does not exist.")
|
||||
continue
|
||||
|
||||
if encrypt:
|
||||
encrypted_journals[journal_name] = path
|
||||
|
|
Loading…
Add table
Reference in a new issue