@@ -270,25 +270,7 @@ def test_user_info_with_custom_user_non_string_username(django_elasticapm_client
270270 assert user_info ["username" ] == "1"
271271
272272
273- @pytest .mark .skipif (django .VERSION > (1 , 9 ), reason = "MIDDLEWARE_CLASSES removed in Django 2.0" )
274273def test_user_info_with_non_django_auth (django_elasticapm_client , client ):
275- with override_settings (
276- INSTALLED_APPS = [app for app in settings .INSTALLED_APPS if app != "django.contrib.auth" ]
277- ) and override_settings (
278- MIDDLEWARE_CLASSES = [
279- m for m in settings .MIDDLEWARE_CLASSES if m != "django.contrib.auth.middleware.AuthenticationMiddleware"
280- ]
281- ):
282- with pytest .raises (Exception ):
283- resp = client .get (reverse ("elasticapm-raise-exc" ))
284-
285- assert len (django_elasticapm_client .events [ERROR ]) == 1
286- event = django_elasticapm_client .events [ERROR ][0 ]
287- assert event ["context" ]["user" ] == {}
288-
289-
290- @pytest .mark .skipif (django .VERSION < (1 , 10 ), reason = "MIDDLEWARE new in Django 1.10" )
291- def test_user_info_with_non_django_auth_django_2 (django_elasticapm_client , client ):
292274 with override_settings (
293275 INSTALLED_APPS = [app for app in settings .INSTALLED_APPS if app != "django.contrib.auth" ]
294276 ) and override_settings (
@@ -303,22 +285,7 @@ def test_user_info_with_non_django_auth_django_2(django_elasticapm_client, clien
303285 assert event ["context" ]["user" ] == {}
304286
305287
306- @pytest .mark .skipif (django .VERSION > (1 , 9 ), reason = "MIDDLEWARE_CLASSES removed in Django 2.0" )
307288def test_user_info_without_auth_middleware (django_elasticapm_client , client ):
308- with override_settings (
309- MIDDLEWARE_CLASSES = [
310- m for m in settings .MIDDLEWARE_CLASSES if m != "django.contrib.auth.middleware.AuthenticationMiddleware"
311- ]
312- ):
313- with pytest .raises (Exception ):
314- client .get (reverse ("elasticapm-raise-exc" ))
315- assert len (django_elasticapm_client .events [ERROR ]) == 1
316- event = django_elasticapm_client .events [ERROR ][0 ]
317- assert event ["context" ]["user" ] == {}
318-
319-
320- @pytest .mark .skipif (django .VERSION < (1 , 10 ), reason = "MIDDLEWARE new in Django 1.10" )
321- def test_user_info_without_auth_middleware_django_2 (django_elasticapm_client , client ):
322289 with override_settings (
323290 MIDDLEWARE_CLASSES = None ,
324291 MIDDLEWARE = [m for m in settings .MIDDLEWARE if m != "django.contrib.auth.middleware.AuthenticationMiddleware" ],
@@ -614,8 +581,7 @@ def read():
614581 assert_any_record_contains (caplog .records , "Can't capture request body: foobar" )
615582
616583
617- @pytest .mark .skipif (django .VERSION < (1 , 9 ), reason = "get-raw-uri-not-available" )
618- def test_disallowed_hosts_error_django_19 (django_elasticapm_client ):
584+ def test_disallowed_hosts_error (django_elasticapm_client ):
619585 request = WSGIRequest (
620586 environ = {
621587 "wsgi.input" : io .BytesIO (),
@@ -634,26 +600,6 @@ def test_disallowed_hosts_error_django_19(django_elasticapm_client):
634600 assert event ["context" ]["request" ]["url" ]["full" ] == "http://testserver/"
635601
636602
637- @pytest .mark .skipif (django .VERSION >= (1 , 9 ), reason = "get-raw-uri-available" )
638- def test_disallowed_hosts_error_django_18 (django_elasticapm_client ):
639- request = WSGIRequest (
640- environ = {
641- "wsgi.input" : io .BytesIO (),
642- "wsgi.url_scheme" : "http" ,
643- "REQUEST_METHOD" : "POST" ,
644- "SERVER_NAME" : "testserver" ,
645- "SERVER_PORT" : "80" ,
646- "CONTENT_TYPE" : "application/json" ,
647- "ACCEPT" : "application/json" ,
648- }
649- )
650- with override_settings (ALLOWED_HOSTS = ["example.com" ]):
651- # this should not raise a DisallowedHost exception
652- django_elasticapm_client .capture ("Message" , message = "foo" , request = request )
653- event = django_elasticapm_client .events [ERROR ][0 ]
654- assert event ["context" ]["request" ]["url" ] == {"full" : "DisallowedHost" }
655-
656-
657603@pytest .mark .parametrize (
658604 "django_elasticapm_client" ,
659605 [{"capture_body" : "errors" }, {"capture_body" : "all" }, {"capture_body" : "off" }],
@@ -1196,16 +1142,6 @@ def test_stacktrace_filtered_for_elasticapm(client, django_elasticapm_client):
11961142 assert spans [1 ]["stacktrace" ][0 ]["module" ].startswith ("django.template" ), spans [1 ]["stacktrace" ][0 ]["function" ]
11971143
11981144
1199- @pytest .mark .skipif (django .VERSION > (1 , 7 ), reason = "argparse raises CommandError in this case" )
1200- @mock .patch ("elasticapm.contrib.django.management.commands.elasticapm.Command._get_argv" )
1201- def test_subcommand_not_set (argv_mock ):
1202- stdout = io .StringIO ()
1203- argv_mock .return_value = ["manage.py" , "elasticapm" ]
1204- call_command ("elasticapm" , stdout = stdout )
1205- output = stdout .getvalue ()
1206- assert "No command specified" in output
1207-
1208-
12091145@mock .patch ("elasticapm.contrib.django.management.commands.elasticapm.Command._get_argv" )
12101146def test_subcommand_not_known (argv_mock ):
12111147 stdout = io .StringIO ()
@@ -1317,8 +1253,8 @@ def test_settings_server_url_with_credentials():
13171253
13181254
13191255@pytest .mark .skipif (
1320- not (( 1 , 10 ) <= django .VERSION < (2 , 0 ) ),
1321- reason = "only needed in 1.10 and 1. 11 when both middleware settings are valid" ,
1256+ django .VERSION >= (2 , 0 ),
1257+ reason = "only needed in 1.11 when both middleware settings are valid" ,
13221258)
13231259def test_django_1_10_uses_deprecated_MIDDLEWARE_CLASSES ():
13241260 stdout = io .StringIO ()
0 commit comments