def test_render_with_uploaded_image(self):
"""
Checks whether the template_with_initial is not affected by
the render method if it has been called with just uploaded image
"""
# set initial template_with_initial value
self.widget.template_with_initial = "bar"
# create a mock object of just uploaded image
image = mock.MagicMock(spec=InMemoryUploadedFile)
# patch the parent's render method
with mock.patch.object(
AdminFileWidget,
'render',
return_value='foo'
) as render:
# call the method with just uploaded image mock
result = widgets.ImageWidget.render(self.widget, 'name', image)
# check whether the parent's method has been called
# with the same arguments
render.assert_called_with('name', image, None)
# check whether the method returns the result of the parent's method
self.assertEqual(result, 'foo')
# check whether the template_with_initial has not been changed
self.assertEqual(self.widget.template_with_initial, 'bar')
评论列表
文章目录