Ejemplo n.º 1
0
def test_no_exc():
    '''Tests that a command which does not raise an exception does not
    report an exception.

    '''

    args = [util.which('dcos')]
    env = _env_reporting()
    version = 'release'

    with patch('sys.argv', args), \
            patch.dict(os.environ, env), \
            patch('dcoscli.version', version):
        assert main() == 0

        # segment.io
        data = {'userId': USER_ID,
                'event': SEGMENT_IO_CLI_EVENT,
                'properties': _base_properties()}
        assert mock_called_some_args(http.post,
                                     '{}/track'.format(SEGMENT_URL),
                                     json=data,
                                     timeout=(1, 1))

        # rollbar
        assert rollbar.report_message.call_count == 0
Ejemplo n.º 2
0
def test_exc():
    '''Tests that a command which does raise an exception does report an
    exception.

    '''

    args = [util.which('dcos')]
    env = _env_reporting()
    version = 'release'
    with patch('sys.argv', args), \
            patch('dcoscli.version', version), \
            patch.dict(os.environ, env), \
            patch('dcoscli.analytics.wait_and_capture',
                  return_value=(1, 'Traceback')):
        assert main() == 1

        # segment.io
        props = _base_properties()
        props['err'] = 'Traceback'
        props['exit_code'] = 1
        data = {'userId': USER_ID,
                'event': SEGMENT_IO_CLI_ERROR_EVENT,
                'properties': props}

        assert mock_called_some_args(http.post,
                                     '{}/track'.format(SEGMENT_URL),
                                     json=data,
                                     timeout=(1, 1))

        # rollbar
        props = _base_properties()
        props['exit_code'] = 1
        props['stderr'] = 'Traceback'
        rollbar.report_message.assert_called_with('Traceback', 'error',
                                                  extra_data=props)
Ejemplo n.º 3
0
def test_exc():
    '''Tests that a command which does raise an exception does report an
    exception.

    '''

    args = [util.which('dcos')]
    env = _env_reporting()

    with patch('sys.argv', args), \
            patch.dict(os.environ, env), \
            patch('dcoscli.analytics._wait_and_capture',
                  return_value=(1, 'Traceback')):
        assert main() == 1

        # segment.io
        props = _base_properties()
        props['err'] = 'Traceback'
        props['exit_code'] = 1
        data = {'userId': USER_ID,
                'event': SEGMENT_IO_CLI_ERROR_EVENT,
                'properties': props}

        assert mock_called_some_args(requests.post,
                                     '{}/track'.format(SEGMENT_URL),
                                     json=data,
                                     timeout=1)

        # rollbar
        props = _base_properties()
        props['exit_code'] = 1
        props['stderr'] = 'Traceback'
        rollbar.report_message.assert_called_with('Traceback', 'error',
                                                  extra_data=props)
Ejemplo n.º 4
0
def test_no_exc():
    '''Tests that a command which does not raise an exception does not
    report an exception.

    '''

    args = [util.which('dcos')]
    env = _env_reporting()
    version = 'release'

    with patch('sys.argv', args), \
            patch.dict(os.environ, env), \
            patch('dcoscli.version', version):
        assert main() == 0

        # segment.io
        data = {
            'userId': USER_ID,
            'event': SEGMENT_IO_CLI_EVENT,
            'properties': _base_properties()
        }
        assert mock_called_some_args(http.post,
                                     '{}/track'.format(SEGMENT_URL),
                                     json=data,
                                     timeout=(1, 1))

        # rollbar
        assert rollbar.report_message.call_count == 0
Ejemplo n.º 5
0
def _mock_dcos_run(args, authenticated=True):
    if authenticated:
        env = _config_with_credentials()
    else:
        env = _config_without_credentials()

    with patch('sys.argv', args), patch.dict(os.environ, env):
        return main()
Ejemplo n.º 6
0
def _mock_dcos_run(args, authenticated=True):
    if authenticated:
        env = _config_with_credentials()
    else:
        env = _config_without_credentials()

    with patch('sys.argv', args), patch.dict(os.environ, env):
        return main()
Ejemplo n.º 7
0
def test_cluster_id_not_sent_on_config_call():
    """Tests that cluster_id is not sent to segment.io on call to config
    subcommand
    """

    args = ['dcos', 'config', 'show']

    with patch('sys.argv', args), \
            patch('dcos.mesos.DCOSClient.metadata') as get_cluster_id:
        assert main() == 0

        assert get_cluster_id.call_count == 0
Ejemplo n.º 8
0
def test_cluster_id_not_sent_on_config_call():
    """Tests that cluster_id is not sent to segment.io on call to config
    subcommand
    """

    args = ['dcos', 'config', 'show']

    with patch('sys.argv', args), \
            patch('dcos.mesos.DCOSClient.metadata') as get_cluster_id:
        assert main() == 0

        assert get_cluster_id.call_count == 0
Ejemplo n.º 9
0
def test_cluster_id_not_sent():
    '''Tests that cluster_id is sent to segment.io'''

    args = [util.which('dcos'), 'config', 'show']
    env = _env_reporting_with_url()
    version = 'release'

    with patch('sys.argv', args), \
            patch.dict(os.environ, env), \
            patch('dcoscli.version', version), \
            patch('dcos.mesos.DCOSClient.metadata') as get_cluster_id:
        assert main() == 0

        assert get_cluster_id.call_count == 0
Ejemplo n.º 10
0
def test_config_reporting_false():
    '''Test that "core.reporting = false" blocks exception reporting.'''

    args = [util.which('dcos')]
    env = _env_no_reporting()

    with patch('sys.argv', args), \
            patch.dict(os.environ, env), \
            patch('dcoscli.analytics._wait_and_capture',
                  return_value=(1, 'Traceback')):

        assert main() == 1

        assert rollbar.report_message.call_count == 0
        assert requests.post.call_count == 0
Ejemplo n.º 11
0
def test_no_exc():
    '''Tests that a command which does not raise an exception does not
    report an exception.

    '''

    args = ['dcos']
    env = _env_reporting()
    version = 'release'

    with patch('sys.argv', args), \
            patch.dict(os.environ, env), \
            patch('dcoscli.version', version):
        assert main() == 0

        assert rollbar.report_message.call_count == 0
Ejemplo n.º 12
0
def test_config_reporting_false():
    '''Test that "core.reporting = false" blocks exception reporting.'''

    args = ['dcos']
    env = _env_no_reporting()
    version = 'release'

    with patch('sys.argv', args), \
            patch('dcoscli.version', version), \
            patch.dict(os.environ, env), \
            patch('dcoscli.subcommand.SubcommandMain.run_and_capture',
                  return_value=(1, "Traceback")), \
            patch('dcoscli.analytics._segment_track') as track:

        assert main() == 1
        assert track.call_count == 0
Ejemplo n.º 13
0
def test_config_reporting_false():
    '''Test that "core.reporting = false" blocks exception reporting.'''

    args = ['dcos']
    env = _env_no_reporting()
    version = 'release'

    with patch('sys.argv', args), \
            patch('dcoscli.version', version), \
            patch.dict(os.environ, env), \
            patch('dcoscli.subcommand.SubcommandMain.run_and_capture',
                  return_value=(1, "Traceback")), \
            patch('dcoscli.analytics._segment_track') as track:

        assert main() == 1
        assert track.call_count == 0
Ejemplo n.º 14
0
def test_no_exc():
    '''Tests that a command which does not raise an exception does not
    report an exception.

    '''

    args = ['dcos']
    env = _env_reporting()
    version = 'release'

    with patch('sys.argv', args), \
            patch.dict(os.environ, env), \
            patch('dcoscli.version', version):
        assert main() == 0

        assert rollbar.report_message.call_count == 0
