Python mock.sentinel() Examples
The following are 30
code examples of mock.sentinel().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
mock
, or try the search function
.
Example #1
Source File: arista_test.py From netman with Apache License 2.0 | 6 votes |
def test_arista_instance_with_proper_transport(self): pyeapi_client_node = mock.sentinel flexmock(pyeapi).should_receive('connect').once() \ .with_args(host="1.2.3.4", username="you sir name", password="paw sword", port=8888, transport="trololo", return_node=True, timeout=300) \ .and_return(pyeapi_client_node) switch = Arista( SwitchDescriptor(model='arista', hostname="1.2.3.4", username="you sir name", password="paw sword", port=8888), transport="trololo" ) switch._connect() assert_that(switch.node, is_(pyeapi_client_node))
Example #2
Source File: test_ephemeraldisk.py From cloudbase-init with Apache License 2.0 | 6 votes |
def _test_get_ephemeral_disk_volume_by_label(self, label, ephemeral_disk_volume_label): expected_result = None mock_osutils = mock.MagicMock() if ephemeral_disk_volume_label: labels = [None, str(mock.sentinel.label)] * 2 labels += [label] + [None, str(mock.sentinel.label)] mock_osutils.get_logical_drives.return_value = range(len(labels)) mock_osutils.get_volume_label.side_effect = labels if label.upper() == ephemeral_disk_volume_label.upper(): expected_result = labels.index(label) with testutils.ConfPatcher('ephemeral_disk_volume_label', ephemeral_disk_volume_label): result = self._disk._get_ephemeral_disk_volume_by_label( mock_osutils) self.assertEqual(result, expected_result) if ephemeral_disk_volume_label: mock_osutils.get_logical_drives.assert_called_once_with() if expected_result is not None: self.assertEqual(mock_osutils.get_volume_label.call_count, expected_result + 1) else: self.assertEqual(mock_osutils.get_volume_label.call_count, len(labels))
Example #3
Source File: test_ephemeraldisk.py From cloudbase-init with Apache License 2.0 | 6 votes |
def _test_set_ephemeral_disk_data_loss_warning(self, exception_raised): mock_service = mock.MagicMock() disk_warning_path = str(mock.sentinel.disk_warning_path) expected_logging = [ "Setting ephemeral disk data loss warning: %s" % disk_warning_path ] if exception_raised: eclass = metadata_services_base.NotExistingMetadataException mock_service.get_ephemeral_disk_data_loss_warning.side_effect = \ eclass expected_logging += [ "Metadata service does not provide an ephemeral " "disk data loss warning content" ] else: mock_service.get_ephemeral_disk_data_loss_warning.return_value = \ str(mock.sentinel.data_loss_warning) with testutils.LogSnatcher(MODULE_PATH) as snatcher: with mock.patch(MODULE_PATH + '.open', mock.mock_open(), create=True) as mock_open: self._disk._set_ephemeral_disk_data_loss_warning( mock_service, disk_warning_path) self.assertEqual(snatcher.output, expected_logging) mock_open.assert_called_once_with(disk_warning_path, 'wb')
Example #4
Source File: arista_test.py From netman with Apache License 2.0 | 6 votes |
def test_arista_uses_command_timeout(self): arista.default_command_timeout = 500 pyeapi_client_node = mock.sentinel flexmock(pyeapi).should_receive('connect').once() \ .with_args(host="1.2.3.4", username=None, password=None, port=None, transport="trololo", return_node=True, timeout=500) \ .and_return(pyeapi_client_node) switch = Arista( SwitchDescriptor(model='arista', hostname="1.2.3.4"), transport="trololo" ) switch._connect()
Example #5
Source File: test_windows.py From cloudbase-init with Apache License 2.0 | 6 votes |
def test__get_forward_table_insufficient_buffer_no_memory(self): self._kernel32.HeapAlloc.side_effect = (mock.sentinel.table_mem, None) self._iphlpapi.GetIpForwardTable.return_value = ( self._winutils.ERROR_INSUFFICIENT_BUFFER) with self.assertRaises(exception.CloudbaseInitException): with self._winutils._get_forward_table(): pass table = self._ctypes_mock.cast.return_value self._iphlpapi.GetIpForwardTable.assert_called_once_with( table, self._ctypes_mock.byref.return_value, 0) heap_calls = [ mock.call(self._kernel32.GetProcessHeap.return_value, 0, table), mock.call(self._kernel32.GetProcessHeap.return_value, 0, table) ] self.assertEqual(heap_calls, self._kernel32.HeapFree.mock_calls)
Example #6
Source File: test_pod_launcher.py From airflow with Apache License 2.0 | 6 votes |
def test_read_pod_logs_successfully_with_tail_lines(self): mock.sentinel.metadata = mock.MagicMock() self.mock_kube_client.read_namespaced_pod_log.side_effect = [ mock.sentinel.logs ] logs = self.pod_launcher.read_pod_logs(mock.sentinel, 100) self.assertEqual(mock.sentinel.logs, logs) self.mock_kube_client.read_namespaced_pod_log.assert_has_calls([ mock.call( _preload_content=False, container='base', follow=True, name=mock.sentinel.metadata.name, namespace=mock.sentinel.metadata.namespace, tail_lines=100 ), ])
Example #7
Source File: test_windows.py From cloudbase-init with Apache License 2.0 | 6 votes |
def _test_take_path_ownership(self, mock_execute_system32_process, ret_val=None, username=None): mock_path = mock.sentinel.path expected_logging = ["Taking ownership of path: %s" % mock_path] expected_call = ["takeown.exe", "/F", mock_path] mock_execute_system32_process.return_value = ( mock.sentinel.out, mock.sentinel.err, ret_val) if username: self.assertRaises( NotImplementedError, self._winutils.take_path_ownership, mock_path, username) return with self.snatcher: if ret_val: self.assertRaises( exception.CloudbaseInitException, self._winutils.take_path_ownership, mock_path, username) else: self._winutils.take_path_ownership(mock_path, username) self.assertEqual(self.snatcher.output, expected_logging) mock_execute_system32_process.assert_called_once_with(expected_call)
Example #8
Source File: test_windows.py From cloudbase-init with Apache License 2.0 | 6 votes |
def _test_set_path_admin_acls(self, mock_execute_system32_process, ret_val=None): mock_path = mock.sentinel.path expected_logging = ["Assigning admin ACLs on path: %s" % mock_path] expected_call = [ "icacls.exe", mock_path, "/inheritance:r", "/grant:r", "*S-1-5-18:(OI)(CI)F", "*S-1-5-32-544:(OI)(CI)F"] mock_execute_system32_process.return_value = ( mock.sentinel.out, mock.sentinel.err, ret_val) with self.snatcher: if ret_val: self.assertRaises( exception.CloudbaseInitException, self._winutils.set_path_admin_acls, mock_path) else: self._winutils.set_path_admin_acls(mock_path) self.assertEqual(self.snatcher.output, expected_logging) mock_execute_system32_process.assert_called_once_with(expected_call)
Example #9
Source File: test_windows.py From cloudbase-init with Apache License 2.0 | 6 votes |
def _test_enum_users(self, resume_handle=False, exc=None): userenum_mock = self._win32net_mock.NetUserEnum if exc is not None: userenum_mock.side_effect = [exc] with self.assertRaises(exception.CloudbaseInitException): self._winutils.enum_users() return else: userenum_mock.side_effect = ( [([{"name": "fake name"}], mock.sentinel, False)] * 3 + [([{"name": "fake name"}], mock.sentinel, resume_handle)]) self._winutils.enum_users() result = self._winutils.enum_users() if resume_handle: self.assertEqual(result, ["fake name"] * 3)
Example #10
Source File: test_windows.py From cloudbase-init with Apache License 2.0 | 6 votes |
def test_execute_process_as_user_fail(self, mock_list2cmdline, mock_proc_info, mock_startup_info): advapi32 = self._windll_mock.advapi32 advapi32.CreateProcessAsUserW.side_effect = [False, True] kernel32 = self._ctypes_mock.windll.kernel32 kernel32.GetExitCodeProcess.return_value = False mock_proc_info.hProcess = True token = mock.sentinel.token args = mock.sentinel.args new_console = mock.sentinel.new_console with self.assert_raises_windows_message("CreateProcessAsUserW " "failed: %r", 100): self._winutils.execute_process_as_user(token, args, False, new_console) with self.assert_raises_windows_message("GetExitCodeProcess " "failed: %r", 100): self._winutils.execute_process_as_user(token, args, True, new_console)
Example #11
Source File: test_windows.py From cloudbase-init with Apache License 2.0 | 6 votes |
def test_set_service_credentials(self, mock_get_service): self._win32service_mock.SERVICE_CHANGE_CONFIG = mock.sentinel.change self._win32service_mock.SERVICE_NO_CHANGE = mock.sentinel.no_change mock_change_service = self._win32service_mock.ChangeServiceConfig mock_context_manager = mock.MagicMock() mock_context_manager.__enter__.return_value = mock.sentinel.hs mock_get_service.return_value = mock_context_manager self._winutils.set_service_credentials( mock.sentinel.service, mock.sentinel.user, mock.sentinel.password) mock_get_service.assert_called_with(mock.sentinel.service, mock.sentinel.change) mock_change_service.assert_called_with( mock.sentinel.hs, mock.sentinel.no_change, mock.sentinel.no_change, mock.sentinel.no_change, None, None, False, None, mock.sentinel.user, mock.sentinel.password, None)
Example #12
Source File: test_windows.py From cloudbase-init with Apache License 2.0 | 6 votes |
def test_create_service(self, mock_get_service_control_manager): mock_hs = mock.MagicMock() mock_service_name = "fake name" mock_start_mode = "Automatic" mock_display_name = mock.sentinel.mock_display_name mock_path = mock.sentinel.path mock_get_service_control_manager.return_value = mock_hs with self.snatcher: self._winutils.create_service(mock_service_name, mock_display_name, mock_path, mock_start_mode) self.assertEqual(["Creating service fake name"], self.snatcher.output) mock_get_service_control_manager.assert_called_once_with( scm_access=self._win32service_mock.SC_MANAGER_CREATE_SERVICE) self._win32service_mock.CreateService.assert_called_once_with( mock_hs.__enter__(), mock_service_name, mock_display_name, self._win32service_mock.SERVICE_ALL_ACCESS, self._win32service_mock.SERVICE_WIN32_OWN_PROCESS, self._win32service_mock.SERVICE_AUTO_START, self._win32service_mock.SERVICE_ERROR_NORMAL, mock_path, None, False, None, None, None)
Example #13
Source File: test_windows.py From cloudbase-init with Apache License 2.0 | 6 votes |
def test_get_service_handle(self): open_scm = self._win32service_mock.OpenSCManager open_scm.return_value = mock.sentinel.hscm open_service = self._win32service_mock.OpenService open_service.return_value = mock.sentinel.hs close_service = self._win32service_mock.CloseServiceHandle args = ("fake_name", mock.sentinel.service_access, mock.sentinel.scm_access) with self._winutils._get_service_handle(*args) as hs: self.assertIs(hs, mock.sentinel.hs) open_scm.assert_called_with(None, None, mock.sentinel.scm_access) open_service.assert_called_with(mock.sentinel.hscm, "fake_name", mock.sentinel.service_access) close_service.assert_has_calls([mock.call(mock.sentinel.hs), mock.call(mock.sentinel.hscm)])
Example #14
Source File: test_proxy.py From openstacksdk with Apache License 2.0 | 5 votes |
def setUp(self): super(TestProxyBulkCreate, self).setUp() class Res(resource.Resource): pass self.session = mock.Mock() self.result = mock.sentinel self.data = mock.Mock() self.sot = proxy.Proxy(self.session) self.cls = Res self.cls.bulk_create = mock.Mock(return_value=self.result)
Example #15
Source File: dataflow_test.py From MARA_Framework with GNU Lesser General Public License v3.0 | 5 votes |
def testSplitVariablesGCD(self, group_variables_mock): group = { 'a': [([-1], [0])], 'b': [([-2], [1])], 'c': [([0, 6], [2, 5, 6, 7, 8])], 'd': [([1], [3, 4, 5, 6, 7])], 'ret': [([3, 8], [9])] } group_variables_mock.return_value = group dataflow.split_variables( mock.sentinel, [0, 1, 2, 3, 4], mock.sentinel, mock.sentinel)
Example #16
Source File: test_proxy.py From openstacksdk with Apache License 2.0 | 5 votes |
def test_validate_topology(self): self.verify_get(self.proxy.validate_auto_allocated_topology, auto_allocated_topology.ValidateTopology, value=[mock.sentinel.project_id], expected_args=[ auto_allocated_topology.ValidateTopology], expected_kwargs={"project": mock.sentinel.project_id, "requires_id": False})
Example #17
Source File: test_proxy.py From openstacksdk with Apache License 2.0 | 5 votes |
def test_set_tags(self): x_network = network.Network.new(id='NETWORK_ID') self._verify('openstack.network.v2.network.Network.set_tags', self.proxy.set_tags, method_args=[x_network, ['TAG1', 'TAG2']], expected_args=[['TAG1', 'TAG2']], expected_result=mock.sentinel.result_set_tags)
Example #18
Source File: test_proxy.py From openstacksdk with Apache License 2.0 | 5 votes |
def test_security_group_rules_create(self, bc): data = mock.sentinel self.proxy.create_security_group_rules(data) bc.assert_called_once_with(security_group_rule.SecurityGroupRule, data)
Example #19
Source File: test_metadata_service_app.py From dragonflow with Apache License 2.0 | 5 votes |
def test_proxy_get_host(self): host = self.proxy.get_host(mock.sentinel) self.assertEqual('nova-host:443', host)
Example #20
Source File: test_metadata_service_app.py From dragonflow with Apache License 2.0 | 5 votes |
def test_proxy_get_scheme(self): scheme = self.proxy.get_scheme(mock.sentinel) self.assertEqual('https', scheme)
Example #21
Source File: test_ephemeraldisk.py From cloudbase-init with Apache License 2.0 | 5 votes |
def test_get_ephemeral_disk_volume_by_label(self): self._test_get_ephemeral_disk_volume_by_label( label=str(mock.sentinel.same_label), ephemeral_disk_volume_label=str(mock.sentinel.same_label))
Example #22
Source File: test_auth.py From stethoscope with Apache License 2.0 | 5 votes |
def test_route_token_required(self): request = requestMock(b"/", headers={b'Authorization': [str(mock.sentinel)]}) returned = self.app.execute_endpoint("token_required_endpoint", request) self.assertEqual(returned, self.userinfo) self.auth.decode_header_value.assert_called_once_with(str(mock.sentinel))
Example #23
Source File: test_auth.py From stethoscope with Apache License 2.0 | 5 votes |
def test_match_required_raises(self): """Tests that an exception is raised if the token's value doesn't match the given email.""" @self.auth.match_required def wrapped(request, userinfo, email=None): return userinfo request = mock.create_autospec(twisted.web.http.Request) request.getCookie.return_value = mock.sentinel with pytest.raises(werkzeug.exceptions.Forbidden): with mock.patch.object(self.auth, '_debug', False): # ensure check actually happens wrapped(request, email='baduser@example.com')
Example #24
Source File: test_auth.py From stethoscope with Apache License 2.0 | 5 votes |
def test_match_required_injects(self): """Tests both that the token value is injected and that that value matches the given email.""" @self.auth.match_required def wrapped(request, userinfo, email=None): return userinfo request = mock.create_autospec(twisted.web.http.Request) request.getCookie.return_value = mock.sentinel self.assertEqual(wrapped(request, email='user@example.com'), {'sub': 'user@example.com'})
Example #25
Source File: test_auth.py From stethoscope with Apache License 2.0 | 5 votes |
def test_token_required_injects(self): """Tests that the token value is appended to the wrapped function's arguments.""" @self.auth.token_required def wrapped(request, userinfo): return userinfo request = mock.create_autospec(twisted.web.http.Request) request.getCookie.return_value = mock.sentinel self.assertEqual(wrapped(request), {'sub': 'user@example.com'})
Example #26
Source File: dataflow_test.py From AndroBugs_Framework with GNU General Public License v3.0 | 5 votes |
def testSplitVariablesGCD(self, group_variables_mock): group = {'a': [([-1], [0])], 'b': [([-2], [1])], 'c': [([0, 6], [2, 5, 6, 7, 8])], 'd': [([1], [3, 4, 5, 6, 7])], 'ret': [([3, 8], [9])]} group_variables_mock.return_value = group dataflow.split_variables( mock.sentinel, [0, 1, 2, 3, 4], mock.sentinel, mock.sentinel)
Example #27
Source File: dataflow_test.py From TimeMachine with GNU Lesser General Public License v3.0 | 5 votes |
def testSplitVariablesGCD(self, group_variables_mock): group = {'a': [([-1], [0])], 'b': [([-2], [1])], 'c': [([0, 6], [2, 5, 6, 7, 8])], 'd': [([1], [3, 4, 5, 6, 7])], 'ret': [([3, 8], [9])]} group_variables_mock.return_value = group dataflow.split_variables( mock.sentinel, [0, 1, 2, 3, 4], mock.sentinel, mock.sentinel)
Example #28
Source File: test_ephemeraldisk.py From cloudbase-init with Apache License 2.0 | 5 votes |
def test_execute(self): self._test_execute( not_existing_exception=None, disk_volume_path=str(mock.sentinel.disk_volume_path), disk_warning_path=str(mock.sentinel.path))
Example #29
Source File: test_ephemeraldisk.py From cloudbase-init with Apache License 2.0 | 5 votes |
def _test_execute(self, mock_get_osutils, mock_get_volume_path, mock_set_volume_path, mock_join, not_existing_exception, disk_volume_path, disk_warning_path): mock_service = mock.MagicMock() shared_data = mock.sentinel.shared_data eclass = metadata_services_base.NotExistingMetadataException expected_result = base.PLUGIN_EXECUTION_DONE, False expected_logging = [] if not_existing_exception: mock_service.get_ephemeral_disk_data_loss_warning.side_effect = \ eclass() else: mock_osutils = mock.MagicMock() mock_get_osutils.return_value = mock_osutils mock_get_volume_path.return_value = disk_volume_path if not disk_volume_path: expected_logging += [ "Ephemeral disk volume not found" ] else: mock_join.return_value = disk_warning_path with testutils.ConfPatcher('ephemeral_disk_data_loss_warning_path', disk_warning_path): with testutils.LogSnatcher(MODULE_PATH) as snatcher: result = self._disk.execute(mock_service, shared_data) self.assertEqual(result, expected_result) self.assertEqual(snatcher.output, expected_logging) (mock_service.get_ephemeral_disk_data_loss_warning. assert_called_once_with()) if not not_existing_exception: mock_get_osutils.assert_called_once_with() mock_get_volume_path.assert_called_once_with(mock_osutils) if disk_volume_path and disk_warning_path: mock_join.assert_called_once_with( disk_volume_path, disk_warning_path) mock_set_volume_path.assert_called_once_with( mock_service, disk_warning_path)
Example #30
Source File: test_windows.py From cloudbase-init with Apache License 2.0 | 5 votes |
def test_add_network_team_nic(self, mock_get_network_team_manager): mock_team_manager = mock_get_network_team_manager.return_value self._winutils.add_network_team_nic( mock.sentinel.team_name, mock.sentinel.nic_name, mock.sentinel.vlan_id) mock_team_manager.add_team_nic.assert_called_once_with( mock.sentinel.team_name, mock.sentinel.nic_name, mock.sentinel.vlan_id)