本文整理汇总了Python中mock.mock.MagicMock.force_repo_version方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.force_repo_version方法的具体用法?Python MagicMock.force_repo_version怎么用?Python MagicMock.force_repo_version使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.force_repo_version方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_set_current_with_force
# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import force_repo_version [as 别名]
def test_set_current_with_force(self, urlopen_mock, get_verbose_mock, get_ambari_server_api_base_mock,
get_ambari_properties_mock, get_validated_string_input_mock,
no_finalize_options_set_mock, is_server_runing_mock):
options = MagicMock()
options.cluster_name = 'cc'
options.desired_repo_version = 'HDP-2.2.2.0-2561'
options.force_repo_version = True
# Case when server is not running
is_server_runing_mock.return_value = False, None
try:
set_current(options)
self.fail("Server is not running - should error out")
except FatalException:
pass # expected
is_server_runing_mock.return_value = True, 11111
# Test insufficient options case
no_finalize_options_set_mock.return_value = True
try:
set_current(options)
self.fail("Should error out")
except FatalException:
pass # expected
no_finalize_options_set_mock.return_value = False
# Test normal flow
get_validated_string_input_mock.return_value = 'dummy_string'
p = get_ambari_properties_mock.return_value
p.get_property.side_effect = ["8080", "false"]
get_ambari_server_api_base_mock.return_value = 'http://127.0.0.1:8080/api/v1/'
get_verbose_mock.retun_value = False
set_current(options)
self.assertTrue(urlopen_mock.called)
request = urlopen_mock.call_args_list[0][0][0]
self.assertEquals(request._Request__original, 'http://127.0.0.1:8080/api/v1/clusters/cc/stack_versions')
self.assertEquals(request.data, '{"ClusterStackVersions": {"state": "CURRENT", "repository_version": "HDP-2.2.2.0-2561", "force": "true"}}')
self.assertEquals(request.origin_req_host, '127.0.0.1')
self.assertEquals(request.headers, {'X-requested-by': 'ambari', 'Authorization': 'Basic ZHVtbXlfc3RyaW5nOmR1bW15X3N0cmluZw=='})