10
10
11
11
from datetime import datetime
12
12
13
- from behave import given , then
13
+ from behave import given , then , when
14
14
15
15
from docx import Document
16
16
from docx .opc .coreprops import CoreProperties
@@ -25,6 +25,32 @@ def given_a_document_having_known_core_properties(context):
25
25
context .document = Document (test_docx ('doc-coreprops' ))
26
26
27
27
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
+
28
54
# then ====================================================
29
55
30
56
@then ('I can access the core properties object' )
@@ -59,3 +85,13 @@ def then_the_core_property_values_match_the_known_values(context):
59
85
assert value == expected_value , (
60
86
"got '%s' for core property '%s'" % (value , name )
61
87
)
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