Skip to content

Commit

Permalink
Test Django class based view (#227)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adamchainz authored Aug 11, 2019
1 parent 5eec350 commit 27456eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tests/integration/django_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)")
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down
15 changes: 14 additions & 1 deletion tests/integration/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] == [
Expand Down Expand Up @@ -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/")
Expand Down

0 comments on commit 27456eb

Please sign in to comment.