mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Better tests for exporting to json
This commit is contained in:
parent
cb55bccb17
commit
5255e39448
2 changed files with 39 additions and 42 deletions
|
@ -4,49 +4,19 @@ Feature: Expoting a Journal
|
||||||
Given we use the config "tags.json"
|
Given we use the config "tags.json"
|
||||||
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
|
and the output should be parsable as json
|
||||||
"""
|
and "entries" in the json output should have 2 elements
|
||||||
{
|
and "tags" in the json output should contain "@idea"
|
||||||
"entries": [
|
and "tags" in the json output should contain "@journal"
|
||||||
{
|
and "tags" in the json output should contain "@dan"
|
||||||
"body": "(1) write a command line @journal software\n(2) ???\n(3) PROFIT!",
|
|
||||||
"date": "2013-04-09",
|
|
||||||
"time": "15:39",
|
|
||||||
"title": "I have an @idea:"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"body": "As alway's he shared his latest @idea on how to rule the world with me.",
|
|
||||||
"date": "2013-06-10",
|
|
||||||
"time": "15:40",
|
|
||||||
"title": "I met with @dan."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tags": {
|
|
||||||
"@idea": 2,
|
|
||||||
"@journal": 1,
|
|
||||||
"@dan": 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
Scenario: Exporting using filters should only export parts of the journal
|
Scenario: Exporting using filters should only export parts of the journal
|
||||||
Given we use the config "tags.json"
|
Given we use the config "tags.json"
|
||||||
When we run "jrnl -to 'may 2013' --export json"
|
When we run "jrnl -to 'may 2013' --export json"
|
||||||
Then we should get no error
|
# Then we should get no error
|
||||||
and the output should be
|
Then the output should be parsable as json
|
||||||
"""
|
and "entries" in the json output should have 1 element
|
||||||
{
|
and "tags" in the json output should contain "@idea"
|
||||||
"entries": [
|
and "tags" in the json output should contain "@journal"
|
||||||
{
|
and "tags" in the json output should not contain "@dan"
|
||||||
"body": "(1) write a command line @journal software\n(2) ???\n(3) PROFIT!",
|
|
||||||
"date": "2013-04-09",
|
|
||||||
"time": "15:39",
|
|
||||||
"title": "I have an @idea:"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tags": {
|
|
||||||
"@idea": 1,
|
|
||||||
"@journal": 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
|
@ -63,6 +63,33 @@ def run(context, command):
|
||||||
def no_error(context):
|
def no_error(context):
|
||||||
assert context.failed is False
|
assert context.failed is False
|
||||||
|
|
||||||
|
@then('the output should be parsable as json')
|
||||||
|
def check_output_json(context):
|
||||||
|
out = context.stdout_capture.getvalue()
|
||||||
|
assert json.loads(out)
|
||||||
|
|
||||||
|
@then('"{field}" in the json output should have {number:d} elements')
|
||||||
|
@then('"{field}" in the json output should have 1 element')
|
||||||
|
def check_output_field(context, field, number=1):
|
||||||
|
out = context.stdout_capture.getvalue()
|
||||||
|
out_json = json.loads(out)
|
||||||
|
assert field in out_json
|
||||||
|
assert len(out_json[field]) == number
|
||||||
|
|
||||||
|
@then('"{field}" in the json output should not contain "{key}"')
|
||||||
|
def check_output_field_not_key(context, field, key):
|
||||||
|
out = context.stdout_capture.getvalue()
|
||||||
|
out_json = json.loads(out)
|
||||||
|
assert field in out_json
|
||||||
|
assert key not in out_json[field]
|
||||||
|
|
||||||
|
@then('"{field}" in the json output should contain "{key}"')
|
||||||
|
def check_output_field_key(context, field, key):
|
||||||
|
out = context.stdout_capture.getvalue()
|
||||||
|
out_json = json.loads(out)
|
||||||
|
assert field in out_json
|
||||||
|
assert key in out_json[field]
|
||||||
|
|
||||||
@then('the output should be')
|
@then('the output should be')
|
||||||
def check_output(context):
|
def check_output(context):
|
||||||
text = context.text.strip().splitlines()
|
text = context.text.strip().splitlines()
|
||||||
|
|
Loading…
Add table
Reference in a new issue