Skip to content

Commit

Permalink
Use real models and register them with the admin
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Jul 30, 2024
1 parent 04a56ce commit 38d8170
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Install the package:
venv/bin/pip install django-prose-editor
To include nh3 as optional dependency for sanitized HTML, install the extra
"sanitize":
"sanitize":

.. code-block:: shell
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ dependencies = [
"django>=4.2",
]

optional-dependencies.tests = [
"coverage",
optional-dependencies.sanitize = [
"nh3",
]
optional-dependencies.sanitize = [
optional-dependencies.tests = [
"coverage",
"nh3",
]
urls.Homepage = "https://github.com/matthiask/django-prose-editor/"
Expand Down
7 changes: 7 additions & 0 deletions tests/testapp/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin

from testapp import models


admin.register(models.ProseEditorModel)
admin.register(models.SanitizedProseEditorModel)
18 changes: 18 additions & 0 deletions tests/testapp/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.db import models

from django_prose_editor.fields import ProseEditorField
from django_prose_editor.sanitized import SanitizedProseEditorField


class ProseEditorModel(models.Model):
description = ProseEditorField()

def __str__(self):
return self.description


class SanitizedProseEditorModel(models.Model):
description = SanitizedProseEditorField()

def __str__(self):
return self.description
1 change: 1 addition & 0 deletions tests/testapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

INSTALLED_APPS = [
"django.contrib.auth",
Expand Down
32 changes: 10 additions & 22 deletions tests/testapp/test_prose_editor.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,40 @@
from django import test
from django.db import models
from django.test.utils import isolate_apps

from django_prose_editor.fields import ProseEditorField
from django_prose_editor.sanitized import SanitizedProseEditorField
from testapp.models import ProseEditorModel, SanitizedProseEditorModel


class Test(test.TestCase):
@isolate_apps()
def test_standard_field(self):
class Model(models.Model):
description = ProseEditorField()

def __str__(self):
return self.description

m = Model(description="<p></p>")
m = ProseEditorModel(description="<p></p>")
m.full_clean()
self.assertEqual(m.description, "")

m = Model(description="<h1></h1>")
m = ProseEditorModel(description="<h1></h1>")
m.full_clean()
self.assertEqual(m.description, "")

m = Model(description="<p>hello</p>")
m = ProseEditorModel(description="<p>hello</p>")
m.full_clean()
self.assertEqual(m.description, "<p>hello</p>")

@isolate_apps()
def test_sanitized_field(self):
class Model(models.Model):
description = SanitizedProseEditorField()

def __str__(self):
return self.description

m = Model(description="<style>h1{color:red}</style><h1>Hello</h1>")
m = SanitizedProseEditorModel(
description="<style>h1{color:red}</style><h1>Hello</h1>"
)
m.full_clean()
self.assertEqual(m.description, "<h1>Hello</h1>")

m = Model(description="<p></p>")
m = SanitizedProseEditorModel(description="<p></p>")
m.full_clean()
self.assertEqual(m.description, "")

m = Model(description="<h1></h1>")
m = SanitizedProseEditorModel(description="<h1></h1>")
m.full_clean()
self.assertEqual(m.description, "")

m = Model(description="<p>hello</p>")
m = SanitizedProseEditorModel(description="<p>hello</p>")
m.full_clean()
self.assertEqual(m.description, "<p>hello</p>")
8 changes: 7 additions & 1 deletion tests/testapp/urls.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
urlpatterns = []
from django.contrib import admin
from django.urls import path


urlpatterns = [
path("admin/", admin.site.urls),
]

0 comments on commit 38d8170

Please sign in to comment.