本文整理汇总了Python中unittest.mock.MagicMock.status方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.status方法的具体用法?Python MagicMock.status怎么用?Python MagicMock.status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.status方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: resp
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import status [as 别名]
async def resp(*args, **kwargs):
node.__calls += 1
response = MagicMock()
if node.__calls == 1:
response.status = 409
response.json = {"image": "linux.img", "exception": "ImageMissingError"}
else:
response.status = 200
return response
示例2: test_clean_order_release_payment
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import status [as 别名]
def test_clean_order_release_payment():
payment = MagicMock(spec=Payment)
payment.status = 'not preauth'
errors = clean_release_payment(payment)
assert errors[0].field == 'payment'
assert errors[0].message == 'Only pre-authorized payments can be released'
payment.status = PaymentStatus.PREAUTH
error_msg = 'error has happened.'
payment.release = Mock(side_effect=ValueError(error_msg))
errors = clean_release_payment(payment)
assert errors[0].field == 'payment'
assert errors[0].message == error_msg
示例3: test_render_with_typename
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import status [as 别名]
def test_render_with_typename(self, select_template):
model = MagicMock()
model.__name__ = MagicMock()
model.__name__.lower = MagicMock(return_value='model')
model._meta.app_label = 'app_label'
activity = MagicMock()
activity.status = 'status'
context = MagicMock()
rendered = MagicMock()
template = MagicMock()
template.render.return_value = rendered
select_template.return_value = template
typename = 'test'
mediator = ActivityMediator()
mediator.connect(model)
mediator.prepare_context = MagicMock(return_value=context.new())
r = mediator.render(activity, context, typename=typename)
select_template.assert_called_with(
mediator.get_template_names(activity, typename=typename))
mediator.prepare_context.assert_called_with(activity,
context.new(),
typename=typename)
template.render.assert_called_with(context.new())
self.assertEqual(r, rendered)
示例4: test_forward_post
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import status [as 别名]
def test_forward_post(compute, async_run):
response = MagicMock()
response.status = 200
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
async_run(compute.forward("POST", "qemu", "img", data={"id": 42}))
mock.assert_called_with("POST", "https://example.com:84/v2/compute/qemu/img", auth=None, data=b'{"id": 42}', headers={'content-type': 'application/json'}, chunked=None, timeout=None)
async_run(compute.close())
示例5: test_compute_httpQueryError
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import status [as 别名]
def test_compute_httpQueryError(compute, async_run):
response = MagicMock()
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
response.status = 404
with pytest.raises(aiohttp.web.HTTPNotFound):
async_run(compute.post("/projects", {"a": "b"}))
示例6: test_downloadFile
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import status [as 别名]
def test_downloadFile(project, async_run, compute):
response = MagicMock()
response.status = 200
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
async_run(compute.download_file(project, "test/titi"))
mock.assert_called_with("GET", "https://example.com:84/v2/compute/projects/{}/files/test/titi".format(project.id), auth=None)
async_run(compute.close())
示例7: test_forward_404
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import status [as 别名]
def test_forward_404(compute, async_run):
response = MagicMock()
response.status = 404
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
with pytest.raises(aiohttp.web_exceptions.HTTPNotFound):
async_run(compute.forward("GET", "qemu", "images"))
async_run(compute.close())
示例8: test_stumbleupon
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import status [as 别名]
def test_stumbleupon(self):
body = b'{"result":{"url":"http:\\/\\/www.google.com\\/","in_index":true,"publicid":"2pI1xR","views":254956,"title":"Google","thumbnail":"http:\\/\\/cdn.stumble-upon.com\\/mthumb\\/31\\/10031.jpg","thumbnail_b":"http:\\/\\/cdn.stumble-upon.com\\/bthumb\\/31\\/10031.jpg","submit_link":"http:\\/\\/www.stumbleupon.com\\/submit\\/?url=http:\\/\\/www.google.com\\/","badge_link":"http:\\/\\/www.stumbleupon.com\\/badge\\/?url=http:\\/\\/www.google.com\\/","info_link":"http:\\/\\/www.stumbleupon.com\\/url\\/www.google.com\\/"},"timestamp":1393900890,"success":true}'
mock_resp = MagicMock()
mock_resp.status = 200
mock_resp.read.return_value = body
self.create_patch('urllib.request.urlopen', return_value=mock_resp)
self.assertEqual(evaluator.stumbleupon(self.url), 254956)
示例9: test_compute_httpQueryConflictError
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import status [as 别名]
def test_compute_httpQueryConflictError(compute, async_run):
response = MagicMock()
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
response.status = 409
response.read = AsyncioMagicMock(return_value=b'{"message": "Test"}')
with pytest.raises(ComputeConflict):
async_run(compute.post("/projects", {"a": "b"}))
示例10: test_linkedin
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import status [as 别名]
def test_linkedin(self):
body = b'{"count":63952,"fCnt":"63K","fCntPlusOne":"63K","url":"http:\\/\\/www.google.com"}'
mock_resp = MagicMock()
mock_resp.status = 200
mock_resp.read.return_value = body
self.create_patch('urllib.request.urlopen', return_value=mock_resp)
self.assertEqual(evaluator.linkedin(self.url), 63952)
示例11: test_compute_httpQuery
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import status [as 别名]
def test_compute_httpQuery(compute, async_run):
response = MagicMock()
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
response.status = 200
async_run(compute.post("/projects", {"a": "b"}))
mock.assert_called_with("POST", "https://example.com:84/v2/compute/projects", data=b'{"a": "b"}', headers={'content-type': 'application/json'}, auth=None, chunked=None, timeout=20)
assert compute._auth is None
示例12: test_twitter
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import status [as 别名]
def test_twitter(self):
body = b'{"count":19515036,"url":"http:\\/\\/www.google.com\\/"}'
mock_resp = MagicMock()
mock_resp.status = 200
mock_resp.read.return_value = body
self.create_patch('urllib.request.urlopen', return_value=mock_resp)
self.assertEqual(evaluator.twitter(self.url), 19515036)
示例13: test_facebook_graph
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import status [as 别名]
def test_facebook_graph(self):
body = b'{"id":"http:\\/\\/www.google.com","shares":8503603,"comments":841}'
mock_resp = MagicMock()
mock_resp.status = 200
mock_resp.read.return_value = body
self.create_patch('urllib.request.urlopen', return_value=mock_resp)
self.assertEqual(evaluator.facebook_graph(self.url), 8503603 + 841)
示例14: test_compute_httpQuery_project
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import status [as 别名]
def test_compute_httpQuery_project(compute, async_run):
response = MagicMock()
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
response.status = 200
project = Project(name="Test")
async_run(compute.post("/projects", project))
mock.assert_called_with("POST", "https://example.com:84/v2/compute/projects", data=json.dumps(project.__json__()), headers={'content-type': 'application/json'}, auth=None, chunked=None, timeout=20)
示例15: test_emergency_stop_monitor
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import status [as 别名]
def test_emergency_stop_monitor(self):
robot = MagicMock()
robot.register = MagicMock(return_value=42)
with EmergencyStopMonitor(robot) as esm:
robot.register.assert_called_once_with(esm.update)
robot.status = 0x0
with self.assertRaises(EmergencyStopException):
esm.update(robot)
robot.unregister.assert_called_once_with(42)