From 108cadcf0e299b7d3f801081c093501110804a5b Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Mon, 25 May 2020 22:32:24 -0600 Subject: [PATCH] [DayOne] [Tests] test that extended DayOne metadata is added to new entries --- features/dayone.feature | 12 ++++++++++++ features/steps/export_steps.py | 22 +++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/features/dayone.feature b/features/dayone.feature index 8e50b42b..bf74dc8d 100644 --- a/features/dayone.feature +++ b/features/dayone.feature @@ -63,3 +63,15 @@ Feature: Dayone specific implementation details. Then we should get no error and the output should be parsable as json and the json output should contain entries.0.uuid = "4BB1F46946AD439996C9B59DE7C4DDC1" + + Scenario: Writing into Dayone adds extended metadata + Given we use the config "dayone.yaml" + When we run "jrnl 01 may 1979: Being born hurts." + and we run "jrnl --export json" + Then "entries" in the json output should have 5 elements + and the json output should contain entries.0.creator.software_agent + and the json output should contain entries.0.creator.os_agent + and the json output should contain entries.0.creator.host_name + and the json output should contain entries.0.creator.generation_date + and the json output should contain entries.0.creator.device_agent + and "entries.0.creator.software_agent" in the json output should contain "jrnl" diff --git a/features/steps/export_steps.py b/features/steps/export_steps.py index 40127ecc..bc5b085d 100644 --- a/features/steps/export_steps.py +++ b/features/steps/export_steps.py @@ -32,13 +32,21 @@ def check_output_field_not_key(context, field, key): @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] + struct = json.loads(out) + + for node in field.split("."): + try: + struct = struct[int(node)] + except ValueError: + assert node in struct + struct = struct[node] + + assert key in struct +@then("the json output should contain {path}") @then('the json output should contain {path} = "{value}"') -def check_json_output_path(context, path, value): +def check_json_output_path(context, path, value=None): """ E.g. the json output should contain entries.0.title = "hello" """ @@ -50,7 +58,11 @@ def check_json_output_path(context, path, value): struct = struct[int(node)] except ValueError: struct = struct[node] - assert struct == value, struct + + if value is not None: + assert struct == value, struct + else: + assert struct is not None @then("the output should be a valid XML string")