Skip to content

Commit 4be578f

Browse files
committed
Add basic test case
1 parent 0b6c133 commit 4be578f

File tree

4 files changed

+59
-16
lines changed

4 files changed

+59
-16
lines changed

tests/test_placeholder.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/test_streamfield.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from django.contrib.auth.models import Group, Permission
2+
from django.contrib.contenttypes.models import ContentType
3+
from django.test import TestCase
4+
from testapp.models import MathPage
5+
from wagtail.blocks.stream_block import StreamValue
6+
from wagtail.models import Page
7+
from wagtail.test.utils import WagtailTestUtils
8+
9+
10+
class TestStreamField(WagtailTestUtils, TestCase):
11+
def setUp(self):
12+
self.user = self.login()
13+
14+
# Convert the user into an moderator
15+
self.moderators_group = Group.objects.get(name="Moderators")
16+
for permission in Permission.objects.filter(
17+
content_type=ContentType.objects.get_for_model(MathPage)
18+
):
19+
self.moderators_group.permissions.add(permission)
20+
self.user.is_superuser = False
21+
self.user.groups.add(self.moderators_group)
22+
self.user.save()
23+
24+
# Create test page with a draft revision
25+
self.page = Page.objects.get(id=1).add_child(
26+
instance=MathPage(title="Test", slug="test")
27+
)
28+
29+
self.page.body = StreamValue(
30+
stream_block=self.page.body.stream_block,
31+
stream_data=[
32+
{
33+
"type": "equation",
34+
"value": "$ y = ax + b $",
35+
}
36+
],
37+
is_lazy=True,
38+
)
39+
40+
self.page.save_revision().publish()
41+
42+
def test_streamfield_value(self):
43+
page = MathPage.objects.first()
44+
self.assertTrue(page is not None)
45+
46+
response = self.client.get(f"/admin/pages/{page.id}/edit/")
47+
self.assertEqual(response.status_code, 200)
48+
49+
self.assertRegex(
50+
response.content.decode(),
51+
r""value": "\$ y = ax \+ b \$"",
52+
)

tests/testproject/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,6 @@
151151

152152
WAGTAIL_SITE_NAME = "Wagtail Polymath test site"
153153
WAGTAILADMIN_BASE_URL = "http://localhost:8020"
154+
155+
# Wagtail-polymath settings
156+
WAGTAILPOLYMATH_ENGINE = os.environ.setdefault("WAGTAILPOLYMATH_ENGINE", "mathjax")

tox.ini

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
min_version = 4.11
33

44
envlist =
5-
python{3.8,3.9,3.10,3.11}-django{4.2}-wagtail{5.2,6.1}-{sqlite}
6-
python{3.10,3.11,3.12}-django{5.0}-wagtail{5.2,6.1}-{sqlite}
5+
python{3.8,3.9,3.10,3.11}-django{4.2}-wagtail{5.2,6.1}-{sqlite}-{mathjax,katex}
6+
python{3.10,3.11,3.12}-django{5.0}-wagtail{5.2,6.1}-{sqlite}-{mathjax,katex}
77

88
[gh-actions]
99
python =
@@ -29,6 +29,8 @@ setenv =
2929
# will use the Python 3.12+ sys.monitoring when available
3030
COVERAGE_CORE=sysmon
3131
COVERAGE_FILE = .coverage.{envname}
32+
mathjax: WAGTAILPOLYMATH_ENGINE = mathjax
33+
katex: WAGTAILPOLYMATH_ENGINE = katex
3234

3335
deps =
3436
coverage>=7.0,<8.0

0 commit comments

Comments
 (0)