mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Implement JSON tests and remove "node" nomenclature from tests
Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
This commit is contained in:
parent
48c9d9fa16
commit
430182a0a5
2 changed files with 32 additions and 15 deletions
|
@ -7,15 +7,15 @@ Feature: Custom formats
|
||||||
Then we should get no error
|
Then we should get no error
|
||||||
And the output should be valid JSON
|
And the output should be valid JSON
|
||||||
Given we parse the output as JSON
|
Given we parse the output as JSON
|
||||||
Then "entries" node in the parsed output should have 3 elements
|
Then "entries" in the parsed output should have 3 elements
|
||||||
And "tags" in the parsed output should be
|
And "tags" in the parsed output should be
|
||||||
@ipsum
|
@ipsum
|
||||||
@tagone
|
@tagone
|
||||||
@tagtwo
|
@tagtwo
|
||||||
@tagthree
|
@tagthree
|
||||||
And entry 1 should have an array "tags" with 3 elements
|
And "entries.0.tags" in the parsed output should have 3 elements
|
||||||
And entry 2 should have an array "tags" with 1 elements
|
And "entries.1.tags" in the parsed output should have 1 elements
|
||||||
And entry 3 should have an array "tags" with 2 elements
|
And "entries.2.tags" in the parsed output should have 2 elements
|
||||||
|
|
||||||
Examples: configs
|
Examples: configs
|
||||||
| config_file |
|
| config_file |
|
||||||
|
@ -24,12 +24,14 @@ Feature: Custom formats
|
||||||
| basic_folder.yaml |
|
| basic_folder.yaml |
|
||||||
| basic_dayone.yaml |
|
| basic_dayone.yaml |
|
||||||
|
|
||||||
Scenario: Exporting dayone to json
|
Scenario: Exporting dayone to json should include UUID
|
||||||
Given we use the config "dayone.yaml"
|
Given we use the config "dayone.yaml"
|
||||||
When we run "jrnl --export json"
|
When we run "jrnl --export json"
|
||||||
Then we should get no error
|
Then we should get no error
|
||||||
And the output should be valid JSON
|
And the output should be valid JSON
|
||||||
And the json output should contain entries.0.uuid = "4BB1F46946AD439996C9B59DE7C4DDC1"
|
Given we parse the output as JSON
|
||||||
|
Then "entries.0.uuid" in the parsed output should be
|
||||||
|
4BB1F46946AD439996C9B59DE7C4DDC1
|
||||||
|
|
||||||
Scenario Outline: Printing a journal that has multiline entries with tags
|
Scenario Outline: Printing a journal that has multiline entries with tags
|
||||||
Given we use the config "<config_file>"
|
Given we use the config "<config_file>"
|
||||||
|
@ -248,7 +250,7 @@ Feature: Custom formats
|
||||||
And we use the password "test" if prompted
|
And we use the password "test" if prompted
|
||||||
When we run "jrnl --export xml"
|
When we run "jrnl --export xml"
|
||||||
Then the output should be a valid XML string
|
Then the output should be a valid XML string
|
||||||
And "entries" node in the xml output should have 3 elements
|
And "entries" in the xml output should have 3 elements
|
||||||
And "tags" in the xml output should contain
|
And "tags" in the xml output should contain
|
||||||
@ipsum
|
@ipsum
|
||||||
@tagone
|
@tagone
|
||||||
|
@ -269,7 +271,7 @@ Feature: Custom formats
|
||||||
When we run "jrnl --export xml"
|
When we run "jrnl --export xml"
|
||||||
Then the output should be valid XML
|
Then the output should be valid XML
|
||||||
Given we parse the output as XML
|
Given we parse the output as XML
|
||||||
Then "entries" node in the parsed output should have 2 elements
|
Then "entries" in the parsed output should have 2 elements
|
||||||
And "tags" in the parsed output should be
|
And "tags" in the parsed output should be
|
||||||
@idea
|
@idea
|
||||||
@journal
|
@journal
|
||||||
|
|
|
@ -480,7 +480,7 @@ def parse_output_as_language(cli_run, language_name):
|
||||||
return {"lang": language_name, "obj": parsed_output}
|
return {"lang": language_name, "obj": parsed_output}
|
||||||
|
|
||||||
|
|
||||||
@then(parse('"{node_name}" node in the parsed output should have {number:d} elements'))
|
@then(parse('"{node_name}" in the parsed output should have {number:d} elements'))
|
||||||
def assert_parsed_output_item_count(node_name, number, parsed_output):
|
def assert_parsed_output_item_count(node_name, number, parsed_output):
|
||||||
lang = parsed_output["lang"]
|
lang = parsed_output["lang"]
|
||||||
obj = parsed_output["obj"]
|
obj = parsed_output["obj"]
|
||||||
|
@ -493,14 +493,23 @@ def assert_parsed_output_item_count(node_name, number, parsed_output):
|
||||||
assert actual_entry_count == number, actual_entry_count
|
assert actual_entry_count == number, actual_entry_count
|
||||||
|
|
||||||
elif lang == "JSON":
|
elif lang == "JSON":
|
||||||
assert node_name in obj, [node_name, obj]
|
my_obj = obj
|
||||||
assert len(obj[node_name]) == number, len(obj[node_name])
|
|
||||||
|
for node in node_name.split("."):
|
||||||
|
try:
|
||||||
|
my_obj = my_obj[int(node)]
|
||||||
|
except ValueError:
|
||||||
|
assert node in my_obj
|
||||||
|
my_obj = my_obj[node]
|
||||||
|
|
||||||
|
assert len(my_obj) == number, len(my_obj)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
assert False, f"Language name {lang} not recognized"
|
assert False, f"Language name {lang} not recognized"
|
||||||
|
|
||||||
|
|
||||||
@then(parse('"{field_name}" in the parsed output should be\n{expected_keys}'))
|
@then(parse('"{field_name}" in the parsed output should be\n{expected_keys}'))
|
||||||
def assert_xml_output_tags(field_name, expected_keys, cli_run, parsed_output):
|
def assert_output_field_content(field_name, expected_keys, cli_run, parsed_output):
|
||||||
lang = parsed_output["lang"]
|
lang = parsed_output["lang"]
|
||||||
obj = parsed_output["obj"]
|
obj = parsed_output["obj"]
|
||||||
expected_keys = expected_keys.split("\n")
|
expected_keys = expected_keys.split("\n")
|
||||||
|
@ -511,7 +520,10 @@ def assert_xml_output_tags(field_name, expected_keys, cli_run, parsed_output):
|
||||||
|
|
||||||
if field_name == "tags":
|
if field_name == "tags":
|
||||||
actual_tags = set(t.attrib["name"] for t in obj.find("tags"))
|
actual_tags = set(t.attrib["name"] for t in obj.find("tags"))
|
||||||
assert set(actual_tags) == set(expected_keys), [actual_tags, set(expected_keys)]
|
assert set(actual_tags) == set(expected_keys), [
|
||||||
|
actual_tags,
|
||||||
|
set(expected_keys),
|
||||||
|
]
|
||||||
else:
|
else:
|
||||||
assert False, "This test only works for tags in XML"
|
assert False, "This test only works for tags in XML"
|
||||||
|
|
||||||
|
@ -522,10 +534,13 @@ def assert_xml_output_tags(field_name, expected_keys, cli_run, parsed_output):
|
||||||
try:
|
try:
|
||||||
my_obj = my_obj[int(node)]
|
my_obj = my_obj[int(node)]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
assert field_name in my_obj
|
assert node in my_obj, [my_obj.keys(), node]
|
||||||
my_obj = my_obj[node]
|
my_obj = my_obj[node]
|
||||||
|
|
||||||
assert set(expected_keys) == set(my_obj)
|
if type(my_obj) is str:
|
||||||
|
my_obj = [my_obj]
|
||||||
|
|
||||||
|
assert set(expected_keys) == set(my_obj), [set(my_obj), set(expected_keys)]
|
||||||
else:
|
else:
|
||||||
assert False, f"Language name {lang} not recognized"
|
assert False, f"Language name {lang} not recognized"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue