本文整理汇总了Python中mock.Mock.send方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.send方法的具体用法?Python Mock.send怎么用?Python Mock.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.Mock
的用法示例。
在下文中一共展示了Mock.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_recover_retry_txn
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import send [as 别名]
def test_recover_retry_txn(self):
txn = Mock()
txns = [txn, None]
pop_txn = False
def take_txn(*args, **kwargs):
if pop_txn:
return defer.succeed(txns.pop(0))
else:
return defer.succeed(txn)
self.store.get_oldest_unsent_txn = Mock(side_effect=take_txn)
self.recoverer.recover()
self.assertEquals(0, self.store.get_oldest_unsent_txn.call_count)
txn.send = Mock(return_value=False)
self.clock.advance_time(2)
self.assertEquals(1, txn.send.call_count)
self.assertEquals(0, txn.complete.call_count)
self.assertEquals(0, self.callback.call_count)
self.clock.advance_time(4)
self.assertEquals(2, txn.send.call_count)
self.assertEquals(0, txn.complete.call_count)
self.assertEquals(0, self.callback.call_count)
self.clock.advance_time(8)
self.assertEquals(3, txn.send.call_count)
self.assertEquals(0, txn.complete.call_count)
self.assertEquals(0, self.callback.call_count)
txn.send = Mock(return_value=True) # successfully send the txn
pop_txn = True # returns the txn the first time, then no more.
self.clock.advance_time(16)
self.assertEquals(1, txn.send.call_count) # new mock reset call count
self.assertEquals(1, txn.complete.call_count)
self.callback.assert_called_once_with(self.recoverer)
示例2: test_custodian_azure_send_override_429_long_retry
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import send [as 别名]
def test_custodian_azure_send_override_429_long_retry(self, logger):
mock = Mock()
mock.send = types.MethodType(custodian_azure_send_override, mock)
response_dict = {
'headers': {'Retry-After': 60},
'status_code': 429
}
mock.orig_send.return_value = type(str('response'), (), response_dict)
mock.send('')
self.assertEqual(mock.orig_send.call_count, 1)
self.assertEqual(logger.call_count, 1)
示例3: setUp
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import send [as 别名]
def setUp(self):
job_mock = Mock()
job_mock.update = Mock()
self.job = job_mock
notification_mock = Mock()
notification_mock.send = Mock()
notification_fail = Mock()
notification_fail.send = Mock(side_effect=Exception('something went wrong!'))
self.success_notification = notification_mock
self.failure_notification = notification_fail
示例4: test_custodian_azure_send_override_200
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import send [as 别名]
def test_custodian_azure_send_override_200(self, logger):
mock = Mock()
mock.send = types.MethodType(custodian_azure_send_override, mock)
response_dict = {
'headers': {'x-ms-ratelimit-remaining-subscription-reads': '12000'},
'status_code': 200
}
mock.orig_send.return_value = type(str('response'), (), response_dict)
mock.send('')
self.assertEqual(mock.orig_send.call_count, 1)
self.assertEqual(logger.call_count, 2)
示例5: setUp
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import send [as 别名]
def setUp(self):
socket = Mock()
socket.recv = Mock()
socket.send = Mock()
with patch("socket.create_connection") as create_connection:
create_connection.return_value = socket
self.connection = TCPSocketConnection(("localhost", 1234))
示例6: test_registration_craps_out
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import send [as 别名]
def test_registration_craps_out(self):
from horus.views import RegisterController
from pyramid_mailer.interfaces import IMailer
from horus.interfaces import IUserClass
from horus.tests.models import User
from horus.interfaces import IActivationClass
from horus.tests.models import Activation
self.config.registry.registerUtility(Activation, IActivationClass)
self.config.registry.registerUtility(User, IUserClass)
def send(message):
raise Exception("I broke!")
mailer = Mock()
mailer.send = send
self.config.include('horus')
self.config.registry.registerUtility(mailer, IMailer)
self.config.add_route('index', '/')
request = self.get_csrf_request(post={
'username': 'admin',
'password': {
'password': 'test123',
'password-confirm': 'test123',
},
'email': '[email protected]'
}, request_method='POST')
request.user = Mock()
controller = RegisterController(request)
self.assertRaises(Exception, controller.register)
示例7: test_quit_bot
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import send [as 别名]
def test_quit_bot(self):
from functions import quit_bot
with nested(
patch('functions.log_write'),
patch('sys.stdout', new=StringIO()),
patch('functions.get_datetime'),
) as (log_write, stdout, get_dt):
get_dt.return_value = {'date': '42', 'time': '42'}
s = Mock()
s.send.side_effect = IOError()
message = 'Unexpected error while quitting: \n'
self.assertFalse(quit_bot(s, 'foo'))
self.assertEqual(stdout.getvalue(), message)
log_write.assert_called_with('foo', '42', ' <> ', message)
s.send.side_effect = None
s.send = Mock()
self.assertTrue(quit_bot(s, 'foo'))
log_write.assert_called_with('foo', '42', ' <> ', 'QUIT\r\n')
s.send.assert_called_with('QUIT\r\n')
示例8: test_source_process
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import send [as 别名]
def test_source_process(self):
source = FilesystemObserverSource("*.txt", "/some/directory")
reactor = Mock()
reactor.spawnProcess = Mock(spec=_spawnProcess)
scheduler = Mock()
scheduler.send = Mock(spec=Scheduler.send)
# Attach source to the scheduler.
yield source.attach(scheduler, reactor)
self.assertEquals(reactor.spawnProcess.call_count, 1)
# Simulate a message directed to the source.
msg = {
"port": "default",
"item": {
"type": "delta",
"date": datetime(2010, 10, 20, 20, 10),
"inserts": ["abcdefg"],
"deletes": ["hiklmno"],
"data": {"abcdefg": {"path": "/some/directory/xyz.txt"}},
},
}
matches = MatchesSendDeltaItemInvocation(copy.deepcopy(msg["item"]), source)
source.peer.dataReceived(BSON.encode(msg))
self.assertEquals(scheduler.send.call_count, 1)
self.assertThat(scheduler.send.call_args, matches)
示例9: test_single_service_up_txn_not_sent
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import send [as 别名]
def test_single_service_up_txn_not_sent(self):
# Test: The AS is up and the txn is not sent. A Recoverer is made and
# started.
service = Mock()
events = [Mock(), Mock()]
txn_id = "foobar"
txn = Mock(id=txn_id, service=service, events=events)
# mock methods
self.store.get_appservice_state = Mock(
return_value=defer.succeed(ApplicationServiceState.UP)
)
self.store.set_appservice_state = Mock(return_value=defer.succeed(True))
txn.send = Mock(return_value=defer.succeed(False)) # fails to send
self.store.create_appservice_txn = Mock(
return_value=defer.succeed(txn)
)
# actual call
self.txnctrl.send(service, events)
self.store.create_appservice_txn.assert_called_once_with(
service=service, events=events
)
self.assertEquals(1, self.recoverer_fn.call_count) # recoverer made
self.assertEquals(1, self.recoverer.recover.call_count) # and invoked
self.assertEquals(1, len(self.txnctrl.recoverers)) # and stored
self.assertEquals(0, txn.complete.call_count) # txn not completed
self.store.set_appservice_state.assert_called_once_with(
service, ApplicationServiceState.DOWN # service marked as down
)
示例10: test_registration_craps_out
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import send [as 别名]
def test_registration_craps_out(self):
from pyramid_signup.views import RegisterController
from pyramid_mailer.interfaces import IMailer
def send(message):
raise Exception("I broke!")
mailer = Mock()
mailer.send = send
self.config.include('pyramid_signup')
self.config.registry.registerUtility(mailer, IMailer)
self.config.add_route('index', '/')
request = self.get_csrf_request(post={
'Username': 'admin',
'Password': {
'value': 'test123',
'confirm': 'test123',
},
'Email': '[email protected]'
}, request_method='POST')
flash = Mock()
request.session.flash = flash
request.user = Mock()
controller = RegisterController(request)
controller.register()
flash.assert_called_with('I broke!', 'error')
示例11: test_handle_response_401
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import send [as 别名]
def test_handle_response_401(self):
# Get a 401 from server, authenticate, and get a 200 back.
with patch.multiple(kerberos_module_name,
authGSSClientInit=clientInit_complete,
authGSSClientResponse=clientResponse,
authGSSClientStep=clientStep_continue):
response_ok = requests.Response()
response_ok.url = "http://www.example.org/"
response_ok.status_code = 200
response_ok.headers = {'www-authenticate': 'negotiate servertoken'}
connection = Mock()
connection.send = Mock(return_value=response_ok)
raw = Mock()
raw.release_conn = Mock(return_value=None)
request = requests.Request()
response = requests.Response()
response.request = request
response.url = "http://www.example.org/"
response.headers = {'www-authenticate': 'negotiate token'}
response.status_code = 401
response.connection = connection
response._content = ""
response.raw = raw
auth = requests_kerberos.HTTPKerberosAuth()
auth.handle_other = Mock(return_value=response_ok)
r = auth.handle_response(response)
self.assertTrue(response in r.history)
auth.handle_other.assert_called_once_with(response_ok)
self.assertEqual(r, response_ok)
self.assertEqual(
request.headers['Authorization'],
'Negotiate GSSRESPONSE')
connection.send.assert_called_with(request)
raw.release_conn.assert_called_with()
clientInit_complete.assert_called_with(
"[email protected]",
gssflags=(
kerberos.GSS_C_MUTUAL_FLAG |
kerberos.GSS_C_SEQUENCE_FLAG),
principal=None)
clientStep_continue.assert_called_with("CTX", "token")
clientResponse.assert_called_with("CTX")
示例12: test_delegation
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import send [as 别名]
def test_delegation(self):
with patch.multiple('kerberos',
authGSSClientInit=clientInit_complete,
authGSSClientResponse=clientResponse,
authGSSClientStep=clientStep_continue):
response_ok = requests.Response()
response_ok.url = "http://www.example.org/"
response_ok.status_code = 200
response_ok.headers = {'www-authenticate': 'negotiate servertoken'}
connection = Mock()
connection.send = Mock(return_value=response_ok)
raw = Mock()
raw.release_conn = Mock(return_value=None)
request = requests.Request()
response = requests.Response()
response.request = request
response.url = "http://www.example.org/"
response.headers = {'www-authenticate': 'negotiate token'}
response.status_code = 401
response.connection = connection
response._content = ""
response.raw = raw
auth = requests_kerberos.HTTPKerberosAuth(1, "HTTP", True)
r = auth.authenticate_user(response)
self.assertTrue(response in r.history)
self.assertEqual(r, response_ok)
self.assertEqual(
request.headers['Authorization'],
'Negotiate GSSRESPONSE')
connection.send.assert_called_with(request)
raw.release_conn.assert_called_with()
clientInit_complete.assert_called_with(
"[email protected]",
gssflags=(
kerberos.GSS_C_MUTUAL_FLAG |
kerberos.GSS_C_SEQUENCE_FLAG |
kerberos.GSS_C_DELEG_FLAG))
clientStep_continue.assert_called_with("CTX", "token")
clientResponse.assert_called_with("CTX")
示例13: test_partial_send
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import send [as 别名]
def test_partial_send(self):
mock_sock = Mock()
mock_sock.send = Mock(return_value = 3)
string1 = "abcdefghi"
w = SocketReaderWriter(mock_sock)
w.tx_bytes(string1)
w.write_event()
assert mock_sock.send.called_with(string1)
w.write_event()
assert mock_sock.send.called_with(string1[3:])
w.write_event()
assert mock_sock.send.called_with(string1[6:])
call_count = mock_sock.send.call_count
w.write_event()
assert mock_sock.send.call_count == call_count
示例14: test_handle_response_401
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import send [as 别名]
def test_handle_response_401(self):
with patch.multiple('kerberos',
authGSSClientInit=clientInit_complete,
authGSSClientResponse=clientResponse,
authGSSClientStep=clientStep_continue):
response_ok = requests.Response()
response_ok.url = "http://www.example.org/"
response_ok.status_code = 200
response_ok.headers = {'www-authenticate': 'negotiate servertoken'}
connection = Mock()
connection.send = Mock(return_value=response_ok)
raw = Mock()
raw.release_conn = Mock(return_value=None)
request = requests.Request()
response = requests.Response()
response.request = request
response.url = "http://www.example.org/"
response.headers = {'www-authenticate': 'negotiate token'}
response.status_code = 401
response.connection = connection
response._content = ""
response.raw = raw
auth = requests_gssapi.HTTPGSSAPIAuth()
auth.handle_other = Mock(return_value=response_ok)
r = auth.handle_response(response)
self.assertTrue(response in r.history)
auth.handle_other.assert_called_with(response_ok)
self.assertEqual(r, response_ok)
self.assertEqual(request.headers['Authorization'], 'Negotiate GSSRESPONSE')
connection.send.assert_called_with(request)
raw.release_conn.assert_called_with()
clientInit_complete.assert_called_with("[email protected]")
clientStep_continue.assert_called_with("CTX", "token")
clientResponse.assert_called_with("CTX")
示例15: test_recover_single_txn
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import send [as 别名]
def test_recover_single_txn(self):
txn = Mock()
# return one txn to send, then no more old txns
txns = [txn, None]
def take_txn(*args, **kwargs):
return defer.succeed(txns.pop(0))
self.store.get_oldest_unsent_txn = Mock(side_effect=take_txn)
self.recoverer.recover()
# shouldn't have called anything prior to waiting for exp backoff
self.assertEquals(0, self.store.get_oldest_unsent_txn.call_count)
txn.send = Mock(return_value=True)
# wait for exp backoff
self.clock.advance_time(2)
self.assertEquals(1, txn.send.call_count)
self.assertEquals(1, txn.complete.call_count)
# 2 because it needs to get None to know there are no more txns
self.assertEquals(2, self.store.get_oldest_unsent_txn.call_count)
self.callback.assert_called_once_with(self.recoverer)
self.assertEquals(self.recoverer.service, self.service)