Skip to content

Commit aeaf77b

Browse files
author
Steve Canny
committed
parts: add _Document.body
1 parent 7ef0bd8 commit aeaf77b

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

docx/parts.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,17 @@ def body(self):
2929
"""
3030
The |_Body| instance containing the content for this document.
3131
"""
32+
return _Body(self._element.body)
3233

3334
@staticmethod
3435
def load(partname, content_type, blob):
3536
document_elm = oxml_fromstring(blob)
3637
document = _Document(partname, content_type, document_elm)
3738
return document
39+
40+
41+
class _Body(object):
42+
"""
43+
Proxy for ``<w:body>`` element in this document, having primarily a
44+
container role.
45+
"""

tests/test_parts.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515

1616
from mock import Mock
1717

18-
from .unitutil import function_mock, initializer_mock
18+
from .unitutil import class_mock, function_mock, initializer_mock
1919

2020

2121
class Describe_Document(object):
2222

23+
@pytest.fixture
24+
def _Body_(self, request):
25+
return class_mock('docx.parts._Body', request)
26+
2327
@pytest.fixture
2428
def init(self, request):
2529
return initializer_mock(_Document, request)
@@ -28,8 +32,8 @@ def init(self, request):
2832
def oxml_fromstring_(self, request):
2933
return function_mock('docx.parts.oxml_fromstring', request)
3034

31-
def it_can_be_constructed_by_opc_part_factory(self, oxml_fromstring_,
32-
init):
35+
def it_can_be_constructed_by_opc_part_factory(
36+
self, oxml_fromstring_, init):
3337
# mockery ----------------------
3438
partname, content_type, blob, document_elm = (
3539
Mock(name='partname'), Mock(name='content_type'),
@@ -42,3 +46,13 @@ def it_can_be_constructed_by_opc_part_factory(self, oxml_fromstring_,
4246
oxml_fromstring_.assert_called_once_with(blob)
4347
init.assert_called_once_with(partname, content_type, document_elm)
4448
assert isinstance(doc, _Document)
49+
50+
def it_has_a_body(self, init, _Body_):
51+
# mockery ----------------------
52+
doc = _Document(None, None, None)
53+
doc._element = Mock(name='_element')
54+
# exercise ---------------------
55+
body = doc.body
56+
# verify -----------------------
57+
_Body_.assert_called_once_with(doc._element.body)
58+
assert body is _Body_.return_value

0 commit comments

Comments
 (0)