mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 21:18:32 +02:00
Add scenario for XML export
This commit is contained in:
parent
e24beeffd0
commit
3c1496eed2
2 changed files with 39 additions and 0 deletions
|
@ -82,3 +82,10 @@ Feature: Exporting a Journal
|
||||||
More stuff
|
More stuff
|
||||||
more stuff again
|
more stuff again
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
Scenario: Exporting to XML
|
||||||
|
Given we use the config "tags.yaml"
|
||||||
|
When we run "jrnl --export xml"
|
||||||
|
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"]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import json
|
import json
|
||||||
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
from behave import then
|
from behave import then
|
||||||
|
|
||||||
|
@ -49,3 +50,34 @@ def check_json_output_path(context, path, value):
|
||||||
struct = struct[node]
|
struct = struct[node]
|
||||||
assert struct == value, struct
|
assert struct == value, struct
|
||||||
|
|
||||||
|
|
||||||
|
@then('the output should be a valid XML string')
|
||||||
|
def assert_valid_xml_string(context):
|
||||||
|
output = context.stdout_capture.getvalue()
|
||||||
|
xml_tree = ElementTree.fromstring(output)
|
||||||
|
assert xml_tree, output
|
||||||
|
|
||||||
|
|
||||||
|
@then('"entries" node in the xml output should have {number:d} elements')
|
||||||
|
def assert_xml_output_entries_count(context, 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))
|
||||||
|
|
||||||
|
actual_entry_count = len(xml_tree.find("entries"))
|
||||||
|
assert actual_entry_count == number, actual_entry_count
|
||||||
|
|
||||||
|
|
||||||
|
@then('"tags" in the xml output should contain {expected_tags_json_list}')
|
||||||
|
def assert_xml_output_tags(context, expected_tags_json_list):
|
||||||
|
output = context.stdout_capture.getvalue()
|
||||||
|
xml_tree = ElementTree.fromstring(output)
|
||||||
|
|
||||||
|
xml_tags = (node.tag for node in xml_tree)
|
||||||
|
assert "tags" in xml_tags, str(list(xml_tags))
|
||||||
|
|
||||||
|
expected_tags = json.loads(expected_tags_json_list)
|
||||||
|
actual_tags = set(t.attrib["name"] for t in xml_tree.find("tags"))
|
||||||
|
assert actual_tags == set(expected_tags), [actual_tags, set(expected_tags)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue