From 16a4e60582e8dd5a18af87133a42d93515f1641c Mon Sep 17 00:00:00 2001 From: dbxnr Date: Tue, 11 Feb 2020 22:46:35 +0000 Subject: [PATCH] add tests --- features/data/journals/dayone2.json | 2 +- features/dayone2.feature | 20 +++++++++++++------- jrnl/plugins/dayone2_importer.py | 3 ++- jrnl/plugins/util.py | 9 ++++----- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/features/data/journals/dayone2.json b/features/data/journals/dayone2.json index 4f3ff20e..ab9ba24f 100644 --- a/features/data/journals/dayone2.json +++ b/features/data/journals/dayone2.json @@ -16,7 +16,7 @@ "photos": [], "starred": true, "tags": [], - "text": "Entry Number Two.\n\nAnd a bit of text over here.", + "text": "Entry Number Two.\n\nWith some body.", "timeZone": "Europe/London", "uuid": "EC61E5D4E66C44E6AC796E863E8BF7E7" } diff --git a/features/dayone2.feature b/features/dayone2.feature index fdc1e346..9ec5ccdb 100644 --- a/features/dayone2.feature +++ b/features/dayone2.feature @@ -13,15 +13,21 @@ Feature: Day One 2.0 implementation details. Then we should get no error and the output should contain "not the expected Day One 2 format." - Scenario: Verify conversion to jrnl + Scenario: Converted journal is added to config Given we use the config "basic.yaml" When we run "jrnl --import dayone2 features/data/journals/dayone2.json" When we run "jrnl -ls" - Then the output should be - """ - 2013-06-09 15:39 My first entry. - | Everything is alright + Then the output should contain "dayone2.txt" + And the output should contain "default" - 2013-06-10 15:40 Life is good. - | But I'm better. + Scenario: Converted journal is validated + Given we use the config "basic.yaml" + When we run "jrnl --import dayone2 features/data/journals/dayone2.json" + When we run "jrnl dayone2 -n 10" + Then the output should contain + """ + 10-01-2020 12:21 Entry Number Two. + | With some body. + + 10-01-2020 12:22 Entry Number One. """ \ No newline at end of file diff --git a/jrnl/plugins/dayone2_importer.py b/jrnl/plugins/dayone2_importer.py index 5afd131b..cb921805 100644 --- a/jrnl/plugins/dayone2_importer.py +++ b/jrnl/plugins/dayone2_importer.py @@ -10,7 +10,7 @@ class DayOne2Importer(JSONImporter): extension = "json" def __init__(self, path): - self.type = "DayOne2" + self.type = "dayone2" self.path = path self.keys = [ "audios", @@ -42,6 +42,7 @@ class DayOne2Importer(JSONImporter): def parse_json(self): entries = [] + print(self.json) for entry in self.json["entries"]: entries.append( Entry( diff --git a/jrnl/plugins/util.py b/jrnl/plugins/util.py index c0bc43fc..4303d175 100644 --- a/jrnl/plugins/util.py +++ b/jrnl/plugins/util.py @@ -2,8 +2,9 @@ # encoding: utf-8 import yaml +from jrnl.install import CONFIG_FILE_PATH, save_config from jrnl.util import load_config -from jrnl.install import CONFIG_FILE_PATH, CONFIG_FILE_PATH_FALLBACK +from pathlib import Path def get_tags_count(journal): @@ -34,9 +35,7 @@ def add_journal_to_config(name, path): try: data = load_config(CONFIG_FILE_PATH) except FileNotFoundError: - try: - data = load_config(CONFIG_FILE_PATH_FALLBACK) - except FileNotFoundError: - print("Config file not found.") + print("Config file not found.") finally: data["journals"][name] = path + save_config(data)