Skip to content
This repository was archived by the owner on Jan 7, 2024. It is now read-only.

Commit 783cf9f

Browse files
author
Steve Canny
committed
acpt: add scenario for reading CoreProperties
1 parent b3bf30a commit 783cf9f

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

docx/opc/coreprops.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# encoding: utf-8
2+
3+
"""
4+
The :mod:`pptx.packaging` module coheres around the concerns of reading and
5+
writing presentations to and from a .pptx file.
6+
"""
7+
8+
from __future__ import (
9+
absolute_import, division, print_function, unicode_literals
10+
)
11+
12+
13+
class CoreProperties(object):
14+
"""
15+
Corresponds to part named ``/docProps/core.xml``, containing the core
16+
document properties for this document package.
17+
"""

features/doc-coreprops.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Feature: Read and write core document properties
2+
In order to find documents and make them manageable by digital means
3+
As a developer using python-docx
4+
I need to access and modify the Dublin Core metadata for a document
5+
6+
@wip
7+
Scenario: read the core properties of a document
8+
Given a document having known core properties
9+
Then I can access the core properties object
10+
And the core property values match the known values

features/steps/coreprops.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
)
11.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)