本文整理汇总了Python中mock.assert_called_once_with函数的典型用法代码示例。如果您正苦于以下问题:Python assert_called_once_with函数的具体用法?Python assert_called_once_with怎么用?Python assert_called_once_with使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_called_once_with函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_search_several_param
def test_search_several_param(self, mock):
keywords = ['one', 'two']
mock.return_value = (200, MOCK_CONFIGURATION_SEARCH_JSON, MOCK_CONFIGURATION_SEARCH_JSON_RAW)
status_code, json_response = maccli.dao.api_configuration.search_public_configuration(keywords)
mock.assert_called_once_with("GET", "/configuration/search?keyword=one&keyword=two")
self.assertEqual(json_response, MOCK_CONFIGURATION_SEARCH_JSON)
self.assertEqual(status_code, 200)
示例2: test_instance_destroy_error_not_found
def test_instance_destroy_error_not_found(self, mock):
mock.return_value = (404, None, "Error Response")
json_response = maccli.dao.api_instance.destroy(DEFAULT_SERVERNAME)
mock.assert_called_once_with("DELETE", "/instance/%s" % DEFAULT_SERVERNAME)
error = self.buf.getvalue()
self.assertEqual(' '.join(MOCK_RESPONSE_INSTANCE_DESTROY_NOT_FOUND.split()), ' '.join(error.split()))
self.assertEqual(json_response, None)
示例3: _test_assert_called_once_with
def _test_assert_called_once_with(self, mock, resource,
chk_interval, time_out, **kwargs):
"""Method to replace repeatative asserts on resources
:param mock: The mock to call assert with
:param resource: The resource used in mock
:param chk_interval: The interval used for polling the action
:param time_out: Time out value for action
:param kwargs: currently used for validating the is_ready attribute,
can be extended as required
"""
isready = self.res_is.mock()
if kwargs:
if kwargs["is_ready"]:
mock.assert_called_once_with(
resource,
update_resource=self.gfm(),
is_ready=isready,
check_interval=chk_interval,
timeout=time_out)
else:
mock.assert_called_once_with(
resource,
update_resource=self.gfm(),
check_interval=chk_interval,
timeout=time_out)
示例4: test_ip_ns_route
def test_ip_ns_route(self, mock):
ns_list = commands.ip_ns_list()
for ns in ns_list:
expected = ['/usr/bin/sudo', '-n', 'ip', 'netns', 'exec', ns,
'ip', 'r']
commands.ip_ns_route(ns)
mock.assert_called_once_with(expected, **self.subprocess_args)
示例5: test_hardwares_ok
def test_hardwares_ok(self, mock):
mock.return_value = (200, MOCK_HARDWARE_LIST_JSON, MOCK_HARDWARE_LIST_JSON_RAW)
status_code, json_response = maccli.dao.api_provider.get_hardwares(DEFAULT_PROVIDER, DEFAULT_LOCATION, DEFAULT_CONFIGURATION, DEFAULT_RELEASE)
mock.assert_called_once_with("GET", "/provider/hardware?provider=%s&location=%s&release=%s&cookbook_tag=%s" % (
DEFAULT_PROVIDER, DEFAULT_LOCATION, DEFAULT_RELEASE, DEFAULT_CONFIGURATION))
self.assertEqual(json_response, MOCK_HARDWARE_LIST_JSON)
self.assertEqual(status_code, 200)
示例6: test_locations
def test_locations(self, mock):
mock.return_value = (200, MOCK_LOCATION_LIST_JSON, MOCK_LOCATION_LIST_JSON_RAW)
status_code, json_response = maccli.dao.api_provider.get_locations(DEFAULT_CONFIGURATION, DEFAULT_PROVIDER)
mock.assert_called_once_with("GET", "/provider/locations?cookbook_tag=%s&provider=%s" % (
DEFAULT_CONFIGURATION, DEFAULT_PROVIDER))
self.assertEqual(json_response, MOCK_LOCATION_LIST_JSON)
self.assertEqual(status_code, 200)
示例7: test_iptables_raw
def test_iptables_raw(self, mock):
table = 'filter'
expected = ['/usr/bin/sudo', '-n', 'iptables', '--line-numbers',
'-L', '-nv', '-t',
'%s' % table]
commands.iptables_raw(table)
mock.assert_called_once_with(expected, **self.subprocess_args)
示例8: test_instance_destroy_error
def test_instance_destroy_error(self, mock):
mock.return_value = (400, None, "Error Response")
json_response = maccli.dao.api_instance.destroy(DEFAULT_SERVER_ID)
mock.assert_called_once_with("DELETE", "/instance/%s" % DEFAULT_SERVER_ID)
error = self.buf.getvalue()
self.assertEqual(" ".join(MOCK_RESPONSE_INSTANCE_DESTROY_ERROR.split()), " ".join(error.split()))
self.assertEqual(json_response, None)
示例9: test_is_tracing_returns_what_tracing_percent_method_returns_for_rest
def test_is_tracing_returns_what_tracing_percent_method_returns_for_rest(
mock, dummy_request
):
dummy_request.zipkin_trace_id = '42'
assert mock.return_value == request_helper.is_tracing(dummy_request)
mock.assert_called_once_with(
request_helper.DEFAULT_REQUEST_TRACING_PERCENT, '42'
)
示例10: test_iptables_ns
def test_iptables_ns(self, mock):
table = 'filter'
ns_list = commands.ip_ns_list()
for ns in ns_list:
expected = ['/usr/bin/sudo', '-n', 'ip', 'netns', 'exec', ns,
'iptables', '-v', '-S', '-t', table]
commands.iptables_ns(ns, table)
mock.assert_called_once_with(expected, **self.subprocess_args)
示例11: test_hardwares_error
def test_hardwares_error(self, mock):
mock.return_value = (400, None, "No credentials available")
status_code, json_response = maccli.dao.api_provider.get_hardwares(DEFAULT_PROVIDER, DEFAULT_LOCATION, DEFAULT_CONFIGURATION, DEFAULT_RELEASE)
mock.assert_called_once_with("GET", "/provider/hardware?provider=%s&location=%s&release=%s&cookbook_tag=%s" % (
DEFAULT_PROVIDER, DEFAULT_LOCATION, DEFAULT_RELEASE, DEFAULT_CONFIGURATION))
self.assertEqual(json_response, None)
self.assertEqual(status_code, 400)
out = self.buf.getvalue()
self.assertEqual(' '.join(OUTPUT_HARDWARES_NO_CREDENTIALS.split()), ' '.join(out.split()))
示例12: test_output_is_sourceable
def test_output_is_sourceable(mock, releases_dictionary):
bash_script = '/foo/bar.sh'
assert (write_releases_dictionary_to_bash(releases_dictionary,
bash_script))
mock.assert_called_once_with(bash_script, 'w')
handle = mock()
args, _ = handle.write.call_args
written_content = args[0]
# TODO(Llorente): check environment variables
assert (0 == os.system(written_content))
示例13: test_instance_create_error
def test_instance_create_error(self, mock):
mock.return_value = (400, None, "Error Response")
json_response = maccli.dao.api_instance.create(DEFAULT_CONFIGURATION, DEFAULT_BOOTSTRAP, DEFAULT_DEPLOYMENT, DEFAULT_LOCATION,
DEFAULT_SERVERNAME,
DEFAULT_PROVIDER, DEFAULT_RELEASE, DEFAULT_RELEASE_VERSION, DEFAULT_BRANCH,
DEFAULT_HARDWARE, DEFAULT_LIFESPAN, DEFAULT_ENVIRONMENT,
DEFAULT_HD, DEFAULT_PORT, DEFAULT_NET, DEFAULT_METADATA, DEFAULT_APPLYCHANGES)
mock.assert_called_once_with("POST", "/instance", data=MOCK_INSTANCE_CREATE_PARAMETERS_JSON_RAW)
error = self.buf.getvalue()
self.assertEqual(' '.join(MOCK_RESPONSE_INSTANCE_CREATE_ERROR.split()), ' '.join(error.split()))
self.assertEqual(json_response, None)
示例14: test_all_running_options
def test_all_running_options(self, mock):
jid = "[email protected]"
room = "[email protected]"
password = "password"
nick = "nick"
args = ["test", "-j", jid, "-p", password, "-r", room, "-n", nick]
self.assertIsNone(nonobot.main.main(args))
mock.assert_called_once_with(jid=jid, room=room, password=password, nick=nick, plugins={"help": []})
示例15: test_list_with_pagination
def test_list_with_pagination(self, mock):
self.call(execution_cmd.List)
mock.assert_called_once_with(limit=None, marker='',
sort_dirs='asc',
sort_keys='created_at')
self.call(execution_cmd.List, app_args=['--limit', '5',
'--sort_dirs', 'id, Workflow',
'--sort_keys', 'desc',
'--marker', 'abc'])
mock.assert_called_with(limit=5, marker='abc',
sort_dirs='id, Workflow',
sort_keys='desc')