コード例 #1
0
ファイル: test_config.py プロジェクト: vemel/iopipe-python
def test_set_config__iopipe_token(monkeypatch):
    monkeypatch.setattr(os, "getenv", partial(mock_getenv, "IOPIPE_TOKEN", "foobar"))
    config = set_config()
    assert config["token"] == "foobar"

    monkeypatch.setattr(os, "getenv", partial(mock_getenv, "IOPIPE_CLIENTID", "barbaz"))
    config = set_config()
    assert config["token"] == "barbaz"
コード例 #2
0
ファイル: test_config.py プロジェクト: pselle/iopipe-python
def test_set_config__iopipe_token(monkeypatch):
    monkeypatch.setattr(os, 'getenv',
                        partial(mock_getenv, 'IOPIPE_TOKEN', 'foobar'))
    config = set_config()
    assert config['token'] == 'foobar'

    monkeypatch.setattr(os, 'getenv',
                        partial(mock_getenv, 'IOPIPE_CLIENTID', 'barbaz'))
    config = set_config()
    assert config['token'] == 'barbaz'
コード例 #3
0
ファイル: test_config.py プロジェクト: pselle/iopipe-python
def test_set_config__iopipe_timeout_window(monkeypatch):
    monkeypatch.setattr(os, 'getenv',
                        partial(mock_getenv, 'IOPIPE_TIMEOUT_WINDOW', '5000'))
    config = set_config()
    assert config['timeout_window'] == 5.0

    monkeypatch.setattr(
        os, 'getenv',
        partial(mock_getenv, 'IOPIPE_TIMEOUT_WINDOW', 'not a number'))
    config = set_config()
    assert config['timeout_window'] == 0.5
コード例 #4
0
ファイル: test_config.py プロジェクト: pselle/iopipe-python
def test_set_config__iopipe_network_timeout(monkeypatch):
    monkeypatch.setattr(
        os, 'getenv', partial(mock_getenv, 'IOPIPE_NETWORK_TIMEOUT', '60000'))
    config = set_config()
    assert config['network_timeout'] == 60.0

    monkeypatch.setattr(
        os, 'getenv',
        partial(mock_getenv, 'IOPIPE_NETWORK_TIMEOUT', 'not a number'))
    config = set_config()
    assert config['network_timeout'] == 5
コード例 #5
0
ファイル: test_config.py プロジェクト: vemel/iopipe-python
def test_set_config__iopipe_network_timeout(monkeypatch):
    monkeypatch.setattr(
        os, "getenv", partial(mock_getenv, "IOPIPE_NETWORK_TIMEOUT", "60000")
    )
    config = set_config()
    assert config["network_timeout"] == 60.0

    monkeypatch.setattr(
        os, "getenv", partial(mock_getenv, "IOPIPE_NETWORK_TIMEOUT", "not a number")
    )
    config = set_config()
    assert config["network_timeout"] == 5
コード例 #6
0
ファイル: test_config.py プロジェクト: vemel/iopipe-python
def test_set_config__iopipe_timeout_window(monkeypatch):
    monkeypatch.setattr(
        os, "getenv", partial(mock_getenv, "IOPIPE_TIMEOUT_WINDOW", "5000")
    )
    config = set_config()
    assert config["timeout_window"] == 5.0

    monkeypatch.setattr(
        os, "getenv", partial(mock_getenv, "IOPIPE_TIMEOUT_WINDOW", "not a number")
    )
    config = set_config()
    assert config["timeout_window"] == 0.15
コード例 #7
0
def test_send_report_network_timeout(mock_session):
    """Assert that the timeout is changed when network_timeout is set"""
    send_report({'foo': 'bar'}, set_config(network_timeout=60000))

    mock_session.post.assert_called_once_with(
        'https://metrics-api.iopipe.com/v0/event',
        json={'foo': 'bar'},
        timeout=60)
