1010
1111from datetime import datetime
1212
13- from behave import given , then
13+ from behave import given , then , when
1414
1515from docx import Document
1616from 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