|
12 | 12 |
|
13 | 13 | from docx.api import Document |
14 | 14 | from docx.enum.text import WD_BREAK |
15 | | -from docx.opc.constants import CONTENT_TYPE as CT |
| 15 | +from docx.opc.constants import CONTENT_TYPE as CT, RELATIONSHIP_TYPE as RT |
16 | 16 | from docx.package import Package |
17 | 17 | from docx.parts.document import DocumentPart, InlineShapes |
| 18 | +from docx.parts.numbering import NumberingPart |
18 | 19 | from docx.table import Table |
19 | 20 | from docx.text import Paragraph, Run |
20 | 21 |
|
@@ -123,6 +124,24 @@ def it_can_save_the_package(self, save_fixture): |
123 | 124 | document.save(file_) |
124 | 125 | package_.save.assert_called_once_with(file_) |
125 | 126 |
|
| 127 | + def it_provides_access_to_the_numbering_part(self, num_part_get_fixture): |
| 128 | + document, document_part_, numbering_part_ = num_part_get_fixture |
| 129 | + numbering_part = document.numbering_part |
| 130 | + document_part_.part_related_by.assert_called_once_with(RT.NUMBERING) |
| 131 | + assert numbering_part is numbering_part_ |
| 132 | + |
| 133 | + def it_creates_numbering_part_on_first_access_if_not_present( |
| 134 | + self, num_part_create_fixture): |
| 135 | + document, NumberingPart_, document_part_, numbering_part_ = ( |
| 136 | + num_part_create_fixture |
| 137 | + ) |
| 138 | + numbering_part = document.numbering_part |
| 139 | + NumberingPart_.new.assert_called_once_with() |
| 140 | + document_part_.relate_to.assert_called_once_with( |
| 141 | + numbering_part_, RT.NUMBERING |
| 142 | + ) |
| 143 | + assert numbering_part is numbering_part_ |
| 144 | + |
126 | 145 | # fixtures ------------------------------------------------------- |
127 | 146 |
|
128 | 147 | @pytest.fixture(params=[0, 1, 2, 5, 9]) |
@@ -220,6 +239,27 @@ def init_fixture(self, docx_, open_): |
220 | 239 | def inline_shapes_(self, request): |
221 | 240 | return instance_mock(request, InlineShapes) |
222 | 241 |
|
| 242 | + @pytest.fixture |
| 243 | + def num_part_create_fixture( |
| 244 | + self, document, NumberingPart_, document_part_, numbering_part_): |
| 245 | + document_part_.part_related_by.side_effect = KeyError |
| 246 | + return document, NumberingPart_, document_part_, numbering_part_ |
| 247 | + |
| 248 | + @pytest.fixture |
| 249 | + def num_part_get_fixture(self, document, document_part_, numbering_part_): |
| 250 | + document_part_.part_related_by.return_value = numbering_part_ |
| 251 | + return document, document_part_, numbering_part_ |
| 252 | + |
| 253 | + @pytest.fixture |
| 254 | + def NumberingPart_(self, request, numbering_part_): |
| 255 | + NumberingPart_ = class_mock(request, 'docx.api.NumberingPart') |
| 256 | + NumberingPart_.new.return_value = numbering_part_ |
| 257 | + return NumberingPart_ |
| 258 | + |
| 259 | + @pytest.fixture |
| 260 | + def numbering_part_(self, request): |
| 261 | + return instance_mock(request, NumberingPart) |
| 262 | + |
223 | 263 | @pytest.fixture |
224 | 264 | def open_(self, request, document_part_, package_): |
225 | 265 | return method_mock( |
|
0 commit comments