Skip to content

Commit 113c999

Browse files
author
Steve Canny
committed
acpt: add scenario for default CoreProperties part
1 parent d49d71f commit 113c999

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

features/doc-coreprops.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ Feature: Read and write core document properties
1414
Given a document having known core properties
1515
When I assign new values to the properties
1616
Then the core property values match the new values
17+
18+
19+
@wip
20+
Scenario: a default core properties part is added if doc doesn't have one
21+
Given a document having no core properties part
22+
When I access the core properties object
23+
Then a core properties part with default values is added

features/steps/coreprops.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
absolute_import, division, print_function, unicode_literals
99
)
1010

11-
from datetime import datetime
11+
from datetime import datetime, timedelta
1212

1313
from 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")
3141
def 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')
5780
def then_I_can_access_the_core_properties_object(context):
5881
document = context.document
11.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)