コード例 #8
0
def test_send_report(mock_session):
    """Assert that a POST request is made when a report is sent"""
    send_report({'foo': 'bar'}, set_config())

    mock_session.post.assert_called_once_with(
        'https://metrics-api.iopipe.com/v0/event',
        json={'foo': 'bar'},
        timeout=5)
コード例 #9
0
def test_set_config__iopipe_enabled__title_case_true(monkeypatch):
    def mock_getenv(key, default=None):
        if key == 'IOPIPE_ENABLED':
            return 'True'
        return os.environ.get(key, default)

    monkeypatch.setattr(os, 'getenv', mock_getenv)
    config = set_config()
    assert config['enabled'] is True
コード例 #10
0
def test_report_samlocal(monkeypatch, mock_context):
    """Assert that if invoked by sam local that the function name is overridden"""
    monkeypatch.setattr(os, 'environ', {'AWS_SAM_LOCAL': True})

    report = Report(set_config(), mock_context)
    report.prepare()

    assert report.report['aws'][
        'invokedFunctionArn'] == 'arn:aws:lambda:local:0:function:handler'
コード例 #11
0
def test_set_config__iopipe_enabled__small_caps_false(monkeypatch):
    def mock_getenv(key, default=None):
        if key == 'IOPIPE_ENABLED':
            return 'false'
        return os.environ.get(key, default)

    monkeypatch.setattr(os, 'getenv', mock_getenv)
    config = set_config()
    assert config['enabled'] is False
コード例 #12
0
def test_send_report(mock_session):
    """Assert that a POST request is made when a report is sent"""
    send_report({"foo": "bar"}, set_config())

    mock_session.post.assert_called_once_with(
        "https://metrics-api.iopipe.com/v0/event",
        json={"foo": "bar"},
        headers=mock.ANY,
        timeout=5.0,
    )
コード例 #13
0
def test_send_report_network_timeout(mock_session):
    """Assert that the timeout is changed when network_timeout is set"""
    send_report({"foo": "bar"}, set_config(network_timeout=60000))

    mock_session.post.assert_called_once_with(
        "https://metrics-api.iopipe.com/v0/event",
        json={"foo": "bar"},
        headers=mock.ANY,
        timeout=60,
    )
コード例 #14
0
def test_report_linux_system_success(mock_context, assert_valid_schema):
    """Asserts that fields collected by the system module are present in a success report"""
    report = Report(set_config(), mock_context)
    report.prepare()

    assert_valid_schema(report.report,
                        optional_fields=[
                            'environment.runtime.vendor',
                            'environment.runtime.vmVendor',
                            'environment.runtime.vmVersion',
                            'environment.nodejs',
                            'errors.count',
                            'errors.message',
                            'errors.name',
                            'errors.stack',
                            'errors.stackHash',
                            'labels',
                            'memory',
                            'projectId',
                            'performanceEntries',
                        ])
コード例 #15
0
def test_report_linux_system_error(mock_context, assert_valid_schema):
    """Asserts that fields collected by the system module are present in a error report"""
    report = Report(set_config(), mock_context)

    try:
        raise Exception('Uh oh, this happened')
    except Exception as e:
        report.prepare(e)

    assert_valid_schema(report.report,
                        optional_fields=[
                            'environment.runtime.vendor',
                            'environment.runtime.vmVendor',
                            'environment.runtime.vmVersion',
                            'environment.nodejs',
                            'errors.count',
                            'errors.stackHash',
                            'labels',
                            'memory',
                            'projectId',
                            'performanceEntries',
                        ])
コード例 #16
0
ファイル: test_config.py プロジェクト: vemel/iopipe-python
def test_set_config__iopipe_install_method(monkeypatch):
    monkeypatch.setattr(
        os, "getenv", partial(mock_getenv, "IOPIPE_INSTALL_METHOD", "auto")
    )
    config = set_config()
    assert config["install_method"] == "auto"
