From a7752673c2fda3f81e809db68dd4f24b06aa8299 Mon Sep 17 00:00:00 2001 From: Jaap Roes Date: Thu, 7 Mar 2024 09:20:20 +0100 Subject: [PATCH] Reformat with black --- djrichtextfield/models.py | 2 +- djrichtextfield/sanitizer.py | 6 +- djrichtextfield/settings.py | 12 +-- djrichtextfield/urls.py | 2 +- djrichtextfield/views.py | 10 +-- djrichtextfield/widgets.py | 32 ++++---- setup.py | 50 ++++++------ testproject/settings.py | 119 ++++++++++++++-------------- testproject/testapp/forms.py | 4 +- testproject/testapp/models.py | 10 ++- testproject/testapp/views.py | 2 +- testproject/tests/test_models.py | 16 ++-- testproject/tests/test_sanitizer.py | 20 ++--- testproject/tests/test_urls.py | 4 +- testproject/tests/test_views.py | 14 ++-- testproject/tests/test_widgets.py | 62 ++++++++------- testproject/urls.py | 10 ++- 17 files changed, 196 insertions(+), 179 deletions(-) diff --git a/djrichtextfield/models.py b/djrichtextfield/models.py index 548c001..ec469b2 100644 --- a/djrichtextfield/models.py +++ b/djrichtextfield/models.py @@ -10,7 +10,7 @@ def __init__(self, *args, field_settings=None, **kwargs): super(RichTextField, self).__init__(*args, **kwargs) def formfield(self, **kwargs): - kwargs['widget'] = RichTextWidget( + kwargs["widget"] = RichTextWidget( field_settings=self.field_settings, sanitizer=self.sanitizer ) return super(RichTextField, self).formfield(**kwargs) diff --git a/djrichtextfield/sanitizer.py b/djrichtextfield/sanitizer.py index 5c381ed..190b39d 100644 --- a/djrichtextfield/sanitizer.py +++ b/djrichtextfield/sanitizer.py @@ -12,8 +12,8 @@ class SanitizerMixin: Get the field sanitizer from the provided kwargs during init, or from the settings. """ - SANITIZER_KEY = 'sanitizer' - SANITIZER_PROFILES_KEY = 'sanitizer_profiles' + SANITIZER_KEY = "sanitizer" + SANITIZER_PROFILES_KEY = "sanitizer_profiles" def __init__(self, *args, sanitizer=None, **kwargs): self.sanitizer = sanitizer @@ -34,7 +34,7 @@ def get_sanitizer(self): if not sanitizer: default_sanitizer = settings.CONFIG.get(self.SANITIZER_KEY) - field_settings = getattr(self, 'field_settings', None) + field_settings = getattr(self, "field_settings", None) if isinstance(field_settings, str): profiles = settings.CONFIG.get(self.SANITIZER_PROFILES_KEY, {}) sanitizer = profiles.get(field_settings, default_sanitizer) diff --git a/djrichtextfield/settings.py b/djrichtextfield/settings.py index 83598e8..6b39d4e 100644 --- a/djrichtextfield/settings.py +++ b/djrichtextfield/settings.py @@ -3,19 +3,19 @@ from django.test.signals import setting_changed DEFAULT_CONFIG = { - 'js': [], - 'css': {}, - 'init_template': None, - 'settings': {}, + "js": [], + "css": {}, + "init_template": None, + "settings": {}, } CONFIG = DEFAULT_CONFIG.copy() -CONFIG.update(getattr(settings, 'DJRICHTEXTFIELD_CONFIG', {})) +CONFIG.update(getattr(settings, "DJRICHTEXTFIELD_CONFIG", {})) @receiver(setting_changed) def update_settings(setting=None, value=None, **kwargs): global CONFIG - if setting == 'DJRICHTEXTFIELD_CONFIG': # pragma: no branch + if setting == "DJRICHTEXTFIELD_CONFIG": # pragma: no branch CONFIG = DEFAULT_CONFIG.copy() if value: # pragma: no branch CONFIG.update(value) diff --git a/djrichtextfield/urls.py b/djrichtextfield/urls.py index 184edbb..11ef91b 100644 --- a/djrichtextfield/urls.py +++ b/djrichtextfield/urls.py @@ -3,5 +3,5 @@ from djrichtextfield.views import InitView urlpatterns = [ - path('init.js', InitView.as_view(), name='djrichtextfield_init'), + path("init.js", InitView.as_view(), name="djrichtextfield_init"), ] diff --git a/djrichtextfield/views.py b/djrichtextfield/views.py index 07f3271..1aae315 100644 --- a/djrichtextfield/views.py +++ b/djrichtextfield/views.py @@ -8,14 +8,14 @@ class InitView(TemplateView): - template_name = 'djrichtextfield/init.js' - content_type = 'application/javascript' + template_name = "djrichtextfield/init.js" + content_type = "application/javascript" def get_settings_json(self): - return mark_safe(json.dumps(settings.CONFIG['settings'], default=force_str)) + return mark_safe(json.dumps(settings.CONFIG["settings"], default=force_str)) def get_context_data(self, **kwargs): context_data = super(InitView, self).get_context_data(**kwargs) - context_data['default_settings'] = self.get_settings_json() - context_data['init_template'] = settings.CONFIG['init_template'] + context_data["default_settings"] = self.get_settings_json() + context_data["init_template"] = settings.CONFIG["init_template"] return context_data diff --git a/djrichtextfield/widgets.py b/djrichtextfield/widgets.py index 5f1bbf0..6264821 100644 --- a/djrichtextfield/widgets.py +++ b/djrichtextfield/widgets.py @@ -10,20 +10,22 @@ class RichTextWidget(SanitizerMixin, Textarea): - CSS_CLASS = 'djrichtextfield' - INIT_URL = 'djrichtextfield_init' - SETTINGS_ATTR = 'data-field-settings' - CONTAINER_CLASS = 'fieldBox' - PROFILE_KEY = 'profiles' + CSS_CLASS = "djrichtextfield" + INIT_URL = "djrichtextfield_init" + SETTINGS_ATTR = "data-field-settings" + CONTAINER_CLASS = "fieldBox" + PROFILE_KEY = "profiles" def __init__(self, attrs=None, field_settings=None, sanitizer=None): - defaults = {'class': self.CSS_CLASS} + defaults = {"class": self.CSS_CLASS} if attrs: - if 'class' in attrs: - attrs['class'] = ' '.join([ - attrs['class'], - defaults['class'], - ]) + if "class" in attrs: + attrs["class"] = " ".join( + [ + attrs["class"], + defaults["class"], + ] + ) defaults.update(attrs) self.field_settings = field_settings or {} super(RichTextWidget, self).__init__(defaults, sanitizer=sanitizer) @@ -31,9 +33,9 @@ def __init__(self, attrs=None, field_settings=None, sanitizer=None): @property def media(self): js = [] - js.extend(settings.CONFIG['js']) + js.extend(settings.CONFIG["js"]) js.append(reverse(self.INIT_URL)) - return Media(js=js, css=settings.CONFIG['css']) + return Media(js=js, css=settings.CONFIG["css"]) def get_field_settings(self): """ @@ -54,7 +56,9 @@ def render(self, name, value, attrs=None, renderer=None): field_settings = self.get_field_settings() if field_settings: attrs[self.SETTINGS_ATTR] = json.dumps(field_settings, default=force_str) - textarea = super(RichTextWidget, self).render(name, value, attrs=attrs, renderer=renderer) + textarea = super(RichTextWidget, self).render( + name, value, attrs=attrs, renderer=renderer + ) return format_html('
{1}
', self.CONTAINER_CLASS, textarea) def value_from_datadict(self, *args, **kwargs): diff --git a/setup.py b/setup.py index a8ec33b..dd1b219 100644 --- a/setup.py +++ b/setup.py @@ -3,45 +3,45 @@ from setuptools import setup -version = '1.6.2.dev0' +version = "1.6.2.dev0" -if sys.argv[-1] == 'publish': - os.system('python setup.py sdist bdist_wheel upload') +if sys.argv[-1] == "publish": + os.system("python setup.py sdist bdist_wheel upload") print("You probably want to also tag the version now:") print(" git tag -a %s -m 'version %s'" % (version, version)) print(" git push --tags") sys.exit() -readme = open('README.rst').read() -history = open('HISTORY.rst').read() +readme = open("README.rst").read() +history = open("HISTORY.rst").read() setup( - name='django-richtextfield', + name="django-richtextfield", version=version, - description='A Django model field and widget that renders a customizable WYSIWYG/rich text editor', - long_description=readme + '\n\n' + history, - author='Jaap Roes', - author_email='jaap.roes@gmail.com', - url='https://github.com/jaap3/django-richtextfield', + description="A Django model field and widget that renders a customizable WYSIWYG/rich text editor", + long_description=readme + "\n\n" + history, + author="Jaap Roes", + author_email="jaap.roes@gmail.com", + url="https://github.com/jaap3/django-richtextfield", packages=[ - 'djrichtextfield', + "djrichtextfield", ], include_package_data=True, install_requires=[], - python_requires='>=3.6', - license='MIT', + python_requires=">=3.6", + license="MIT", zip_safe=False, - keywords='django-richtextfield, djrichtextfield django wywiwyg field', + keywords="django-richtextfield, djrichtextfield django wywiwyg field", classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Framework :: Django', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Natural Language :: English', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3 :: Only', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', + "Development Status :: 5 - Production/Stable", + "Framework :: Django", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Natural Language :: English", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", ], ) diff --git a/testproject/settings.py b/testproject/settings.py index 19fec98..abeeeea 100644 --- a/testproject/settings.py +++ b/testproject/settings.py @@ -2,101 +2,102 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__)) -SECRET_KEY = '--1oh7*5-1_rr%*34^&@e^b59(vgv=zm1wt(wm1ga=pfm73(9i' +SECRET_KEY = "--1oh7*5-1_rr%*34^&@e^b59(vgv=zm1wt(wm1ga=pfm73(9i" DEBUG = True INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'djrichtextfield', - 'testproject.testapp', + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "djrichtextfield", + "testproject.testapp", ] MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -ROOT_URLCONF = 'testproject.urls' +ROOT_URLCONF = "testproject.urls" -WSGI_APPLICATION = 'testproject.wsgi.application' +WSGI_APPLICATION = "testproject.wsgi.application" DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": os.path.join(BASE_DIR, "db.sqlite3"), } } -DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' +DEFAULT_AUTO_FIELD = "django.db.models.AutoField" TEMPLATES = [ { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", ], }, } ] -STATIC_URL = '/static/' +STATIC_URL = "/static/" # Django Rich Text Field TINYMCE_CONFIG = { - 'js': ['//cdn.tiny.cloud/1/no-api-key/tinymce/5/tinymce.min.js'], - 'init_template': 'djrichtextfield/init/tinymce.js', - 'settings': { - 'menubar': False, - 'plugins': 'link image table code', - 'toolbar': 'formatselect | bold italic | removeformat |' ' link unlink image table | code', - 'block_formats': 'Paragraph=p;Header 1=h1;Header 2=h2;Header 3=h3', - 'width': 700, + "js": ["//cdn.tiny.cloud/1/no-api-key/tinymce/5/tinymce.min.js"], + "init_template": "djrichtextfield/init/tinymce.js", + "settings": { + "menubar": False, + "plugins": "link image table code", + "toolbar": "formatselect | bold italic | removeformat |" + " link unlink image table | code", + "block_formats": "Paragraph=p;Header 1=h1;Header 2=h2;Header 3=h3", + "width": 700, }, - 'profiles': { - 'mini': { - 'toolbar': 'bold italic | removeformat', + "profiles": { + "mini": { + "toolbar": "bold italic | removeformat", }, }, } CKEDITOR_CONFIG = { - 'js': ['//cdn.ckeditor.com/4.14.0/standard/ckeditor.js'], - 'init_template': 'djrichtextfield/init/ckeditor.js', - 'settings': { - 'toolbar': [ - {'items': ['Format', '-', 'Bold', 'Italic', '-', 'RemoveFormat']}, - {'items': ['Link', 'Unlink', 'Image', 'Table']}, - {'items': ['Source']}, + "js": ["//cdn.ckeditor.com/4.14.0/standard/ckeditor.js"], + "init_template": "djrichtextfield/init/ckeditor.js", + "settings": { + "toolbar": [ + {"items": ["Format", "-", "Bold", "Italic", "-", "RemoveFormat"]}, + {"items": ["Link", "Unlink", "Image", "Table"]}, + {"items": ["Source"]}, ], - 'format_tags': 'p;h1;h2;h3', - 'width': 700, + "format_tags": "p;h1;h2;h3", + "width": 700, }, - 'profiles': { - 'mini': { - 'toolbar': [ - {'items': ['Bold', 'Italic', '-', 'RemoveFormat']}, + "profiles": { + "mini": { + "toolbar": [ + {"items": ["Bold", "Italic", "-", "RemoveFormat"]}, ] } }, - 'sanitizer': lambda value: 'foo' + value, - 'sanitizer_profiles': { - 'baz': lambda value: value + 'baz', + "sanitizer": lambda value: "foo" + value, + "sanitizer_profiles": { + "baz": lambda value: value + "baz", }, } diff --git a/testproject/testapp/forms.py b/testproject/testapp/forms.py index 5ff4fbf..b528725 100644 --- a/testproject/testapp/forms.py +++ b/testproject/testapp/forms.py @@ -6,8 +6,8 @@ class CommentForm(forms.ModelForm): - content = forms.CharField(widget=RichTextWidget(field_settings='mini')) + content = forms.CharField(widget=RichTextWidget(field_settings="mini")) class Meta: model = Comment - exclude = ['post'] + exclude = ["post"] diff --git a/testproject/testapp/models.py b/testproject/testapp/models.py index 8860ebc..95899de 100644 --- a/testproject/testapp/models.py +++ b/testproject/testapp/models.py @@ -6,14 +6,14 @@ class Post(models.Model): title = models.CharField(max_length=50) - lead = RichTextField(field_settings='mini') + lead = RichTextField(field_settings="mini") content = RichTextField() def get_absolute_url(self): - return reverse('post_detail', kwargs={'pk': self.pk}) + return reverse("post_detail", kwargs={"pk": self.pk}) def get_add_comment_url(self): - return reverse('post_add_comment', kwargs={'pk': self.pk}) + return reverse("post_add_comment", kwargs={"pk": self.pk}) def __str__(self): return self.title @@ -24,7 +24,9 @@ class Comment(models.Model): content = models.TextField() def get_absolute_url(self): - return '{}#c{}'.format(reverse('post_detail', kwargs={'pk': self.post.pk}), self.pk) + return "{}#c{}".format( + reverse("post_detail", kwargs={"pk": self.post.pk}), self.pk + ) def __str__(self): return 'Comment on "%s"' % self.post.title diff --git a/testproject/testapp/views.py b/testproject/testapp/views.py index 719aa5a..94fed04 100644 --- a/testproject/testapp/views.py +++ b/testproject/testapp/views.py @@ -14,5 +14,5 @@ class CommentCreateView(UpdateView): form_class = CommentForm def get_object(self): - post = get_object_or_404(Post, pk=self.kwargs['pk']) + post = get_object_or_404(Post, pk=self.kwargs["pk"]) return Comment(post=post) diff --git a/testproject/tests/test_models.py b/testproject/tests/test_models.py index d5f413e..6ea2217 100644 --- a/testproject/tests/test_models.py +++ b/testproject/tests/test_models.py @@ -6,7 +6,7 @@ def empty_string(value): - return '' + return "" class TestRichTextField(TestCase): @@ -21,8 +21,8 @@ def test_formfield_widget_passes_settings(self): Model field passes setting to widget """ settings = { - 'foo': True, - 'bar': [1, 2, 3], + "foo": True, + "bar": [1, 2, 3], } widget = RichTextField(field_settings=settings).formfield().widget self.assertEqual(widget.field_settings, settings) @@ -39,19 +39,19 @@ def test_clean_uses_sanitizer(self): """ Model field sanitizes values on clean with the provided sanitizer """ - field = RichTextField(sanitizer=lambda value: 'test' + value) - self.assertEqual('testbar', field.clean('bar', None)) + field = RichTextField(sanitizer=lambda value: "test" + value) + self.assertEqual("testbar", field.clean("bar", None)) def test_field_validates_after_sanitizer(self): """ Required field raises ValidationError if sanitizer returns empty """ field = RichTextField(blank=False, sanitizer=empty_string) - self.assertRaises(ValidationError, field.clean, 'fancy text', None) + self.assertRaises(ValidationError, field.clean, "fancy text", None) # No error if field is allowed to be blank field = RichTextField(blank=True, sanitizer=empty_string) - field.clean('fancy text', None) + field.clean("fancy text", None) def test_sanitizer_handles_none(self): """ @@ -61,4 +61,4 @@ def test_sanitizer_handles_none(self): try: field.clean(None, None) except Exception: - raise AssertionError('Expected no errors') + raise AssertionError("Expected no errors") diff --git a/testproject/tests/test_sanitizer.py b/testproject/tests/test_sanitizer.py index a239b39..9e07e49 100644 --- a/testproject/tests/test_sanitizer.py +++ b/testproject/tests/test_sanitizer.py @@ -19,23 +19,25 @@ def test_get_sanitizer_uses_profile_sanitizer(self): Sanitizer from settings for the given profile """ mixin = SanitizerMixin() - mixin.field_settings = 'baz' - self.assertEqual(settings.CONFIG['sanitizer_profiles']['baz'], mixin.get_sanitizer()) + mixin.field_settings = "baz" + self.assertEqual( + settings.CONFIG["sanitizer_profiles"]["baz"], mixin.get_sanitizer() + ) def test_clean_uses_global_sanitizer_with_no_sanitizer_profiles(self): """ Global sanitizer from settings is returned if none match the profile """ mixin = SanitizerMixin() - mixin.field_settings = 'sanitizer_profile_does_not_exist' - self.assertEqual(settings.CONFIG['sanitizer'], mixin.get_sanitizer()) + mixin.field_settings = "sanitizer_profile_does_not_exist" + self.assertEqual(settings.CONFIG["sanitizer"], mixin.get_sanitizer()) def test_clean_uses_global_sanitizer(self): """ Global sanitizer from settings is returned """ mixin = SanitizerMixin() - self.assertEqual(settings.CONFIG['sanitizer'], mixin.get_sanitizer()) + self.assertEqual(settings.CONFIG["sanitizer"], mixin.get_sanitizer()) @override_settings(DJRICHTEXTFIELD_CONFIG={}) def test_clean_uses_noop_sanitizer(self): @@ -49,10 +51,10 @@ def test_import_string(self): """ Passing a function path causes it to be imported """ - mixin = SanitizerMixin(sanitizer='django.utils.text.slugify') + mixin = SanitizerMixin(sanitizer="django.utils.text.slugify") sanitizer = mixin.get_sanitizer() - self.assertEqual('django.utils.text', sanitizer.__module__) - self.assertEqual('slugify', sanitizer.__name__) + self.assertEqual("django.utils.text", sanitizer.__module__) + self.assertEqual("slugify", sanitizer.__name__) class TestNoop(TestCase): @@ -61,4 +63,4 @@ def test_object_in_is_out(self): self.assertEqual(value, noop(value)) def test_str_in_is_out(self): - self.assertEqual('foo', noop('foo')) + self.assertEqual("foo", noop("foo")) diff --git a/testproject/tests/test_urls.py b/testproject/tests/test_urls.py index 5ed3c5c..452cd08 100644 --- a/testproject/tests/test_urls.py +++ b/testproject/tests/test_urls.py @@ -4,5 +4,5 @@ class TestUrls(TestCase): def test_reverse(self): - url = reverse('djrichtextfield_init') - self.assertEqual(url, '/djrichtextfield/init.js') + url = reverse("djrichtextfield_init") + self.assertEqual(url, "/djrichtextfield/init.js") diff --git a/testproject/tests/test_views.py b/testproject/tests/test_views.py index f6c5df9..a042ffc 100644 --- a/testproject/tests/test_views.py +++ b/testproject/tests/test_views.py @@ -3,19 +3,21 @@ from django.urls import reverse -@override_settings(DJRICHTEXTFIELD_CONFIG={'init_template': 'djrichtextfield/init/tinymce.js'}) +@override_settings( + DJRICHTEXTFIELD_CONFIG={"init_template": "djrichtextfield/init/tinymce.js"} +) class TestInitView(TestCase): def setUp(self): - self.response = self.client.get(reverse('djrichtextfield_init')) + self.response = self.client.get(reverse("djrichtextfield_init")) def test_template(self): - self.assertEqual(self.response.template_name, ['djrichtextfield/init.js']) + self.assertEqual(self.response.template_name, ["djrichtextfield/init.js"]) def test_content_type(self): - self.assertEqual(self.response['content-type'], 'application/javascript') + self.assertEqual(self.response["content-type"], "application/javascript") def test_init_template_in_context(self): self.assertEqual( - 'djrichtextfield/init/tinymce.js', - self.response.context_data['init_template'], + "djrichtextfield/init/tinymce.js", + self.response.context_data["init_template"], ) diff --git a/testproject/tests/test_widgets.py b/testproject/tests/test_widgets.py index 1e365f8..e57ef74 100644 --- a/testproject/tests/test_widgets.py +++ b/testproject/tests/test_widgets.py @@ -7,13 +7,13 @@ from djrichtextfield.widgets import RichTextWidget CONFIG = { - 'js': ['foo.js'], - 'css': { - 'all': ['bar.css'], + "js": ["foo.js"], + "css": { + "all": ["bar.css"], }, - 'settings': {'foo': True, 'bar': [1, 2, 3]}, - 'profiles': { - 'simple': {'bar': [1, 2]}, + "settings": {"foo": True, "bar": [1, 2, 3]}, + "profiles": { + "simple": {"bar": [1, 2]}, }, } @@ -23,42 +23,46 @@ def test_css_class(self): """ Has the correct css class set """ - self.assertEqual(RichTextWidget().attrs['class'], 'djrichtextfield') + self.assertEqual(RichTextWidget().attrs["class"], "djrichtextfield") def test_attrs(self): """ Takes attrs into account """ - widget = RichTextWidget({'cols': 10}) - self.assertEqual(widget.attrs['cols'], 10) + widget = RichTextWidget({"cols": 10}) + self.assertEqual(widget.attrs["cols"], 10) def test_css_class_addition(self): """ Adds to the given css class """ - widget = RichTextWidget({'class': 'somethingelse'}) - self.assertEqual(widget.attrs['class'], 'somethingelse djrichtextfield') + widget = RichTextWidget({"class": "somethingelse"}) + self.assertEqual(widget.attrs["class"], "somethingelse djrichtextfield") def test_value_from_datadict_sanitizes_value(self): """ Value returned by value_from_datadict is sanitized """ widget = RichTextWidget() - self.assertEqual('foobar', widget.value_from_datadict({'baz': 'bar'}, {}, 'baz')) + self.assertEqual( + "foobar", widget.value_from_datadict({"baz": "bar"}, {}, "baz") + ) def test_value_from_datadict_handles_none(self): """ value_from_datadict doesn't sanitize None values """ widget = RichTextWidget() - self.assertEqual(None, widget.value_from_datadict({}, {}, 'baz')) + self.assertEqual(None, widget.value_from_datadict({}, {}, "baz")) def test_init_sanitizer_is_used_by_value_from_datadict(self): """ Sanitizer passed on widget initialisation is used """ - widget = RichTextWidget(sanitizer=lambda value: value + 'baz') - self.assertEqual('barbaz', widget.value_from_datadict({'baz': 'bar'}, {}, 'baz')) + widget = RichTextWidget(sanitizer=lambda value: value + "baz") + self.assertEqual( + "barbaz", widget.value_from_datadict({"baz": "bar"}, {}, "baz") + ) @override_settings(DJRICHTEXTFIELD_CONFIG=CONFIG) @@ -73,13 +77,13 @@ def test_media_js(self): """ Test that the correct javascript files are included. """ - self.assertTrue(set(self.config['js']).issubset(self.widget.media._js)) + self.assertTrue(set(self.config["js"]).issubset(self.widget.media._js)) def test_media_css(self): """ Test that the correct CSS files are included. """ - self.assertEqual(self.config['css'], self.widget.media._css) + self.assertEqual(self.config["css"], self.widget.media._css) def test_render(self): """ @@ -90,45 +94,45 @@ def test_render(self): expected = ( '
' '' - '
'.format(self.container_class) + "".format(self.container_class) ) - self.assertHTMLEqual(expected, widget.render('', '')) + self.assertHTMLEqual(expected, widget.render("", "")) def test_render_with_settings(self): """ The field includes the correct data attribute. """ - settings = {'foo': False} + settings = {"foo": False} widget = RichTextWidget(field_settings=settings) config = json.dumps(settings) expected = ( '
' '' - '
'.format(self.container_class, escape(config)) + "".format(self.container_class, escape(config)) ) - self.assertHTMLEqual(expected, widget.render('', '')) + self.assertHTMLEqual(expected, widget.render("", "")) def test_render_with_profile(self): """ The field includes the correct data attribute. """ - widget = RichTextWidget(field_settings='simple') - config = json.dumps(self.config['profiles']['simple']) + widget = RichTextWidget(field_settings="simple") + config = json.dumps(self.config["profiles"]["simple"]) expected = ( '
' '' - '
'.format(self.container_class, escape(config)) + "".format(self.container_class, escape(config)) ) - self.assertHTMLEqual(expected, widget.render('', '')) + self.assertHTMLEqual(expected, widget.render("", "")) def test_render_with_missing_profile(self): """ The field gets rendered without a data attribute. """ - widget = RichTextWidget(field_settings='missing') + widget = RichTextWidget(field_settings="missing") expected = ( '
' '' - '
'.format(self.container_class) + "".format(self.container_class) ) - self.assertHTMLEqual(expected, widget.render('', '')) + self.assertHTMLEqual(expected, widget.render("", "")) diff --git a/testproject/urls.py b/testproject/urls.py index 0c30a69..fb685cf 100644 --- a/testproject/urls.py +++ b/testproject/urls.py @@ -7,8 +7,10 @@ admin.autodiscover() urlpatterns = [ - path('admin/', admin.site.urls), - path('djrichtextfield/', include('djrichtextfield.urls')), - path('post//', PostDetail.as_view(), name='post_detail'), - path('post//comment/', CommentCreateView.as_view(), name='post_add_comment'), + path("admin/", admin.site.urls), + path("djrichtextfield/", include("djrichtextfield.urls")), + path("post//", PostDetail.as_view(), name="post_detail"), + path( + "post//comment/", CommentCreateView.as_view(), name="post_add_comment" + ), ]