From 3d44a3ab1758a1a412e9f582bf71be9ec31ee547 Mon Sep 17 00:00:00 2001 From: Park Hyunwoo Date: Fri, 20 Dec 2019 04:30:16 +0900 Subject: [PATCH] Update test and misc for Django 3.0 --- CHANGES.md | 5 +-- README.md | 32 ++++++++++++++----- django_summernote/__init__.py | 2 +- .../{tests.py => test_django_summernote.py} | 8 ++++- django_summernote/test_settings.py | 3 ++ django_summernote/views.py | 9 +++--- djs_playground/settings.py | 3 ++ pytest.ini | 2 ++ runtests.py | 20 ------------ setup.py | 7 ---- tox.ini | 11 +++++-- 11 files changed, 57 insertions(+), 45 deletions(-) rename django_summernote/{tests.py => test_django_summernote.py} (99%) create mode 100644 pytest.ini delete mode 100644 runtests.py diff --git a/CHANGES.md b/CHANGES.md index aa67c191..4230b336 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,9 +1,10 @@ -0.8.11.5 (WIP) +0.8.11.5 -------- - Fix crispy-forms issue with SummernoteInplaceWidget (@wuuuduu) - Security fixes and CustomUserPassesTestMixin in SummernoteUploadAttachment view (@wuuuduu) - Update Travis / Tox settings for the latest Django and Python versions (@lqez) - + - Add test targets for Django 3.0+ (@lqez) + - Replace test runer with pytest (@lqez) Archived -------- diff --git a/README.md b/README.md index 622f74f7..4bce363c 100644 --- a/README.md +++ b/README.md @@ -42,21 +42,26 @@ SETUP 4. Be sure to set proper `MEDIA_URL` for attachments. - The following is an example test code: - + MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') - + - When debug option is enabled(```DEBUG=True```), DO NOT forget to add urlpatterns as shown below: - + from django.conf import settings from django.conf.urls.static import static - + if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) - + - Please, read the official document more in detail: -5. Run database migration for preparing attachment model. +5. If you're using Django 3.x with default SummernoteWidget, then + + - Do not forget to set `X_FRAME_OPTIONS = 'SAMEORIGIN'` in your django settings. + - [Clickjacking Protection](https://docs.djangoproject.com/en/3.0/ref/clickjacking/) + +6. Run database migration for preparing attachment model. python manage.py migrate @@ -201,7 +206,7 @@ SUMMERNOTE_CONFIG = { # You can disable attachment feature. 'disable_attachment': False, - + # Set `True` to return attachment paths in absolute URIs. 'attachment_absolute_uri': False, @@ -268,13 +273,24 @@ class SomeForm(forms.Form): foo = forms.CharField(widget=SummernoteWidget(attrs={'data-user-id': 123456, 'data-device': 'iphone'})) ``` +TEST +---- + +Run `tox`. If you don't have it, just `pip install tox` + +You can also run test with only specified targets. +``` +$ tox -e py27-dj111, py38-dj301 +``` + + LIMITATIONS ----------- `django-summernote` does currently not support upload of non-image files. + LICENSE ------- `django-summernote` is distributed under MIT license and proudly served by great contributors. - diff --git a/django_summernote/__init__.py b/django_summernote/__init__.py index 1b7170e2..e522b97b 100644 --- a/django_summernote/__init__.py +++ b/django_summernote/__init__.py @@ -1,4 +1,4 @@ -version_info = (0, 8, 11, 4) +version_info = (0, 8, 11, 5) __version__ = version = '.'.join(map(str, version_info)) __project__ = PROJECT = 'django-summernote' diff --git a/django_summernote/tests.py b/django_summernote/test_django_summernote.py similarity index 99% rename from django_summernote/tests.py rename to django_summernote/test_django_summernote.py index 5ccf4b5d..040f1ca0 100644 --- a/django_summernote/tests.py +++ b/django_summernote/test_django_summernote.py @@ -17,7 +17,13 @@ from django.test import TestCase, Client, override_settings from django_summernote.utils import get_attachment_storage, get_attachment_model -from imp import reload +import sys + +if sys.version_info >= (3, 4): + from importlib import reload +else: + from imp import reload + import json import os diff --git a/django_summernote/test_settings.py b/django_summernote/test_settings.py index d8556a7d..e17473ce 100644 --- a/django_summernote/test_settings.py +++ b/django_summernote/test_settings.py @@ -52,3 +52,6 @@ }, }, ] + +if django.VERSION >= (3, 0): + X_FRAME_OPTIONS = 'SAMEORIGIN' diff --git a/django_summernote/views.py b/django_summernote/views.py index 13d48182..2cf17239 100644 --- a/django_summernote/views.py +++ b/django_summernote/views.py @@ -4,7 +4,10 @@ from django.templatetags.static import static from django.http import HttpResponse, JsonResponse from django.template.loader import render_to_string -from django.utils.translation import ugettext as _ +if django_version >= (3, 0): + from django.utils.translation import gettext as _ +else: + from django.utils.translation import ugettext as _ from django.views.generic import TemplateView from django_summernote.forms import UploadForm @@ -70,9 +73,7 @@ def get(self, request, *args, **kwargs): @using_config def post(self, request, *args, **kwargs): - authenticated = \ - request.user.is_authenticated if django_version >= (1, 10) \ - else request.user.is_authenticated() + authenticated = request.user.is_authenticated if config['disable_attachment']: logger.error( diff --git a/djs_playground/settings.py b/djs_playground/settings.py index d740d6f5..4fd581f7 100644 --- a/djs_playground/settings.py +++ b/djs_playground/settings.py @@ -153,3 +153,6 @@ }, 'lazy': False, } + +# From Django 3.0, this setting is necessary for iframe +X_FRAME_OPTIONS = 'SAMEORIGIN' diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..9473e566 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +DJANGO_SETTINGS_MODULE=django_summernote.test_settings diff --git a/runtests.py b/runtests.py deleted file mode 100644 index 01881004..00000000 --- a/runtests.py +++ /dev/null @@ -1,20 +0,0 @@ -import os -import sys -os.environ['DJANGO_SETTINGS_MODULE'] = 'django_summernote.test_settings' -test_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -sys.path.insert(0, test_dir) - -import django -from django.conf import settings -from django.test.utils import get_runner - -django.setup() - -def runtests(): - TestRunner = get_runner(settings) - test_runner = TestRunner(verbosity=1, interactive=True) - failures = test_runner.run_tests(['django_summernote']) - sys.exit(bool(failures)) - -if __name__ == '__main__': - runtests() diff --git a/setup.py b/setup.py index b0aa7f34..301329d1 100644 --- a/setup.py +++ b/setup.py @@ -25,11 +25,6 @@ 'Topic :: Utilities', ] -TESTS_REQUIRE = ['django-dummy-plug'] -# mock is available as unittest.mock in Python 3.3 onwards. -if sys.version_info < (3, 3, 0): - TESTS_REQUIRE += ['mock'] - setup( name=PROJECT, version=version, @@ -45,6 +40,4 @@ classifiers=CLASSIFIERS, install_requires=['django'], - test_suite='runtests.runtests', - tests_require=TESTS_REQUIRE, ) diff --git a/tox.ini b/tox.ini index f4aa6880..70387deb 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ envlist = {py27}-{dj111}, {py34}-{dj111,dj201}, {py35}-{dj111,dj200,dj201,dj202} - {py36,py37,py38}-{dj111,dj200,dj201,dj202,djmaster} + {py36,py37,py38}-{dj111,dj200,dj201,dj202,dj300,dj301,djmaster} [travis] python = @@ -24,11 +24,18 @@ basepython = py38: python3.8 deps = + pytest + pytest-django coverage + django-dummy-plug + + py27: mock dj111: Django<1.12 dj200: Django<2.1 dj201: Django<2.2 dj202: Django<2.3 + dj300: Django<3.1 + dj301: Django<3.2 djmaster: https://github.com/django/django/archive/master.tar.gz -commands = coverage run -a setup.py test +commands = coverage run -m pytest