Ejemplo n.º 15
0
def test_production_setting_false():
    '''Test that env var DCOS_PRODUCTION=false sends exceptions to
    the 'dev' environment.

    '''

    args = [util.which('dcos')]
    env = _env_reporting()
    env['DCOS_PRODUCTION'] = 'false'

    with patch('sys.argv', args), patch.dict(os.environ, env):
        assert main() == 0

        _, kwargs = requests.post.call_args_list[0]
        assert kwargs['auth'].username == SEGMENT_IO_WRITE_KEY_DEV

        rollbar.init.assert_called_with(ROLLBAR_SERVER_POST_KEY, 'dev')
Ejemplo n.º 16
0
def test_config_reporting_false():
    '''Test that "core.reporting = false" blocks exception reporting.'''

    args = [util.which('dcos')]
    env = _env_no_reporting()
    version = 'release'

    with patch('sys.argv', args), \
            patch('dcoscli.version', version), \
            patch.dict(os.environ, env), \
            patch('dcoscli.analytics.wait_and_capture',
                  return_value=(1, 'Traceback')):

        assert main() == 1

        assert rollbar.report_message.call_count == 0
        assert http.post.call_count == 0
Ejemplo n.º 17
0
def test_exc():
    '''Tests that a command which does raise an exception does report an
    exception.

    '''

    args = ['dcos']
    env = _env_reporting()
    version = 'release'
    with patch('sys.argv', args), \
            patch('dcoscli.version', version), \
            patch.dict(os.environ, env), \
            patch('dcoscli.subcommand.SubcommandMain.run_and_capture',
                  return_value=(1, "Traceback")), \
            patch('dcoscli.analytics._segment_track') as track:

        assert main() == 1
        assert track.call_count == 2
        assert rollbar.report_message.call_count == 1
Ejemplo n.º 18
0
def test_exc():
    '''Tests that a command which does raise an exception does report an
    exception.

    '''

    args = ['dcos']
    env = _env_reporting()
    version = 'release'
    with patch('sys.argv', args), \
            patch('dcoscli.version', version), \
            patch.dict(os.environ, env), \
            patch('dcoscli.subcommand.SubcommandMain.run_and_capture',
                  return_value=(1, "Traceback")), \
            patch('dcoscli.analytics._segment_track') as track:

        assert main() == 1
        assert track.call_count == 2
        assert rollbar.report_message.call_count == 1
Ejemplo n.º 19
0
def test_cluster_id_sent():
    '''Tests that cluster_id is sent to segment.io'''

    args = [util.which('dcos')]
    env = _env_reporting_with_url()
    version = 'release'

    with patch('sys.argv', args), \
            patch.dict(os.environ, env), \
            patch('dcoscli.version', version):
        assert main() == 0

        props = _base_properties()
        # segment.io
        data = {'userId': USER_ID,
                'event': SEGMENT_IO_CLI_EVENT,
                'properties': props}
        assert props.get('CLUSTER_ID')
        assert mock_called_some_args(http.post,
                                     '{}/track'.format(SEGMENT_URL),
                                     json=data,
                                     timeout=(1, 1))
Ejemplo n.º 20
0
def test_cluster_id_sent():
    '''Tests that cluster_id is sent to segment.io'''

    args = [util.which('dcos')]
    env = _env_reporting_with_url()
    version = 'release'

    with patch('sys.argv', args), \
            patch.dict(os.environ, env), \
            patch('dcoscli.version', version):
        assert main() == 0

        props = _base_properties()
        # segment.io
        data = {
            'userId': USER_ID,
            'event': SEGMENT_IO_CLI_EVENT,
            'properties': props
        }
        assert props.get('CLUSTER_ID')
        assert mock_called_some_args(http.post,
                                     '{}/track'.format(SEGMENT_URL),
                                     json=data,
                                     timeout=(1, 1))