diff --git a/features/data/simple_import.json b/features/data/simple_import.json new file mode 100644 index 00000000..54631c24 --- /dev/null +++ b/features/data/simple_import.json @@ -0,0 +1,15 @@ +{ + "entries" : + [ + { + "date" : "2013-06-09 15:39", + "title" : "My first entry.", + "body" : "Everything is alright" + }, + { + "date" : "2013-06-10 15:40", + "title" : "Life is good.", + "body" : "But I'm better." + } + ] +} diff --git a/features/plugins.feature b/features/plugins.feature index 8b86328b..08dabbe8 100644 --- a/features/plugins.feature +++ b/features/plugins.feature @@ -5,7 +5,7 @@ Feature: Functionality of Importer and Exporter Plugins Given We use the config "basic_onefile.yaml" When We run "jrnl --version" Then the output should contain pyproject.toml version - And The output should contain " : from jrnl..." + And the output should contain " : from jrnl..." And the output should not contain ".contrib." Examples: @@ -31,7 +31,8 @@ Feature: Functionality of Importer and Exporter Plugins Given We use the config "basic_onefile.yaml" When We run "jrnl --version" Then the output should contain pyproject.toml version - And The output should contain " : from jrnl..." + And the output should contain " : from jrnl..." + Examples: | plugin_name | version | source | type | filename | | jrnl | | plugins | importer | jrnl | @@ -65,9 +66,15 @@ Feature: Functionality of Importer and Exporter Plugins | json | | plugins | exporter | json | | txt | | plugins | exporter | text | + @skip_only_with_external_plugins + Scenario Outline: Custom JSON Import + Given we use the config "simple.yaml" + When we run "jrnl --import ./features/data/simple_import.json" + Then the journal should contain "My first entry." + And the journal should contain "Life is good." @skip_only_with_external_plugins - Scenario Outline: JSON format + Scenario Outline: Custom JSON Export Given we use the config ".yaml" And we use the password "test" if prompted When we run "jrnl --format json" @@ -79,8 +86,8 @@ Feature: Functionality of Importer and Exporter Plugins And entry 3 should not have an array "tags" Examples: configs - | config | - | basic_onefile | - | basic_encrypted | - | basic_folder | - | basic_dayone | + | config | + | basic_onefile | + | basic_encrypted | + | basic_folder | + | basic_dayone | diff --git a/jrnl/commands.py b/jrnl/commands.py index 90c01b5a..c2ab66d5 100644 --- a/jrnl/commands.py +++ b/jrnl/commands.py @@ -75,6 +75,7 @@ def postconfig_import(args, config, **kwargs): format = args.export if args.export else "jrnl" get_importer(format).import_(journal, args.filename) + journal.write() def postconfig_encrypt(args, config, original_config, **kwargs): diff --git a/jrnl/plugins/importer/jrnl.py b/jrnl/plugins/importer/jrnl.py index 07031cc3..1519e05a 100644 --- a/jrnl/plugins/importer/jrnl.py +++ b/jrnl/plugins/importer/jrnl.py @@ -37,4 +37,3 @@ class Importer(BaseImporter): ), file=sys.stderr, ) - journal.write() diff --git a/tests/external_plugins_src/jrnl/contrib/importer/simple_json.py b/tests/external_plugins_src/jrnl/contrib/importer/simple_json.py index b1d27858..a67645b6 100644 --- a/tests/external_plugins_src/jrnl/contrib/importer/simple_json.py +++ b/tests/external_plugins_src/jrnl/contrib/importer/simple_json.py @@ -27,13 +27,14 @@ class Importer(BaseImporter): data = json.loads(f) else: try: - data = sys.stdin.read() + f = sys.stdin.read() except KeyboardInterrupt: print( "[Entries NOT imported into journal.]", file=sys.stderr, ) sys.exit(0) + data = json.loads(f) for json_entry in data: raw = json_entry["title"] + "/n" + json_entry["body"]