Esempio n. 1
0
def _present(name='testname',
             tick_script='/tmp/script.tick',
             task_type='stream',
             database='testdb',
             retention_policy='default',
             enable=True,
             task=None,
             define_result=True,
             enable_result=True,
             disable_result=True,
             script='test'):
    get_mock = Mock(return_value=task)
    define_mock = Mock(return_value=define_result)
    enable_mock = Mock(return_value=enable_result)
    disable_mock = Mock(return_value=disable_result)
    with patch.dict(kapacitor.__salt__, {
        'kapacitor.get_task': get_mock,
        'kapacitor.define_task': define_mock,
        'kapacitor.enable_task': enable_mock,
        'kapacitor.disable_task': disable_mock,
    }):
        with patch('salt.utils.fopen', mock_open(read_data=script)) as open_mock:
            retval = kapacitor.task_present(name, tick_script, task_type=task_type,
                database=database, retention_policy=retention_policy, enable=enable)
    return retval, get_mock, define_mock, enable_mock, disable_mock
def _present(
    name="testname",
    tick_script="/tmp/script.tick",
    task_type="stream",
    database="testdb",
    retention_policy="default",
    dbrps=None,
    enable=True,
    task=None,
    define_result=True,
    enable_result=True,
    disable_result=True,
    script="testscript",
):
    """
    Run a "kapacitor.present" state after setting up mocks, and return the
    state return value as well as the mocks to make assertions.
    """
    get_mock = Mock(return_value=task)

    if isinstance(define_result, bool):
        define_result = {"success": define_result}
    define_mock = Mock(return_value=define_result)

    if isinstance(enable_result, bool):
        enable_result = {"success": enable_result}
    enable_mock = Mock(return_value=enable_result)

    if isinstance(disable_result, bool):
        disable_result = {"success": disable_result}
    disable_mock = Mock(return_value=disable_result)

    with patch.dict(
            kapacitor.__salt__,
        {
            "kapacitor.get_task": get_mock,
            "kapacitor.define_task": define_mock,
            "kapacitor.enable_task": enable_mock,
            "kapacitor.disable_task": disable_mock,
        },
    ):
        with patch("salt.utils.files.fopen",
                   mock_open(read_data=script)) as open_mock:
            retval = kapacitor.task_present(
                name,
                tick_script,
                task_type=task_type,
                database=database,
                retention_policy=retention_policy,
                enable=enable,
                dbrps=dbrps,
            )

    return retval, get_mock, define_mock, enable_mock, disable_mock
Esempio n. 3
0
def _present(name='testname',
             tick_script='/tmp/script.tick',
             task_type='stream',
             database='testdb',
             retention_policy='default',
             dbrps=None,
             enable=True,
             task=None,
             define_result=True,
             enable_result=True,
             disable_result=True,
             script='testscript'):
    '''
    Run a "kapacitor.present" state after setting up mocks, and return the
    state return value as well as the mocks to make assertions.
    '''
    get_mock = Mock(return_value=task)

    if isinstance(define_result, bool):
        define_result = {'success': define_result}
    define_mock = Mock(return_value=define_result)

    if isinstance(enable_result, bool):
        enable_result = {'success': enable_result}
    enable_mock = Mock(return_value=enable_result)

    if isinstance(disable_result, bool):
        disable_result = {'success': disable_result}
    disable_mock = Mock(return_value=disable_result)

    with patch.dict(
            kapacitor.__salt__, {
                'kapacitor.get_task': get_mock,
                'kapacitor.define_task': define_mock,
                'kapacitor.enable_task': enable_mock,
                'kapacitor.disable_task': disable_mock,
            }):
        with patch('salt.utils.files.fopen',
                   mock_open(read_data=script)) as open_mock:
            retval = kapacitor.task_present(name,
                                            tick_script,
                                            task_type=task_type,
                                            database=database,
                                            retention_policy=retention_policy,
                                            enable=enable,
                                            dbrps=dbrps)

    return retval, get_mock, define_mock, enable_mock, disable_mock
Esempio n. 4
0
def _present(name='testname',
             tick_script='/tmp/script.tick',
             task_type='stream',
             database='testdb',
             retention_policy='default',
             enable=True,
             task=None,
             define_result=True,
             enable_result=True,
             disable_result=True,
             script='test'):
    '''
    Run a "kapacitor.present" state after setting up mocks, and return the
    state return value as well as the mocks to make assertions.
    '''
    get_mock = Mock(return_value=task)

    if isinstance(define_result, bool):
        define_result = {'success': define_result}
    define_mock = Mock(return_value=define_result)

    if isinstance(enable_result, bool):
        enable_result = {'success': enable_result}
    enable_mock = Mock(return_value=enable_result)

    if isinstance(disable_result, bool):
        disable_result = {'success': disable_result}
    disable_mock = Mock(return_value=disable_result)

    with patch.dict(kapacitor.__salt__, {
        'kapacitor.get_task': get_mock,
        'kapacitor.define_task': define_mock,
        'kapacitor.enable_task': enable_mock,
        'kapacitor.disable_task': disable_mock,
    }):
        with patch('salt.utils.fopen', mock_open(read_data=script)) as open_mock:
            retval = kapacitor.task_present(name, tick_script, task_type=task_type,
                database=database, retention_policy=retention_policy, enable=enable)

    return retval, get_mock, define_mock, enable_mock, disable_mock