1313# limitations under the License.
1414
1515import pytest
16+ from testing_support .fixtures import (
17+ override_generic_settings ,
18+ override_ignore_status_codes ,
19+ validate_transaction_errors ,
20+ validate_transaction_metrics ,
21+ )
22+ from testing_support .validators .validate_code_level_metrics import (
23+ validate_code_level_metrics ,
24+ )
1625
26+ from newrelic .common .object_names import callable_name
27+ from newrelic .core .config import global_settings
1728from newrelic .packages import six
18- from testing_support .fixtures import (validate_transaction_metrics ,
19- validate_transaction_errors , override_ignore_status_codes ,
20- override_generic_settings )
21- from testing_support .validators .validate_code_level_metrics import validate_code_level_metrics
2229
23- from newrelic .core .config import global_settings
24- from newrelic .common .object_names import callable_name
30+ TEST_APPLICATION_PREFIX = "_test_application.create_app.<locals>" if six .PY3 else "_test_application"
2531
2632
2733@pytest .fixture (params = ["flask_restful" , "flask_restplus" , "flask_restx" ])
2834def application (request ):
2935 from _test_application import get_test_application
36+
3037 if request .param == "flask_restful" :
3138 import flask_restful as module
3239 elif request .param == "flask_restplus" :
@@ -44,49 +51,46 @@ def application(request):
4451
4552
4653_test_application_index_scoped_metrics = [
47- ( ' Function/flask.app:Flask.wsgi_app' , 1 ),
48- ( ' Python/WSGI/Application' , 1 ),
49- ( ' Python/WSGI/Response' , 1 ),
50- ( ' Python/WSGI/Finalize' , 1 ),
51- ( ' Function/_test_application:index' , 1 ),
52- ( ' Function/werkzeug.wsgi:ClosingIterator.close' , 1 ),
54+ ( " Function/flask.app:Flask.wsgi_app" , 1 ),
55+ ( " Python/WSGI/Application" , 1 ),
56+ ( " Python/WSGI/Response" , 1 ),
57+ ( " Python/WSGI/Finalize" , 1 ),
58+ ( " Function/_test_application:index" , 1 ),
59+ ( " Function/werkzeug.wsgi:ClosingIterator.close" , 1 ),
5360]
5461
5562
56- @validate_code_level_metrics ("_test_application.create_app.<locals>" if six . PY3 else "_test_application" , "IndexResource " )
63+ @validate_code_level_metrics (TEST_APPLICATION_PREFIX + ".IndexResource" , "get " )
5764@validate_transaction_errors (errors = [])
58- @validate_transaction_metrics ('_test_application:index' ,
59- scoped_metrics = _test_application_index_scoped_metrics )
65+ @validate_transaction_metrics ("_test_application:index" , scoped_metrics = _test_application_index_scoped_metrics )
6066def test_application_index (application ):
61- response = application .get (' /index' )
62- response .mustcontain (' hello' )
67+ response = application .get (" /index" )
68+ response .mustcontain (" hello" )
6369
6470
6571_test_application_raises_scoped_metrics = [
66- ( ' Function/flask.app:Flask.wsgi_app' , 1 ),
67- ( ' Python/WSGI/Application' , 1 ),
68- ( ' Function/_test_application:exception' , 1 ),
72+ ( " Function/flask.app:Flask.wsgi_app" , 1 ),
73+ ( " Python/WSGI/Application" , 1 ),
74+ ( " Function/_test_application:exception" , 1 ),
6975]
7076
7177
7278@pytest .mark .parametrize (
73- 'exception,status_code,ignore_status_code,propagate_exceptions' , [
74- ('werkzeug.exceptions:HTTPException' , 404 , False , False ),
75- ('werkzeug.exceptions:HTTPException' , 404 , True , False ),
76- ('werkzeug.exceptions:HTTPException' , 503 , False , False ),
77- ('_test_application:CustomException' , 500 , False , False ),
78- ('_test_application:CustomException' , 500 , False , True ),
79- ])
80- def test_application_raises (exception , status_code , ignore_status_code ,
81- propagate_exceptions , application ):
82-
83- @validate_code_level_metrics ("_test_application.create_app.<locals>" if six .PY3 else "_test_application" , "ExceptionResource" )
84- @validate_transaction_metrics ('_test_application:exception' ,
85- scoped_metrics = _test_application_raises_scoped_metrics )
79+ "exception,status_code,ignore_status_code,propagate_exceptions" ,
80+ [
81+ ("werkzeug.exceptions:HTTPException" , 404 , False , False ),
82+ ("werkzeug.exceptions:HTTPException" , 404 , True , False ),
83+ ("werkzeug.exceptions:HTTPException" , 503 , False , False ),
84+ ("_test_application:CustomException" , 500 , False , False ),
85+ ("_test_application:CustomException" , 500 , False , True ),
86+ ],
87+ )
88+ def test_application_raises (exception , status_code , ignore_status_code , propagate_exceptions , application ):
89+ @validate_code_level_metrics (TEST_APPLICATION_PREFIX + ".ExceptionResource" , "get" )
90+ @validate_transaction_metrics ("_test_application:exception" , scoped_metrics = _test_application_raises_scoped_metrics )
8691 def _test ():
8792 try :
88- application .get ('/exception/%s/%i' % (exception ,
89- status_code ), status = status_code , expect_errors = True )
93+ application .get ("/exception/%s/%i" % (exception , status_code ), status = status_code , expect_errors = True )
9094 except Exception as e :
9195 assert propagate_exceptions
9296
@@ -108,9 +112,8 @@ def test_application_outside_transaction(application):
108112
109113 _settings = global_settings ()
110114
111- @override_generic_settings (_settings , {' enabled' : False })
115+ @override_generic_settings (_settings , {" enabled" : False })
112116 def _test ():
113- application .get ('/exception/werkzeug.exceptions:HTTPException/404' ,
114- status = 404 )
117+ application .get ("/exception/werkzeug.exceptions:HTTPException/404" , status = 404 )
115118
116119 _test ()
0 commit comments