diff --git a/features/config.feature b/features/config.feature index bae84618..cd974e09 100644 --- a/features/config.feature +++ b/features/config.feature @@ -9,3 +9,16 @@ Feature: Reading & writing the config file And one editor argument should be "-c" And one editor argument should match "'?setf markdown'?" + Scenario: Invalid color configuration + Given we use the config "invalid_color.yaml" + When we run "jrnl -on 2013-06-10 -s" + Then the output should be + """ + 2013-06-10 15:40 Life is good. + """ + And we should get no error + And the error output should contain + """ + body set to invalid color + """ + diff --git a/features/contains.feature b/features/contains.feature deleted file mode 100644 index 7ecf405f..00000000 --- a/features/contains.feature +++ /dev/null @@ -1,29 +0,0 @@ -Feature: Contains - - Scenario: Searching for a string - Given we use the config "basic.yaml" - When we run "jrnl -contains life" - Then we should get no error - And the output should be - """ - 2013-06-10 15:40 Life is good. - | But I'm better. - """ - - Scenario: Searching for a string within tag results - Given we use the config "tags.yaml" - When we run "jrnl @idea -contains software" - Then we should get no error - And the output should contain "software" - - Scenario: Searching for a string within AND tag results - Given we use the config "tags.yaml" - When we run "jrnl -and @journal @idea -contains software" - Then we should get no error - And the output should contain "software" - - Scenario: Searching for a string within NOT tag results - Given we use the config "tags.yaml" - When we run "jrnl -not @dan -contains software" - Then we should get no error - And the output should contain "software" diff --git a/features/core.feature b/features/core.feature index 1cb8aa95..b9a35a4d 100644 --- a/features/core.feature +++ b/features/core.feature @@ -1,52 +1,4 @@ -Feature: Basic reading and writing to a journal - - Scenario: Loading a sample journal - Given we use the config "basic.yaml" - When we run "jrnl -n 2" - Then we should get no error - And the output should be - """ - 2013-06-09 15:39 My first entry. - | Everything is alright - - 2013-06-10 15:40 Life is good. - | But I'm better. - """ - - Scenario: Printing a journal that has multiline entries - Given we use the config "multiline.yaml" - When we run "jrnl -n 1" - Then we should get no error - And the output should be - """ - 2013-06-09 15:39 Multiple line entry. - | This is the first line. - | This line doesn't have any ending punctuation - | - | There is a blank line above this. - """ - - Scenario: Filtering for dates - Given we use the config "basic.yaml" - When we run "jrnl -on 2013-06-10 --short" - Then the output should be "2013-06-10 15:40 Life is good." - When we run "jrnl -on 'june 6 2013' --short" - Then the output should be "2013-06-10 15:40 Life is good." - - Scenario: Emoji support - Given we use the config "basic.yaml" - When we run "jrnl 23 july 2013: 🌞 sunny day. Saw an 🐘" - Then we should see the message "Entry added" - When we run "jrnl -n 1" - Then the output should contain "🌞" - And the output should contain "🐘" - - Scenario: Writing an entry at the prompt - Given we use the config "basic.yaml" - When we run "jrnl" and enter "25 jul 2013: I saw Elvis. He's alive." - Then we should get no error - And the journal should contain "[2013-07-25 09:00] I saw Elvis." - And the journal should contain "He's alive." +Feature: Core functionality of jrnl outside of actually handling journals Scenario: Displaying the version number Given we use the config "basic.yaml" @@ -64,21 +16,6 @@ Feature: Basic reading and writing to a journal When we run "jrnl -on 2013-06-10 -s" Then the output should be "2013-06-10 15:40 Life is good." - Scenario: Invalid color configuration - Given we use the config "invalid_color.yaml" - When we run "jrnl -on 2013-06-10 -s" - Then the output should be - """ - 2013-06-10 15:40 Life is good. - """ - And we should get no error - - Scenario: Journal directory does not exist - Given we use the config "missing_directory.yaml" - When we run "jrnl Life is good" - And we run "jrnl -n 1" - Then the output should contain "Life is good" - Scenario: Installation with relative journal and referencing from another folder Given we use the config "missingconfig" When we run "jrnl hello world" and enter diff --git a/features/data/configs/missing_directory.yaml b/features/data/configs/missing_directory.yaml new file mode 100644 index 00000000..d600404c --- /dev/null +++ b/features/data/configs/missing_directory.yaml @@ -0,0 +1,17 @@ +default_hour: 9 +default_minute: 0 +editor: "" +encrypt: false +highlight: true +journals: + default: features/journals/missing_directory/simple.journal +linewrap: 80 +tagsymbols: "@" +template: false +timeformat: "%Y-%m-%d %H:%M" +indent_character: "|" +colors: + date: none + title: none + body: none + tags: none diff --git a/features/data/configs/missing_journal.yaml b/features/data/configs/missing_journal.yaml new file mode 100644 index 00000000..a1f6f8cf --- /dev/null +++ b/features/data/configs/missing_journal.yaml @@ -0,0 +1,17 @@ +default_hour: 9 +default_minute: 0 +editor: "" +encrypt: false +highlight: true +journals: + default: features/journals/missing.journal +linewrap: 80 +tagsymbols: "@" +template: false +timeformat: "%Y-%m-%d %H:%M" +indent_character: "|" +colors: + date: none + title: none + body: none + tags: none diff --git a/features/dates.feature b/features/dates.feature index c7606695..f1b2ebde 100644 --- a/features/dates.feature +++ b/features/dates.feature @@ -70,3 +70,18 @@ Feature: Reading and writing to journal with custom date formats When we run "jrnl -1" Then the output should contain "friday at 9am" in the local time + Scenario: Journals with unreadable dates should still be loaded + Given we use the config "unreadabledates.yaml" + When we run "jrnl -2" + Then the output should contain "I've lost track of time." + And the output should contain "Time has no meaning." + + Scenario: Journals with readable dates AND unreadable dates should still contain all data. + Given we use the config "mostlyreadabledates.yaml" + When we run "jrnl -3" + Then the output should contain "Time machines are possible." + When we run "jrnl -1" + Then the output should contain "I'm going to activate the machine." + And the output should contain "I've crossed so many timelines. Is there any going back?" + + diff --git a/features/encryption.feature b/features/encryption.feature index cc79b8f5..fc25661a 100644 --- a/features/encryption.feature +++ b/features/encryption.feature @@ -1,103 +1,35 @@ - Feature: Encrypting and decrypting journals +Feature: Encrypting and decrypting journals - Scenario: Loading an encrypted journal - Given we use the config "encrypted.yaml" - When we run "jrnl -n 1" and enter "bad doggie no biscuit" - Then we should be prompted for a password - And the output should contain "2013-06-10 15:40 Life is good" + Scenario: Decrypting a journal + Given we use the config "encrypted.yaml" + When we run "jrnl --decrypt" and enter "bad doggie no biscuit" + Then the config for journal "default" should have "encrypt" set to "bool:False" + And we should see the message "Journal decrypted" + And the journal should have 2 entries - Scenario: Decrypting a journal - Given we use the config "encrypted.yaml" - When we run "jrnl --decrypt" and enter "bad doggie no biscuit" - Then the config for journal "default" should have "encrypt" set to "bool:False" - And we should see the message "Journal decrypted" - And the journal should have 2 entries + @todo + Scenario: Trying to decrypt an already unencrypted journal + # This should warn the user that the journal is already encrypted + Given we use the config "basic.yaml" + When we run "jrnl --decrypt" + Then the config for journal "default" should have "encrypt" set to "bool:False" + And the journal should have 2 entries - Scenario: Trying to decrypt an unencrypted journal - Given we use the config "basic.yaml" - When we run "jrnl --decrypt" - Then the config for journal "default" should have "encrypt" set to "bool:False" - And we should get no error - And the journal should have 2 entries + @todo + Scenario: Trying to encrypt an already encrypted journal + # This should warn the user that the journal is already encrypted - Scenario: Encrypting a journal - Given we use the config "basic.yaml" - When we run "jrnl --encrypt" and enter - """ - swordfish - swordfish - n - """ - Then we should see the message "Journal encrypted" - And the config for journal "default" should have "encrypt" set to "bool:True" - When we run "jrnl -n 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" + Scenario: Encrypting a journal + Given we use the config "basic.yaml" + When we run "jrnl --encrypt" and enter + """ + swordfish + swordfish + n + """ + Then we should see the message "Journal encrypted" + And the config for journal "default" should have "encrypt" set to "bool:True" + When we run "jrnl -n 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" - Scenario: Mistyping your password - Given we use the config "basic.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 - And the journal should have 2 entries - - Scenario: Mistyping your password, then getting it right - Given we use the config "basic.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 -n 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" - - Scenario: Storing a password in keyring - Given we use the config "multiple.yaml" - And we have a keyring - When we run "jrnl simple --encrypt" and enter - """ - sabertooth - sabertooth - y - """ - Then the config for journal "simple" should have "encrypt" set to "bool:True" - When we run "jrnl simple -n 1" - Then the output should contain "2013-06-10 15:40 Life is good" - But the output should not contain "Password" - - Scenario: Encrypt journal with no keyring backend and do not store in keyring - Given we use the config "basic.yaml" - And we do not have a keyring - When we run "jrnl test entry" - And we run "jrnl --encrypt" and enter - """ - password - password - n - """ - Then we should get no error - - Scenario: Encrypt journal with no keyring backend and do store in keyring - Given we use the config "basic.yaml" - And we do not have a keyring - When we run "jrnl test entry" - And we run "jrnl --encrypt" and enter - """ - password - password - y - """ - Then we should get no error diff --git a/features/exporting.feature b/features/formats.feature similarity index 98% rename from features/exporting.feature rename to features/formats.feature index fc22a4bb..7482bcea 100644 --- a/features/exporting.feature +++ b/features/formats.feature @@ -1,6 +1,6 @@ -Feature: Exporting a Journal +Feature: Custom formats - Scenario: Exporting to json + Scenario: JSON format Given we use the config "tags.yaml" When we run "jrnl --export json" Then we should get no error @@ -75,6 +75,7 @@ Feature: Exporting a Journal ####### ATX H4 + ######## ATX H5 ######### ATX H6 @@ -91,7 +92,7 @@ Feature: Exporting a Journal # https://github.com/jrnl-org/jrnl/issues/768 # https://github.com/jrnl-org/jrnl/issues/881 Given we use the config "deletion.yaml" - When we run "jrnl --export markdown" + When we run "jrnl --format markdown" Then the output should be """ # 2019 diff --git a/features/dayone.feature b/features/journaltype_dayone.feature similarity index 100% rename from features/dayone.feature rename to features/journaltype_dayone.feature diff --git a/features/journaltype_default.feature b/features/journaltype_default.feature new file mode 100644 index 00000000..50a31c8f --- /dev/null +++ b/features/journaltype_default.feature @@ -0,0 +1,51 @@ +Feature: Loading the default journal type + + Scenario: Loading a sample journal + Given we use the config "basic.yaml" + When we run "jrnl -2" + Then we should get no error + And the output should be + """ + 2013-06-09 15:39 My first entry. + | Everything is alright + + 2013-06-10 15:40 Life is good. + | But I'm better. + """ + + Scenario: Printing a journal that has multiline entries + Given we use the config "multiline.yaml" + When we run "jrnl -n 1" + Then we should get no error + And the output should be + """ + 2013-06-09 15:39 Multiple line entry. + | This is the first line. + | This line doesn't have any ending punctuation + | + | There is a blank line above this. + """ + + Scenario: Integers in square brackets should not be read as dates + Given we use the config "brackets.yaml" + When we run "jrnl -1" + Then the output should contain "[1] line starting with 1" + + + Scenario: If the journal and it's parent directory don't exist, they should be created + Given we use the config "missing_directory.yaml" + Then the journal should not exist + When we run "jrnl This is a new entry in my journal" + Then the journal should exist + When we run "jrnl -n 1" + Then the output should contain "This is a new entry in my journal" + And the journal should have 1 entry + + Scenario: If the journal file doesn't exist, then it should be created + Given we use the config "missing_journal.yaml" + Then the journal should not exist + When we run "jrnl This is a new entry in my journal" + Then the journal should exist + When we run "jrnl -n 1" + Then the output should contain "This is a new entry in my journal" + And the journal should have 1 entry diff --git a/features/folder.feature b/features/journaltype_directory.feature similarity index 100% rename from features/folder.feature rename to features/journaltype_directory.feature diff --git a/features/journaltype_encrypted.feature b/features/journaltype_encrypted.feature new file mode 100644 index 00000000..e6fb5cfd --- /dev/null +++ b/features/journaltype_encrypted.feature @@ -0,0 +1,37 @@ +Feature: Loading the encrypted journal type + + Scenario: Loading an encrypted journal + Given we use the config "encrypted.yaml" + When we run "jrnl -n 1" and enter "bad doggie no biscuit" + Then we should be prompted for a password + And the output should contain "2013-06-10 15:40 Life is good" + + Scenario: Mistyping your password + Given we use the config "basic.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 + And the journal should have 2 entries + + Scenario: Mistyping your password, then getting it right + Given we use the config "basic.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 -n 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/features/keyring.feature b/features/keyring.feature new file mode 100644 index 00000000..f29d72eb --- /dev/null +++ b/features/keyring.feature @@ -0,0 +1,47 @@ +Feature: Using the installed keyring + + Scenario: Storing a password in keyring + Given we use the config "multiple.yaml" + And we have a keyring + When we run "jrnl simple --encrypt" and enter + """ + sabertooth + sabertooth + y + """ + Then the config for journal "simple" should have "encrypt" set to "bool:True" + When we run "jrnl simple -n 1" + Then the output should contain "2013-06-10 15:40 Life is good" + But the output should not contain "Password" + + Scenario: Encrypt journal with no keyring backend and do not store in keyring + Given we use the config "basic.yaml" + And we do not have a keyring + When we run "jrnl test entry" + And we run "jrnl --encrypt" and enter + """ + password + password + n + """ + Then we should get no error + + Scenario: Encrypt journal with no keyring backend and do store in keyring + Given we use the config "basic.yaml" + And we do not have a keyring + When we run "jrnl test entry" + And we run "jrnl --encrypt" and enter + """ + password + password + y + """ + Then we should get no error + + @todo + Scenario: Open an encrypted journal with wrong password in keyring + # This should ask the user for the password after the keyring fails + + @todo + Scenario: Open encrypted journal when keyring exists but fails + # This should ask the user for the password after the keyring fails diff --git a/features/loading.feature b/features/loading.feature deleted file mode 100644 index 9044ea6e..00000000 --- a/features/loading.feature +++ /dev/null @@ -1,21 +0,0 @@ -Feature: Loading a journal from a file - - Scenario: Integers in square brackets should not be read as dates - Given we use the config "brackets.yaml" - When we run "jrnl -1" - Then the output should contain "[1] line starting with 1" - - Scenario: Journals with unreadable dates should still be loaded - Given we use the config "unreadabledates.yaml" - When we run "jrnl -2" - Then the output should contain "I've lost track of time." - And the output should contain "Time has no meaning." - - Scenario: Journals with readable dates AND unreadable dates should still contain all data. - Given we use the config "mostlyreadabledates.yaml" - When we run "jrnl -3" - Then the output should contain "Time machines are possible." - When we run "jrnl -1" - Then the output should contain "I'm going to activate the machine." - And the output should contain "I've crossed so many timelines. Is there any going back?" - diff --git a/features/searching.feature b/features/searching.feature index e718af0e..e2fdd138 100644 --- a/features/searching.feature +++ b/features/searching.feature @@ -1,4 +1,4 @@ -Feature: Searching a journal +Feature: Searching in a journal Scenario: Displaying entries using -on today should display entries created today. Given we use the config "basic.yaml" @@ -6,6 +6,8 @@ Feature: Searching a journal Then we should see the message "Entry added" When we run "jrnl -on today" Then the output should contain "Adding an entry right now." + But the output should not contain "Everything is alright" + And the output should not contain "Life is good" Scenario: Displaying entries using -from day should display correct entries Given we use the config "basic.yaml" @@ -32,3 +34,39 @@ Feature: Searching a journal Then the output should contain "This thing happened yesterday" And the output should contain "Adding an entry right now." And the output should not contain "A future entry." + + Scenario: Searching for a string + Given we use the config "basic.yaml" + When we run "jrnl -contains life" + Then we should get no error + And the output should be + """ + 2013-06-10 15:40 Life is good. + | But I'm better. + """ + + Scenario: Searching for a string within tag results + Given we use the config "tags.yaml" + When we run "jrnl @idea -contains software" + Then we should get no error + And the output should contain "software" + + Scenario: Searching for a string within AND tag results + Given we use the config "tags.yaml" + When we run "jrnl -and @journal @idea -contains software" + Then we should get no error + And the output should contain "software" + + Scenario: Searching for a string within NOT tag results + Given we use the config "tags.yaml" + When we run "jrnl -not @dan -contains software" + Then we should get no error + And the output should contain "software" + + Scenario: Searching for dates + Given we use the config "basic.yaml" + When we run "jrnl -on 2013-06-10 --short" + Then the output should be "2013-06-10 15:40 Life is good." + When we run "jrnl -on 'june 6 2013' --short" + Then the output should be "2013-06-10 15:40 Life is good." + diff --git a/features/steps/core.py b/features/steps/core.py index 4aadc897..5117dd5f 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -73,7 +73,6 @@ class FailedKeyring(keyring.backend.KeyringBackend): priority = 2 keys = defaultdict(dict) - def set_password(self, servicename, username, password): self.keys[servicename][username] = password @@ -116,27 +115,27 @@ def read_value_from_string(string): # Takes strings like "bool:true" or "int:32" and coerces them into proper type t, value = string.split(":") - value = {"bool": lambda v: v.lower() == "true", "int": int, "str": str}[t]( - value - ) + value = {"bool": lambda v: v.lower() == "true", "int": int, "str": str}[t](value) return value + @given('we use the config "{config_file}"') def set_config(context, config_file): full_path = os.path.join("features/configs", config_file) + install.CONFIG_FILE_PATH = os.path.abspath(full_path) - if config_file.endswith("yaml"): + if config_file.endswith("yaml") and os.path.exists(full_path): # Add jrnl version to file for 2.x journals with open(install.CONFIG_FILE_PATH, "a") as cf: cf.write("version: {}".format(__version__)) -@given('we have a keyring') +@given("we have a keyring") def set_keyring(context): keyring.set_keyring(TestKeyring()) -@given('we do not have a keyring') +@given("we do not have a keyring") def disable_keyring(context): keyring.core.set_keyring(NoKeyring()) @@ -342,7 +341,7 @@ def load_template(context, filename): @when('we set the keyring password of "{journal}" to "{password}"') -def set_keyring(context, journal, password): +def set_keyring_password(context, journal, password): keyring.set_password("jrnl", journal, password) @@ -439,6 +438,7 @@ def check_not_journal_content(context, text, journal_name="default"): assert text not in journal, journal +@then('the journal should not exist') @then('journal "{journal_name}" should not exist') def journal_doesnt_exist(context, journal_name="default"): config = load_config(install.CONFIG_FILE_PATH) @@ -446,6 +446,13 @@ def journal_doesnt_exist(context, journal_name="default"): journal_path = config["journals"][journal_name] assert not os.path.exists(journal_path) +@then('the journal should exist') +@then('journal "{journal_name}" should exist') +def journal_exists(context, journal_name="default"): + config = load_config(install.CONFIG_FILE_PATH) + + journal_path = config["journals"][journal_name] + assert os.path.exists(journal_path) @then('the config should have "{key}" set to') @then('the config should have "{key}" set to "{value}"') @@ -462,7 +469,7 @@ def config_var(context, key, value="", journal=None): @then('the config for journal "{journal}" should not have "{key}" set') -def config_var(context, key, value="", journal=None): +def config_no_var(context, key, value="", journal=None): config = load_config(install.CONFIG_FILE_PATH) if journal: diff --git a/features/writing.feature b/features/writing.feature index 7c278b94..b3a28d32 100644 --- a/features/writing.feature +++ b/features/writing.feature @@ -55,3 +55,17 @@ Feature: Writing new entries. | Hope to get a lot of traffic. """ + Scenario: Emoji support + Given we use the config "basic.yaml" + When we run "jrnl 23 july 2013: 🌞 sunny day. Saw an 🐘" + Then we should see the message "Entry added" + When we run "jrnl -n 1" + Then the output should contain "🌞" + And the output should contain "🐘" + + Scenario: Writing an entry at the prompt (no editor) + Given we use the config "basic.yaml" + When we run "jrnl" and enter "25 jul 2013: I saw Elvis. He's alive." + Then we should get no error + And the journal should contain "[2013-07-25 09:00] I saw Elvis." + And the journal should contain "He's alive."