def test_application_raises(exception, status_code, ignore_status_code, propagate_exceptions, application): @validate_code_level_metrics("_test_application.create_app.<locals>" if six.PY3 else "_test_application", "ExceptionResource") @validate_transaction_metrics( '_test_application:exception', scoped_metrics=_test_application_raises_scoped_metrics) def _test(): try: application.get('/exception/%s/%i' % (exception, status_code), status=status_code, expect_errors=True) except Exception as e: assert propagate_exceptions # check that the exception is the expected one if callable_name(type(e)) != exception: raise if ignore_status_code: _test = validate_transaction_errors(errors=[])(_test) _test = override_ignore_status_codes([status_code])(_test) else: _test = validate_transaction_errors(errors=[exception])(_test) _test = override_ignore_status_codes([])(_test) _test()
def test_unsupported_method(app, nr_enabled, ignore_status_codes): def _test(): response = app.fetch('/simple', method='TEAPOT', body=b'', allow_nonstandard_methods=True) assert response.code == 405 if nr_enabled: _test = override_ignore_status_codes(ignore_status_codes)(_test) _test = validate_transaction_metrics( '_target_application:SimpleHandler')(_test) if ignore_status_codes: _test = validate_transaction_errors(errors=[])(_test) else: _test = validate_transaction_errors( errors=['tornado.web:HTTPError'])(_test) else: settings = global_settings() _test = override_generic_settings(settings, {'enabled': False})(_test) _test()
def test_errors_in_error_handlers( nr_enabled, app, url, metric_name, metrics, errors): settings = global_settings() @override_generic_settings(settings, {'enabled': nr_enabled}) def _test(): # Because of a bug in Sanic versions <0.8.0, the response.status value # is inconsistent. Rather than assert the status value, we rely on the # transaction errors validator to confirm the application acted as we'd # expect it to. app.fetch('get', url) if nr_enabled: _test = validate_transaction_errors(errors=errors)(_test) _test = validate_transaction_metrics(metric_name, scoped_metrics=metrics, rollup_metrics=metrics)(_test) else: _test = function_not_called('newrelic.core.stats_engine', 'StatsEngine.record_transaction')(_test) _test()