本文整理汇总了Python中tests.functional.MagicMock.assert_called_any方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.assert_called_any方法的具体用法?Python MagicMock.assert_called_any怎么用?Python MagicMock.assert_called_any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.functional.MagicMock
的用法示例。
在下文中一共展示了MagicMock.assert_called_any方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: serve_thumbnail_with_valid_params_test
# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import assert_called_any [as 别名]
def serve_thumbnail_with_valid_params_test(self):
"""
Test the serve_thumbnail routine with valid params
"""
# GIVEN: Mocked send_header, send_response, end_headers and wfile
self.router.send_response = MagicMock()
self.router.send_header = MagicMock()
self.router.end_headers = MagicMock()
self.router.wfile = MagicMock()
mocked_image_manager = MagicMock()
Registry.create()
Registry().register("image_manager", mocked_image_manager)
file_name = "another%20test/slide1.png"
full_path = os.path.normpath(os.path.join("thumbnails", file_name))
width = 120
height = 90
with patch("openlp.core.lib.os.path.exists") as mocked_exists, patch(
"builtins.open", mock_open(read_data="123")
), patch("openlp.plugins.remotes.lib.httprouter.AppLocation") as mocked_location, patch(
"openlp.plugins.remotes.lib.httprouter.image_to_byte"
) as mocked_image_to_byte:
mocked_exists.return_value = True
mocked_image_to_byte.return_value = "123"
mocked_location.get_section_data_path.return_value = ""
# WHEN: pass good controller and filename
self.router.serve_thumbnail("presentations", "{0}x{1}".format(width, height), file_name)
# THEN: a file should be returned
self.assertEqual(self.router.send_header.call_count, 1, "One header")
self.assertEqual(self.router.send_response.call_count, 1, "Send response called once")
self.assertEqual(self.router.end_headers.call_count, 1, "end_headers called once")
mocked_exists.assert_called_with(urllib.parse.unquote(full_path))
self.assertEqual(mocked_image_to_byte.call_count, 1, "Called once")
mocked_image_manager.assert_called_any(
os.path.normpath("thumbnails\\another test"), "slide1.png", None, "120x90"
)
mocked_image_manager.assert_called_any(os.path.normpath("thumbnails\\another test"), "slide1.png", "120x90")