Skip to content

Commit d49d71f

Browse files
author
Steve Canny
committed
acpt: add scenario for writing CoreProperties
1 parent 4d2c465 commit d49d71f

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

features/doc-coreprops.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ Feature: Read and write core document properties
88
Given a document having known core properties
99
Then I can access the core properties object
1010
And the core property values match the known values
11+
12+
13+
Scenario: change the core properties of a document
14+
Given a document having known core properties
15+
When I assign new values to the properties
16+
Then the core property values match the new values

features/steps/coreprops.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from datetime import datetime
1212

13-
from behave import given, then
13+
from behave import given, then, when
1414

1515
from docx import Document
1616
from docx.opc.coreprops import CoreProperties
@@ -25,6 +25,32 @@ def given_a_document_having_known_core_properties(context):
2525
context.document = Document(test_docx('doc-coreprops'))
2626

2727

28+
# when ====================================================
29+
30+
@when("I assign new values to the properties")
31+
def when_I_assign_new_values_to_the_properties(context):
32+
context.propvals = (
33+
('author', 'Creator'),
34+
('category', 'Category'),
35+
('comments', 'Description'),
36+
('content_status', 'Content Status'),
37+
('created', datetime(2013, 6, 15, 12, 34, 56)),
38+
('identifier', 'Identifier'),
39+
('keywords', 'key; word; keyword'),
40+
('language', 'Language'),
41+
('last_modified_by', 'Last Modified By'),
42+
('last_printed', datetime(2013, 6, 15, 12, 34, 56)),
43+
('modified', datetime(2013, 6, 15, 12, 34, 56)),
44+
('revision', 9),
45+
('subject', 'Subject'),
46+
('title', 'Title'),
47+
('version', 'Version'),
48+
)
49+
core_properties = context.document.core_properties
50+
for name, value in context.propvals:
51+
setattr(core_properties, name, value)
52+
53+
2854
# then ====================================================
2955

3056
@then('I can access the core properties object')
@@ -59,3 +85,13 @@ def then_the_core_property_values_match_the_known_values(context):
5985
assert value == expected_value, (
6086
"got '%s' for core property '%s'" % (value, name)
6187
)
88+
89+
90+
@then('the core property values match the new values')
91+
def then_the_core_property_values_match_the_new_values(context):
92+
core_properties = context.document.core_properties
93+
for name, expected_value in context.propvals:
94+
value = getattr(core_properties, name)
95+
assert value == expected_value, (
96+
"got '%s' for core property '%s'" % (value, name)
97+
)

0 commit comments

Comments
 (0)