Skip to content

Commit 58ac6f0

Browse files
committed
Fixup
1 parent ac46477 commit 58ac6f0

6 files changed

Lines changed: 47 additions & 66 deletions

File tree

newrelic/hooks/framework_wagtail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _nr_wrapper_route_for_request(wrapped, instance, args, kwargs):
2626
if route_result:
2727
page, args, kwargs = route_result
2828
name = callable_name(page.route)
29-
trans.set_transaction_name(name, priority=6)
29+
transaction.set_transaction_name(name, priority=6)
3030

3131
return route_result
3232

tests/framework_wagtail/migrations/0001_initial.py

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,13 @@
11
from django.db import migrations, models
22
import wagtail.fields
3-
from wagtail.models import Page
43
import django.db.models.deletion
54
import wagtail.contrib.routable_page.models
65

76

8-
def create_homepage(apps, schema_editor):
9-
# Get models
10-
ContentType = apps.get_model("contenttypes.ContentType")
11-
Page = apps.get_model("wagtailcore.Page")
12-
Site = apps.get_model("wagtailcore.Site")
13-
HomePage = apps.get_model("dummy_app.HomePage")
14-
15-
# Delete the default homepage
16-
# If migration is run multiple times, it may have already been deleted
17-
Page.objects.filter(id=2).delete()
18-
19-
# Create content type for homepage model
20-
homepage_content_type, __ = ContentType.objects.get_or_create(
21-
model="homepage", app_label="dummy_app"
22-
)
23-
24-
# Create a new homepage
25-
homepage = HomePage.objects.create(
26-
title="Home",
27-
draft_title="Home",
28-
slug="home",
29-
content_type=homepage_content_type,
30-
path="00010001",
31-
depth=2,
32-
numchild=0,
33-
url_path="/home/",
34-
)
35-
36-
# Create a site with the new homepage set as the root
37-
Site.objects.create(hostname="localhost", root_page=homepage, is_default_site=True)
38-
39-
def remove_homepage(apps, schema_editor):
40-
# Get models
41-
ContentType = apps.get_model("contenttypes.ContentType")
42-
HomePage = apps.get_model("dummy_app.HomePage")
43-
44-
# Delete the default homepage
45-
# Page and Site objects CASCADE
46-
HomePage.objects.filter(slug="home", depth=2).delete()
47-
48-
# Delete content type for homepage model
49-
ContentType.objects.filter(model="homepage", app_label="dummy_app").delete()
50-
51-
527
class Migration(migrations.Migration):
538

549
dependencies = [
55-
("wagtailcore", "0040_page_draft_title"),
10+
("wagtailcore", "0070_rename_pagerevision_revision"),
5611
]
5712

5813
operations = [
@@ -76,7 +31,6 @@ class Migration(migrations.Migration):
7631
},
7732
bases=("wagtailcore.page",),
7833
),
79-
migrations.RunPython(create_homepage, remove_homepage),
8034
migrations.AddField(
8135
model_name='homepage',
8236
name='body',

tests/framework_wagtail/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"wagtail.search",
5454
"wagtail.admin",
5555
"wagtail",
56+
"taggit",
5657
"django_filters",
5758
"django.contrib.admin",
5859
"django.contrib.auth",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<body>
4+
<h1>{{ page.title }}</h1>
5+
{{ page.body|safe }}
6+
</body>
7+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<body>
4+
<h1>{{ page.title }}</h1>
5+
{{ page.body|safe }}
6+
</body>
7+
</html>

tests/framework_wagtail/test_application.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@
1818

1919
from testing_support.fixtures import (
2020
collector_agent_registration_fixture,
21-
collector_available_fixture,
22-
override_application_settings,
23-
override_generic_settings,
24-
override_ignore_status_codes,
21+
collector_available_fixture, # noqa: F401 # autouse fixture, must be importable in this module
2522
)
26-
from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics
27-
from testing_support.validators.validate_transaction_errors import validate_transaction_errors
2823
from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics
2924

3025

@@ -39,11 +34,11 @@
3934
}
4035

4136
collector_agent_registration = collector_agent_registration_fixture(
42-
app_name="Python Agent Test (framework_django)", default_settings=_default_settings, scope="module"
37+
app_name="Python Agent Test (framework_wagtail)", default_settings=_default_settings, scope="module"
4338
)
4439

45-
@pytest.fixture
46-
def database(autouse=True):
40+
@pytest.fixture(autouse=True)
41+
def database():
4742
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
4843
import django
4944

@@ -52,52 +47,69 @@ def database(autouse=True):
5247

5348
call_command("migrate", verbosity=0, interactive=False, run_syncdb=True)
5449

50+
# Wagtail's own migrations seed a default "Welcome" home page (a plain
51+
# ``Page``) and a default ``Site``. Replace that root with a ``HomePage``
52+
# and hang a ``RoutablePage`` beneath it so that "/" and "/routable/"
53+
# resolve to real, renderable pages served by the dummy_app page types.
54+
from wagtail.models import Page, Site
55+
56+
from dummy_app.models import HomePage, RoutablePage
57+
58+
if not HomePage.objects.exists():
59+
site = Site.objects.get(is_default_site=True)
60+
default_home = site.root_page
61+
home = Page.objects.get(depth=1).add_child(instance=HomePage(title="Home", slug="home-page"))
62+
site.root_page = home
63+
site.save()
64+
default_home.delete()
65+
home.add_child(instance=RoutablePage(title="Routable", slug="routable"))
66+
5567
def target_application():
5668
from _target_application import _target_application
5769

5870
return _target_application
5971

6072

6173
@validate_transaction_metrics(
62-
"views:index",
74+
"dummy_app.models:HomePage.route",
6375
scoped_metrics=[
6476
("Function/django.core.handlers.wsgi:WSGIHandler.__call__", 1),
6577
("Python/WSGI/Application", 1),
6678
("Python/WSGI/Response", 1),
6779
("Python/WSGI/Finalize", 1),
68-
("Function/views:index", 1),
80+
("Function/wagtail.views:serve", 1),
6981
]
7082
)
7183
def test_home():
7284
test_application = target_application()
73-
response = test_application.get("")
85+
response = test_application.get("/")
7486

7587

7688
@validate_transaction_metrics(
77-
"views:index",
89+
"dummy_app.models:RoutablePage.index_route",
7890
scoped_metrics=[
7991
("Function/django.core.handlers.wsgi:WSGIHandler.__call__", 1),
8092
("Python/WSGI/Application", 1),
8193
("Python/WSGI/Response", 1),
8294
("Python/WSGI/Finalize", 1),
83-
("Function/views:index", 1),
95+
("Function/wagtail.views:serve", 1),
8496
]
8597
)
8698
def test_routable():
8799
test_application = target_application()
88-
response = test_application.get("/routable")
100+
response = test_application.get("/routable/")
89101

90102

91103
@validate_transaction_metrics(
92-
"views:index",
104+
"dummy_app.models:RoutablePage.index",
93105
scoped_metrics=[
94106
("Function/django.core.handlers.wsgi:WSGIHandler.__call__", 1),
95107
("Python/WSGI/Application", 1),
96108
("Python/WSGI/Response", 1),
97109
("Python/WSGI/Finalize", 1),
98-
("Function/views:index", 1),
110+
("Function/wagtail.views:serve", 1),
99111
]
100112
)
101113
def test_routable_routable():
102114
test_application = target_application()
103-
response = test_application.get("/routable/routable")
115+
response = test_application.get("/routable/routable/")

0 commit comments

Comments
 (0)