88 absolute_import , division , print_function , unicode_literals
99)
1010
11- from datetime import datetime
11+ from datetime import datetime , timedelta
1212
1313from behave import given , then , when
1414
@@ -25,8 +25,18 @@ def given_a_document_having_known_core_properties(context):
2525 context .document = Document (test_docx ('doc-coreprops' ))
2626
2727
28+ @given ('a document having no core properties part' )
29+ def given_a_document_having_no_core_properties_part (context ):
30+ context .document = Document (test_docx ('doc-no-coreprops' ))
31+
32+
2833# when ====================================================
2934
35+ @when ('I access the core properties object' )
36+ def when_I_access_the_core_properties_object (context ):
37+ context .document .core_properties
38+
39+
3040@when ("I assign new values to the properties" )
3141def when_I_assign_new_values_to_the_properties (context ):
3242 context .propvals = (
@@ -53,6 +63,19 @@ def when_I_assign_new_values_to_the_properties(context):
5363
5464# then ====================================================
5565
66+ @then ('a core properties part with default values is added' )
67+ def then_a_core_properties_part_with_default_values_is_added (context ):
68+ core_properties = context .document .core_properties
69+ assert core_properties .title == 'Word Document'
70+ assert core_properties .last_modified_by == 'python-docx'
71+ assert core_properties .revision == 1
72+ # core_properties.modified only stores time with seconds resolution, so
73+ # comparison needs to be a little loose (within two seconds)
74+ modified_timedelta = datetime .utcnow () - core_properties .modified
75+ max_expected_timedelta = timedelta (seconds = 2 )
76+ assert modified_timedelta < max_expected_timedelta
77+
78+
5679@then ('I can access the core properties object' )
5780def then_I_can_access_the_core_properties_object (context ):
5881 document = context .document
0 commit comments