88
99from docx .enum .style import WD_STYLE_TYPE
1010from docx .image .image import Image
11+ from docx .opc .constants import RELATIONSHIP_TYPE as RT
1112from docx .package import Package
1213from docx .parts .document import DocumentPart
14+ from docx .parts .image import ImagePart
1315from docx .parts .story import BaseStoryPart
1416from docx .styles .style import BaseStyle
1517
1921
2022class DescribeBaseStoryPart (object ):
2123
24+ def it_can_get_or_add_an_image (self , package_ , image_part_ , image_ , relate_to_ ):
25+ package_ .get_or_add_image_part .return_value = image_part_
26+ relate_to_ .return_value = "rId42"
27+ image_part_ .image = image_
28+ story_part = BaseStoryPart (None , None , None , package_ )
29+
30+ rId , image = story_part .get_or_add_image ("image.png" )
31+
32+ package_ .get_or_add_image_part .assert_called_once_with ("image.png" )
33+ relate_to_ .assert_called_once_with (story_part , image_part_ , RT .IMAGE )
34+ assert rId == "rId42"
35+ assert image is image_
36+
2237 def it_can_get_a_style_by_id_and_type (
2338 self , _document_part_prop_ , document_part_ , style_
2439 ):
@@ -86,6 +101,10 @@ def get_or_add_image_(self, request):
86101 def image_ (self , request ):
87102 return instance_mock (request , Image )
88103
104+ @pytest .fixture
105+ def image_part_ (self , request ):
106+ return instance_mock (request , ImagePart )
107+
89108 @pytest .fixture
90109 def next_id_prop_ (self , request ):
91110 return property_mock (request , BaseStoryPart , "next_id" )
@@ -94,6 +113,10 @@ def next_id_prop_(self, request):
94113 def package_ (self , request ):
95114 return instance_mock (request , Package )
96115
116+ @pytest .fixture
117+ def relate_to_ (self , request ):
118+ return method_mock (request , BaseStoryPart , "relate_to" )
119+
97120 @pytest .fixture
98121 def style_ (self , request ):
99122 return instance_mock (request , BaseStyle )
0 commit comments