From 520b0cd635bd7a56ba43db188e7285ae18f1dc9b Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 4 Aug 2019 11:32:37 +0100 Subject: [PATCH] Test Django class based view Following #226, test the trace names for Django class-based views. Although they are good as-is and aren't changing, I wanted to add tests to check that future changes such as #102 don't make them worse. --- tests/integration/django_app.py | 8 ++++++++ tests/integration/test_django.py | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/integration/django_app.py b/tests/integration/django_app.py index 662c09e4..941c86c2 100644 --- a/tests/integration/django_app.py +++ b/tests/integration/django_app.py @@ -64,6 +64,7 @@ from django.http import HttpResponse from django.template import engines from django.utils.functional import SimpleLazyObject + from django.views.generic import View def home(request): @@ -78,6 +79,11 @@ def crash(request): raise ValueError("BØØM!") # non-ASCII +class CbvView(View): + def get(self, request): + return HttpResponse("Hello getter") + + def sql(request): with connection.cursor() as cursor: cursor.execute("CREATE TABLE IF NOT EXISTS test(item)") @@ -110,6 +116,7 @@ def urlpatterns(): path("", home), path("hello/", hello), path("crash/", crash), + path("cbv/", CbvView.as_view()), path("sql/", sql), path("template/", template), path("admin/", admin.site.urls), @@ -121,6 +128,7 @@ def urlpatterns(): url(r"^$", home), url(r"^hello/$", hello), url(r"^crash/$", crash), + url(r"^cbv/$", CbvView.as_view()), url(r"^sql/$", sql), url(r"^template/$", template), url(r"^admin/", admin.site.urls), diff --git a/tests/integration/test_django.py b/tests/integration/test_django.py index da525913..1074a4d0 100644 --- a/tests/integration/test_django.py +++ b/tests/integration/test_django.py @@ -122,8 +122,8 @@ def test_user_ip(headers, extra_environ, expected, tracked_requests): def test_hello(tracked_requests): with app_with_scout() as app: response = TestApp(app).get("/hello/") - assert response.status_int == 200 + assert response.status_int == 200 assert len(tracked_requests) == 1 spans = tracked_requests[0].complete_spans assert [s.operation for s in spans] == [ @@ -167,6 +167,19 @@ def test_server_error(tracked_requests): assert operations == expected_operations +def test_cbv(tracked_requests): + with app_with_scout() as app: + response = TestApp(app).get("/cbv/") + + assert response.status_int == 200 + assert len(tracked_requests) == 1 + spans = tracked_requests[0].complete_spans + assert [s.operation for s in spans] == [ + "Controller/tests.integration.django_app.CbvView", + "Middleware", + ] + + def test_sql(tracked_requests): with app_with_scout() as app: response = TestApp(app).get("/sql/")