add tests

This commit is contained in:
dbxnr 2020-02-11 22:46:35 +00:00
parent 774355971a
commit 16a4e60582
4 changed files with 20 additions and 14 deletions

View file

@ -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"
}

View file

@ -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.
"""

View file

@ -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(

View file

@ -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)