Skip to content

Commit

Permalink
Update test and misc for Django 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lqez committed Dec 19, 2019
1 parent 702b574 commit 3d44a3a
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 45 deletions.
5 changes: 3 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
--------
Expand Down
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <https://docs.djangoproject.com/en/1.11/topics/files/>

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

Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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.

2 changes: 1 addition & 1 deletion django_summernote/__init__.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions django_summernote/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@
},
},
]

if django.VERSION >= (3, 0):
X_FRAME_OPTIONS = 'SAMEORIGIN'
9 changes: 5 additions & 4 deletions django_summernote/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions djs_playground/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,6 @@
},
'lazy': False,
}

# From Django 3.0, this setting is necessary for iframe
X_FRAME_OPTIONS = 'SAMEORIGIN'
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
DJANGO_SETTINGS_MODULE=django_summernote.test_settings
20 changes: 0 additions & 20 deletions runtests.py

This file was deleted.

7 changes: 0 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -45,6 +40,4 @@
classifiers=CLASSIFIERS,

install_requires=['django'],
test_suite='runtests.runtests',
tests_require=TESTS_REQUIRE,
)
11 changes: 9 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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

0 comments on commit 3d44a3a

Please sign in to comment.