|
| 1 | +# encoding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | +Gherkin step implementations for core properties-related features. |
| 5 | +""" |
| 6 | + |
| 7 | +from __future__ import ( |
| 8 | + absolute_import, division, print_function, unicode_literals |
| 9 | +) |
| 10 | + |
| 11 | +from datetime import datetime |
| 12 | + |
| 13 | +from behave import given, then |
| 14 | + |
| 15 | +from docx import Document |
| 16 | +from docx.opc.coreprops import CoreProperties |
| 17 | + |
| 18 | +from helpers import test_docx |
| 19 | + |
| 20 | + |
| 21 | +# given =================================================== |
| 22 | + |
| 23 | +@given('a document having known core properties') |
| 24 | +def given_a_document_having_known_core_properties(context): |
| 25 | + context.document = Document(test_docx('doc-coreprops')) |
| 26 | + |
| 27 | + |
| 28 | +# then ==================================================== |
| 29 | + |
| 30 | +@then('I can access the core properties object') |
| 31 | +def then_I_can_access_the_core_properties_object(context): |
| 32 | + document = context.document |
| 33 | + core_properties = document.core_properties |
| 34 | + assert isinstance(core_properties, CoreProperties) |
| 35 | + |
| 36 | + |
| 37 | +@then('the core property values match the known values') |
| 38 | +def then_the_core_property_values_match_the_known_values(context): |
| 39 | + known_propvals = ( |
| 40 | + ('author', 'Steve Canny'), |
| 41 | + ('category', 'Category'), |
| 42 | + ('comments', 'Description'), |
| 43 | + ('content_status', 'Content Status'), |
| 44 | + ('created', datetime(2014, 12, 13, 22, 2, 0)), |
| 45 | + ('identifier', 'Identifier'), |
| 46 | + ('keywords', 'key; word; keyword'), |
| 47 | + ('language', 'Language'), |
| 48 | + ('last_modified_by', 'Steve Canny'), |
| 49 | + ('last_printed', datetime(2014, 12, 13, 22, 2, 42)), |
| 50 | + ('modified', datetime(2014, 12, 13, 22, 6, 0)), |
| 51 | + ('revision', 2), |
| 52 | + ('subject', 'Subject'), |
| 53 | + ('title', 'Title'), |
| 54 | + ('version', '0.7.1a3'), |
| 55 | + ) |
| 56 | + core_properties = context.document.core_properties |
| 57 | + for name, expected_value in known_propvals: |
| 58 | + value = getattr(core_properties, name) |
| 59 | + assert value == expected_value, ( |
| 60 | + "got '%s' for core property '%s'" % (value, name) |
| 61 | + ) |
0 commit comments