本文整理汇总了Python中mock.mock.MagicMock.status方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.status方法的具体用法?Python MagicMock.status怎么用?Python MagicMock.status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.status方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_checkURL
# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import status [as 别名]
def test_checkURL(self, httpsConMock, parseMock):
NetUtil.logger = MagicMock()
parseMock.return_value = [1, 2]
ca_connection = MagicMock()
response = MagicMock()
response.status = 200
ca_connection.getresponse.return_value = response
httpsConMock.return_value = ca_connection
# test 200
netutil = NetUtil.NetUtil(MagicMock())
self.assertTrue(netutil.checkURL("url")[0])
# test fail
response.status = 404
self.assertFalse(netutil.checkURL("url")[0])
# test Exception
response.status = 200
httpsConMock.side_effect = Exception("test")
self.assertFalse(netutil.checkURL("url")[0])
示例2: test_collect_ok
# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import status [as 别名]
def test_collect_ok(self, conn_mock):
alert_meta = {
'name': 'alert1',
'label': 'label1',
'serviceName': 'service1',
'componentName': 'component1',
'uuid': '123',
'enabled': 'true'
}
alert_source_meta = {
'ams': {
'metric_list': [
'metric1'
],
"app_id": "APP_ID",
"interval": 60,
"minimum_value": -1,
"compute": "mean",
"value": "{0}"
},
'uri': {
'http': '192.168.0.10:8080',
'https_property': '{{ams-site/timeline.metrics.service.http.policy}}',
'https_property_value': 'HTTPS_ONLY'
},
"reporting": {
"ok": {
"text": "OK: {0}"
},
"warning": {
"text": "Warn: {0}",
"value": 3
},
"critical": {
"text": "Crit: {0}",
"value": 5
}
}
}
cluster = 'c1'
host = 'host1'
expected_text = 'OK: 2'
def collector_side_effect(clus, data):
self.assertEquals(data['name'], alert_meta['name'])
self.assertEquals(data['label'], alert_meta['label'])
self.assertEquals(data['text'], expected_text)
self.assertEquals(data['service'], alert_meta['serviceName'])
self.assertEquals(data['component'], alert_meta['componentName'])
self.assertEquals(data['uuid'], alert_meta['uuid'])
self.assertEquals(data['enabled'], alert_meta['enabled'])
self.assertEquals(data['cluster'], cluster)
self.assertEquals(clus, cluster)
ca_connection = MagicMock()
response = MagicMock()
response.status = 200
ca_connection.getresponse.return_value = response
conn_mock.return_value = ca_connection
response.read.return_value = '{"metrics":[{"metricname":"metric1","metrics":{"1459966360838":1,"1459966370838":3}}]}'
mock_collector = MagicMock()
mock_collector.put = Mock(side_effect=collector_side_effect)
alert = AmsAlert(alert_meta, alert_source_meta, self.config)
alert.set_helpers(mock_collector, {'foo-site/bar': 12, 'foo-site/baz': 'asd'})
alert.set_cluster(cluster, host)
alert.collect()