コード例 #17
0
ファイル: test_config.py プロジェクト: vemel/iopipe-python
def test_set_config__iopipe_enabled__title_case_true(monkeypatch):
    monkeypatch.setattr(os, "getenv", partial(mock_getenv, "IOPIPE_ENABLED", "True"))
    config = set_config()
    assert config["enabled"] is True
コード例 #18
0
ファイル: test_config.py プロジェクト: vemel/iopipe-python
def test_set_config__iopipe_enabled__small_caps_false(monkeypatch):
    monkeypatch.setattr(os, "getenv", partial(mock_getenv, "IOPIPE_ENABLED", "false"))
    config = set_config()
    assert config["enabled"] is False
コード例 #19
0
ファイル: test_config.py プロジェクト: vemel/iopipe-python
def test_set_config__iopipe_debug__small_caps_false(monkeypatch):
    monkeypatch.setattr(os, "getenv", partial(mock_getenv, "IOPIPE_DEBUG", "false"))
    config = set_config()
    assert config["debug"] is False
コード例 #20
0
ファイル: test_config.py プロジェクト: vemel/iopipe-python
def test_set_config__iopipe_enabled__default():
    config = set_config()
    assert config["enabled"] is True
コード例 #21
0
ファイル: test_config.py プロジェクト: vemel/iopipe-python
def test_set_config__iopipe_debug__default():
    config = set_config()
    assert config["debug"] is False
コード例 #22
0
ファイル: test_config.py プロジェクト: vemel/iopipe-python
def test_set_config__iopipe_debug__title_case_true(monkeypatch):
    monkeypatch.setattr(os, "getenv", partial(mock_getenv, "IOPIPE_DEBUG", "True"))
    config = set_config()
    assert config["debug"] is True
コード例 #23
0
ファイル: test_config.py プロジェクト: pselle/iopipe-python
def test_set_config__iopipe_enabled__small_caps_false(monkeypatch):
    monkeypatch.setattr(os, 'getenv',
                        partial(mock_getenv, 'IOPIPE_ENABLED', 'false'))
    config = set_config()
    assert config['enabled'] is False
コード例 #24
0
def test_set_config__iopipe_enabled__title_case_false():
    os.environ['IOPIPE_ENABLED'] = 'False'

    config = set_config()
    assert config['enabled'] is False
コード例 #25
0
ファイル: test_config.py プロジェクト: pselle/iopipe-python
def test_set_config__iopipe_install_method(monkeypatch):
    monkeypatch.setattr(os, 'getenv',
                        partial(mock_getenv, 'IOPIPE_INSTALL_METHOD', 'auto'))
    config = set_config()
    assert config['install_method'] == 'auto'
コード例 #26
0
ファイル: test_config.py プロジェクト: pselle/iopipe-python
def test_set_config__iopipe_debug__small_caps_false(monkeypatch):
    monkeypatch.setattr(os, 'getenv',
                        partial(mock_getenv, 'IOPIPE_DEBUG', 'false'))
    config = set_config()
    assert config['debug'] is False
コード例 #27
0
ファイル: test_config.py プロジェクト: pselle/iopipe-python
def test_set_config__iopipe_debug__title_case_true(monkeypatch):
    monkeypatch.setattr(os, 'getenv',
                        partial(mock_getenv, 'IOPIPE_DEBUG', 'True'))
    config = set_config()
    assert config['debug'] is True
コード例 #28
0
def test_set_config__iopipe_enabled__small_caps_false():
    os.environ['IOPIPE_ENABLED'] = 'false'

    config = set_config()
    assert config['enabled'] is False
コード例 #29
0
ファイル: test_config.py プロジェクト: pselle/iopipe-python
def test_set_config__iopipe_enabled__title_case_true(monkeypatch):
    monkeypatch.setattr(os, 'getenv',
                        partial(mock_getenv, 'IOPIPE_ENABLED', 'True'))
    config = set_config()
    assert config['enabled'] is True