How to use the mock.mock.patch function in mock

To help you get started, we’ve selected a few mock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SUSE / DeepSea / tests / unit / _modules / test_proposal.py View on Github external
    @mock.patch('srv.salt._modules.proposal._device')
    def test_propose(self, pd, output_helper):
        pd.return_value = "/dev/sda"
        p = proposal.Proposal(output_helper.cephdisks_output)
        prop = p._propose(p.ssd, p.nvme)
        assert len(prop) is p.DEFAULT_DATA_R

        r = 4
        p = proposal.Proposal(output_helper.cephdisks_output, ratio=r,
                              leftovers=True)
        expected_len = r + (len(p.ssd) - r)
        prop = p._propose(p.ssd, p.nvme)
        assert len(prop) is expected_len
github algosec / algosec-python / tests / test_api_clients / test_business_flow.py View on Github external
    @mock.patch(
        "algosec.api_clients.business_flow.BusinessFlowAPIClient.create_network_object"
    )
    def test_create_missing_network_objects(
        self,
        mock_create_network_object,
        mock_search_network_objects,
        mock_is_ip_or_subnet,
        client,
        mock_session,
        mock_check_response,
    ):
        def is_ip_or_subnet(string):
            if string == "non-ip-or-subnet":
                return False
            return True
github claranet / cloud-deploy / tests / test_commands_bluegreen.py View on Github external
@mock.patch('commands.preparebluegreen.get_blue_green_create_temporary_elb_config', new=lambda a: True)
@mock.patch('commands.preparebluegreen.log', new=mocked_logger)
@mock.patch('ghost_tools.log', new=mocked_logger)
@mock.patch('ghost_aws.log', new=mocked_logger)
def test_prepare_bluegreen(get_blue_green_apps,
                           cloud_connections,
                           get_autoscaling_group_and_processes_to_suspend,
                           suspend_autoscaling_group_processes,
                           resume_autoscaling_group_processes,
                           update_auto_scale,
                           load_balancing):
    # Set up mocks and variables
    green_app = get_test_application(name="test-app-green", _id='id_green', autoscale={'name': 'autoscale-green'})
    blue_app = get_test_application(name="test-app-blue", _id='id_blue', autoscale={'name': 'autoscale-blue'})

    connection_mock = MagicMock()
    connection_pool = MagicMock()
github CCExtractor / sample-platform / tests / test_ci / TestControllers.py View on Github external
    @mock.patch('mod_ci.controllers.int')
    @mock.patch('mod_ci.controllers.GeneralData')
    @mock.patch('mod_ci.controllers.g')
    def test_set_avg_time(self, mock_g, mock_gd, mock_int):
        """
        Test setting average time for NOT first time.
        """
        from mod_ci.controllers import set_avg_time

        mock_int.return_value = 5

        set_avg_time(TestPlatform.windows, "prep", 100)

        mock_gd.query.filter.assert_called_with(mock_gd.key == 'avg_prep_count_windows')
        self.assertEqual(mock_gd.call_count, 0)
        self.assertEqual(mock_g.db.add.call_count, 0)
        mock_g.db.commit.assert_called_once()
github claranet / cloud-deploy / tests / test_commands_bluegreen.py View on Github external
@mock.patch('ghost_tools.log', new=mocked_logger)
@mock.patch('ghost_aws.log', new=mocked_logger)
def test_swap_bluegreen_clb(get_blue_green_apps,
                            cloud_connections,
                            get_autoscaling_group_and_processes_to_suspend,
                            suspend_autoscaling_group_processes,
                            resume_autoscaling_group_processes,
                            load_balancing):
    # Set up mocks and variables
    green_app = get_test_application(name="test-app-green", _id='id_green', autoscale={'name': 'autoscale-green'},
                                     blue_green={"is_online": True, "color": "green"})
    blue_app = get_test_application(name="test-app-blue", _id='id_blue', autoscale={'name': 'autoscale-blue'},
                                    blue_green={"is_online": False, "color": "blue"})

    connection_mock = MagicMock()
    connection_pool = MagicMock()
    cloud_connections.get.return_value.return_value = connection_pool
github bloomberg / powerfulseal / tests / metriccollectors / test_collector.py View on Github external
def test_add_filtered_to_empty_set_metric(noop_scenario):
    with mock.patch('powerfulseal.metriccollectors.StdoutCollector.add_filtered_to_empty_set_metric') \
            as metric_function:
        metric_function.assert_not_called()
        noop_scenario.execute()
        metric_function.assert_called()
github CCExtractor / sample-platform / tests / test_ci / TestControllers.py View on Github external
    @mock.patch('mod_ci.controllers.Test')
    @mock.patch('mod_ci.controllers.logupload_type_request')
    def test_progress_reporter_logupload_type_empty(self, mock_logupload_type, mock_test, mock_request):
        """
        Test progress_reporter with request type logupload returning 'EMPTY'.
        """
        from mod_ci.controllers import progress_reporter

        mock_test_obj = MagicMock()
        mock_test_obj.token = "token"
        mock_test.query.filter.return_value.first.return_value = mock_test_obj
        mock_request.form = {'type': 'logupload'}
        mock_logupload_type.return_value = "EMPTY"

        expected_ret = "EMPTY"

        ret_val = progress_reporter(1, "token")
github dmwm / WMCore / test / python / WMCore_t / Storage_t / Backends_t / GFAL2Impl_t.py View on Github external
    @mock.patch('WMCore.Storage.StageOutImpl.StageOutImpl.executeCommand')
    def testRemoveFile(self, mock_executeCommand, mock_path):
        mock_path.isfile.return_value = False
        self.GFAL2Impl.removeFile("file://name")
        mock_executeCommand.assert_called_with("removeCommand file://name")
github fabfuel / ecs-deploy / tests / test_cli.py View on Github external
@patch('ecs_deploy.cli.get_client')
def test_update_task_empty_environment_variable_again(get_client, runner):
    get_client.return_value = EcsTestClient('acces_key', 'secret_key')
    result = runner.invoke(cli.update, (TASK_DEFINITION_ARN_1, '-e', 'webserver', 'empty', ''))

    assert result.exit_code == 0
    assert not result.exception

    assert u"Update task definition based on: test-task:1" in result.output
    assert u"Updating task definition" not in result.output
    assert u'Changed environment' not in result.output
    assert u'Successfully created revision: 2' in result.output