test_widgets.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:django-content-gallery 作者: Kemaweyan 项目源码 文件源码
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')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号