From ced121edc522fe681d4d8fab7861455f3e0d8252 Mon Sep 17 00:00:00 2001 From: = Date: Sat, 30 May 2020 18:12:37 -0400 Subject: [PATCH 1/6] tag array for json --- jrnl/plugins/json_exporter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jrnl/plugins/json_exporter.py b/jrnl/plugins/json_exporter.py index a5c70b979..a5f581722 100644 --- a/jrnl/plugins/json_exporter.py +++ b/jrnl/plugins/json_exporter.py @@ -20,6 +20,7 @@ def entry_to_dict(cls, entry): "body": entry.body, "date": entry.date.strftime("%Y-%m-%d"), "time": entry.date.strftime("%H:%M"), + "tags": entry.tags, "starred": entry.starred, } if hasattr(entry, "uuid"): From e134f0161fe67448df73b99a315916c70b9ff0f2 Mon Sep 17 00:00:00 2001 From: = Date: Sat, 30 May 2020 18:41:15 -0400 Subject: [PATCH 2/6] add tags to entry in xml --- jrnl/plugins/xml_exporter.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jrnl/plugins/xml_exporter.py b/jrnl/plugins/xml_exporter.py index 065c929bb..4ffcc7319 100644 --- a/jrnl/plugins/xml_exporter.py +++ b/jrnl/plugins/xml_exporter.py @@ -35,6 +35,11 @@ def entry_to_xml(cls, entry, doc): if hasattr(entry, "uuid"): entry_el.setAttribute("uuid", entry.uuid) entry_el.setAttribute("starred", entry.starred) + tags = entry.tags + for tag in tags: + tag_el = doc.createElement("tag") + tag_el.setAttribute("name", tag) + entry_el.appendChild(tag_el) entry_el.appendChild(doc.createTextNode(entry.fulltext)) return entry_el From 951a4a3dbb67a038473da50bedf1a6cf94448770 Mon Sep 17 00:00:00 2001 From: = Date: Sat, 30 May 2020 19:05:06 -0400 Subject: [PATCH 3/6] xml test --- features/exporting.feature | 1 + features/steps/export_steps.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/features/exporting.feature b/features/exporting.feature index 7f4df59f9..ec21432d5 100644 --- a/features/exporting.feature +++ b/features/exporting.feature @@ -89,6 +89,7 @@ Feature: Exporting a Journal Then the output should be a valid XML string And "entries" node in the xml output should have 2 elements And "tags" in the xml output should contain ["@idea", "@journal", "@dan"] + And there should be 7 "tag" elements Scenario: Exporting tags Given we use the config "tags.yaml" diff --git a/features/steps/export_steps.py b/features/steps/export_steps.py index 0aa180fdc..a6c471774 100644 --- a/features/steps/export_steps.py +++ b/features/steps/export_steps.py @@ -60,17 +60,23 @@ def assert_valid_xml_string(context): assert xml_tree, output -@then('"entries" node in the xml output should have {number:d} elements') -def assert_xml_output_entries_count(context, number): +@then('"{item}" node in the xml output should have {number:d} elements') +def assert_xml_output_entries_count(context, item, number): output = context.stdout_capture.getvalue() xml_tree = ElementTree.fromstring(output) xml_tags = (node.tag for node in xml_tree) - assert "entries" in xml_tags, str(list(xml_tags)) + assert item in xml_tags, str(list(xml_tags)) - actual_entry_count = len(xml_tree.find("entries")) + actual_entry_count = len(xml_tree.find(item)) assert actual_entry_count == number, actual_entry_count +@then('there should be {number:d} "{item}" elements') +def count_elements(context,number,item): + output = context.stdout_capture.getvalue() + xml_tree = ElementTree.fromstring(output) + assert len(xml_tree.findall(".//"+item))==number + @then('"tags" in the xml output should contain {expected_tags_json_list}') def assert_xml_output_tags(context, expected_tags_json_list): From 8e3a616413264aff1ce3a9d7789410707698f3c5 Mon Sep 17 00:00:00 2001 From: = Date: Sat, 30 May 2020 19:14:23 -0400 Subject: [PATCH 4/6] json test --- features/exporting.feature | 2 ++ features/steps/export_steps.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/features/exporting.feature b/features/exporting.feature index ec21432d5..da6d8ce96 100644 --- a/features/exporting.feature +++ b/features/exporting.feature @@ -9,6 +9,8 @@ Feature: Exporting a Journal And "tags" in the json output should contain "@idea" And "tags" in the json output should contain "@journal" And "tags" in the json output should contain "@dan" + And entry 1 should have an array called "tags" with 2 elements + And entry 2 should have an array called "tags" with 2 elements Scenario: Exporting using filters should only export parts of the journal Given we use the config "tags.yaml" diff --git a/features/steps/export_steps.py b/features/steps/export_steps.py index a6c471774..c200e9adc 100644 --- a/features/steps/export_steps.py +++ b/features/steps/export_steps.py @@ -52,6 +52,12 @@ def check_json_output_path(context, path, value): struct = struct[node] assert struct == value, struct +@then('entry {entry_number:d} should have an array called "{name}" with {items_number:d} elements') +def entry_array_count(context,entry_number,name,items_number): + #note that entry_number is 1-indexed. + out = context.stdout_capture.getvalue() + out_json = json.loads(out) + assert len(out_json["entries"][entry_number-1][name])==items_number @then("the output should be a valid XML string") def assert_valid_xml_string(context): From 4bf75653ab5974911edfcbbae89cf256834e69ff Mon Sep 17 00:00:00 2001 From: = Date: Sat, 30 May 2020 19:15:20 -0400 Subject: [PATCH 5/6] black --- features/steps/export_steps.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/features/steps/export_steps.py b/features/steps/export_steps.py index c200e9adc..093adfaa8 100644 --- a/features/steps/export_steps.py +++ b/features/steps/export_steps.py @@ -52,12 +52,16 @@ def check_json_output_path(context, path, value): struct = struct[node] assert struct == value, struct -@then('entry {entry_number:d} should have an array called "{name}" with {items_number:d} elements') -def entry_array_count(context,entry_number,name,items_number): - #note that entry_number is 1-indexed. + +@then( + 'entry {entry_number:d} should have an array called "{name}" with {items_number:d} elements' +) +def entry_array_count(context, entry_number, name, items_number): + # note that entry_number is 1-indexed. out = context.stdout_capture.getvalue() out_json = json.loads(out) - assert len(out_json["entries"][entry_number-1][name])==items_number + assert len(out_json["entries"][entry_number - 1][name]) == items_number + @then("the output should be a valid XML string") def assert_valid_xml_string(context): @@ -77,11 +81,12 @@ def assert_xml_output_entries_count(context, item, number): actual_entry_count = len(xml_tree.find(item)) assert actual_entry_count == number, actual_entry_count + @then('there should be {number:d} "{item}" elements') -def count_elements(context,number,item): +def count_elements(context, number, item): output = context.stdout_capture.getvalue() xml_tree = ElementTree.fromstring(output) - assert len(xml_tree.findall(".//"+item))==number + assert len(xml_tree.findall(".//" + item)) == number @then('"tags" in the xml output should contain {expected_tags_json_list}') From 575e32666c04146915ce573857d17c443a4b528c Mon Sep 17 00:00:00 2001 From: = Date: Sat, 6 Jun 2020 19:10:58 -0400 Subject: [PATCH 6/6] removed called --- features/exporting.feature | 4 ++-- features/steps/export_steps.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/features/exporting.feature b/features/exporting.feature index da6d8ce96..96a9558f1 100644 --- a/features/exporting.feature +++ b/features/exporting.feature @@ -9,8 +9,8 @@ Feature: Exporting a Journal And "tags" in the json output should contain "@idea" And "tags" in the json output should contain "@journal" And "tags" in the json output should contain "@dan" - And entry 1 should have an array called "tags" with 2 elements - And entry 2 should have an array called "tags" with 2 elements + And entry 1 should have an array "tags" with 2 elements + And entry 2 should have an array "tags" with 2 elements Scenario: Exporting using filters should only export parts of the journal Given we use the config "tags.yaml" diff --git a/features/steps/export_steps.py b/features/steps/export_steps.py index 093adfaa8..ce7fdbc93 100644 --- a/features/steps/export_steps.py +++ b/features/steps/export_steps.py @@ -54,7 +54,7 @@ def check_json_output_path(context, path, value): @then( - 'entry {entry_number:d} should have an array called "{name}" with {items_number:d} elements' + 'entry {entry_number:d} should have an array "{name}" with {items_number:d} elements' ) def entry_array_count(context, entry_number, name, items_number): # note that entry_number is 1-indexed.