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"
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'
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
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
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
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
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)
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)
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
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'
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
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, )
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, )
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', ])
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', ])
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"
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
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
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
def test_set_config__iopipe_enabled__default(): config = set_config() assert config["enabled"] is True
def test_set_config__iopipe_debug__default(): config = set_config() assert config["debug"] is False
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
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
def test_set_config__iopipe_enabled__title_case_false(): os.environ['IOPIPE_ENABLED'] = 'False' config = set_config() assert config['enabled'] is False
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'
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
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
def test_set_config__iopipe_enabled__small_caps_false(): os.environ['IOPIPE_ENABLED'] = 'false' config = set_config() assert config['enabled'] is False
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