8
8
absolute_import , division , print_function , unicode_literals
9
9
)
10
10
11
- from datetime import datetime
11
+ from datetime import datetime , timedelta
12
12
13
13
from behave import given , then , when
14
14
@@ -25,8 +25,18 @@ def given_a_document_having_known_core_properties(context):
25
25
context .document = Document (test_docx ('doc-coreprops' ))
26
26
27
27
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
+
28
33
# when ====================================================
29
34
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
+
30
40
@when ("I assign new values to the properties" )
31
41
def when_I_assign_new_values_to_the_properties (context ):
32
42
context .propvals = (
@@ -53,6 +63,19 @@ def when_I_assign_new_values_to_the_properties(context):
53
63
54
64
# then ====================================================
55
65
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
+
56
79
@then ('I can access the core properties object' )
57
80
def then_I_can_access_the_core_properties_object (context ):
58
81
document = context .document
0 commit comments