From 46b238e39d6241affd3eb4fc51944acef69d7525 Mon Sep 17 00:00:00 2001 From: Bernhard Hagmann Date: Fri, 25 Oct 2024 11:28:29 +0200 Subject: [PATCH] SIANXKE-404: Update Python, Django, and package versions --- .github/workflows/publish.yml | 6 +- .github/workflows/test.yml | 25 ++++---- CHANGELOG.md | 11 +++- README.md | 11 ++-- requirements.txt | 6 +- setup.py | 13 ++-- tests/cleanhtmlfield_testapp/settings.py | 11 ++-- .../cleanhtmlfield_testapp/test_clean_html.py | 8 +-- .../tests_clean_styles.py | 63 +++++++++++++------ tests/myapp/tests.py | 18 +++--- tests/requirements.txt | 2 + 11 files changed, 105 insertions(+), 69 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 59ee48d..1603803 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -8,12 +8,12 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: - python-version: '3.8' + python-version: '3.13' architecture: 'x64' - name: Install dependencies diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1dc0bcc..e9e0a5e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,25 +8,26 @@ jobs: fail-fast: false matrix: python-version: - - '3.7' - - '3.8' - '3.9' - '3.10' + - '3.11' + - '3.12' + - '3.13' django-version: - - '3.2' - - '4.0' - - '4.1' + - '4.2' + - '5.0' + - '5.1' exclude: - - python-version: '3.7' - django-version: '4.0' - - python-version: '3.7' - django-version: '4.1' + - python-version: '3.9' + django-version: '5.0' + - python-version: '3.9' + django-version: '5.1' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} @@ -58,4 +59,4 @@ jobs: coverage xml - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 diff --git a/CHANGELOG.md b/CHANGELOG.md index 34e16ee..d3ca764 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.4.0] +### Removed +- Dropped support for Django 3.2, 4.0, 4.1 +- Dropped support for Python 3.7 and 3.8 +### Added +- Added support for Django 4.2, 5.0, and 5.1 +- Added support for Python 3.11, 3.12, and 3.13 + ## [1.3.0] ### Removed - Dropped support for Django 2.2 @@ -37,7 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Initial Release -[Unreleased]: https://github.com/anexia/django-cleanhtmlfield/compare/v1.3.0...HEAD +[Unreleased]: https://github.com/anexia/django-cleanhtmlfield/compare/v1.4.0...HEAD +[1.3.0]: https://pypi.org/project/django-cleanhtmlfield/1.4.0/ [1.3.0]: https://pypi.org/project/django-cleanhtmlfield/1.3.0/ [1.2.0]: https://pypi.org/project/django-cleanhtmlfield/1.2.0/ [1.1.0]: https://pypi.org/project/django-cleanhtmlfield/1.1.0/ diff --git a/README.md b/README.md index 85713c1..e44e65a 100644 --- a/README.md +++ b/README.md @@ -180,11 +180,12 @@ ModelSerializer.serializer_field_mapping[HTMLField] = RestHtmlField This library should be compatible with the latest Django. For reference, here is a matrix showing the guaranteed and tested compatibility. -django-cleanhtmlfield Version | Django Versions | Python ------------------------------ | --------------- | ------ -1.1 | 2.2, 3.0, 3.1 | 3.5 - 3.8 -1.2 | 2.2, 3.1, 3.2 | 3.7 - 3.10 -1.3 | 3.2, 4.0, 4.1 | 3.7 - 3.10 +| django-cleanhtmlfield Version | Django Versions | Python | +|-------------------------------|-----------------|------------| +| 1.1 | 2.2, 3.0, 3.1 | 3.5 - 3.8 | +| 1.2 | 2.2, 3.1, 3.2 | 3.7 - 3.10 | +| 1.3 | 3.2, 4.0, 4.1 | 3.7 - 3.10 | +| 1.4 | 4.2, 5.0, 5.1 | 3.9 - 3.13 | # License diff --git a/requirements.txt b/requirements.txt index 40d3ba8..a69ee6f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,6 @@ # Development dependencies codecov>=2.1 -setuptools>=42 -wheel>=0.37 -twine>=3.4 +setuptools>=75 +wheel>=0.44 +twine>=5.1 diff --git a/setup.py b/setup.py index 3e646ed..dba5793 100644 --- a/setup.py +++ b/setup.py @@ -22,24 +22,25 @@ author_email='AStocker@anexia-it.com', install_requires=[ 'django', - 'beautifulsoup4>=4.6,<5', + 'beautifulsoup4>=4.12,<4.13', ], classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment', 'Framework :: Django', - 'Framework :: Django :: 2.2', - 'Framework :: Django :: 3.1', - 'Framework :: Django :: 3.2', + 'Framework :: Django :: 4.2', + 'Framework :: Django :: 5.0', + 'Framework :: Django :: 5.1', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', 'Topic :: Internet :: WWW/HTTP', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', ], diff --git a/tests/cleanhtmlfield_testapp/settings.py b/tests/cleanhtmlfield_testapp/settings.py index 7d101e0..868ebce 100644 --- a/tests/cleanhtmlfield_testapp/settings.py +++ b/tests/cleanhtmlfield_testapp/settings.py @@ -4,10 +4,10 @@ Generated by 'django-admin startproject' using Django 1.8. For more information on this file, see -https://docs.djangoproject.com/en/1.8/topics/settings/ +https://docs.djangoproject.com/en/stable/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.8/ref/settings/ +https://docs.djangoproject.com/en/stable/ref/settings/ """ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) @@ -19,7 +19,7 @@ # Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/stable/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = "!u-4q!$+GO2_=!$p&0cr*57z1oN72sady26&8" @@ -86,9 +86,10 @@ } } +DEFAULT_AUTO_FIELD = "django.db.models.AutoField" # Internationalization -# https://docs.djangoproject.com/en/1.8/topics/i18n/ +# https://docs.djangoproject.com/en/stable/topics/i18n/ LANGUAGE_CODE = "en-us" @@ -102,7 +103,7 @@ # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.8/howto/static-files/ +# https://docs.djangoproject.com/en/stable/howto/static-files/ STATIC_URL = "/static/" diff --git a/tests/cleanhtmlfield_testapp/test_clean_html.py b/tests/cleanhtmlfield_testapp/test_clean_html.py index a7862b0..9908fcb 100644 --- a/tests/cleanhtmlfield_testapp/test_clean_html.py +++ b/tests/cleanhtmlfield_testapp/test_clean_html.py @@ -9,11 +9,9 @@ def test_clean_script_tags(self): Tests that javascript "script" tags are removed :return: """ - self.assertEquals( - clean_html( - "

test

", strip_unsafe=True - ), + self.assertEqual( "

test

", + clean_html("

test

", strip_unsafe=True) ) def test_clean_html_keep_it(self): @@ -28,4 +26,4 @@ def test_clean_html_keep_it(self):

Some title

I am Groot. I am Groot. I am Groot. We are Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. We are Groot. We are Groot. We are Groot. We are Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. We are Groot.

""" - self.assertEquals(clean_html(some_html_str), some_html_str) + self.assertEqual(some_html_str, clean_html(some_html_str)) diff --git a/tests/cleanhtmlfield_testapp/tests_clean_styles.py b/tests/cleanhtmlfield_testapp/tests_clean_styles.py index 44b0c7f..95a8594 100644 --- a/tests/cleanhtmlfield_testapp/tests_clean_styles.py +++ b/tests/cleanhtmlfield_testapp/tests_clean_styles.py @@ -9,17 +9,24 @@ def test_clean_styles_multiple_double_dots(self): Tests that cleaning css styles leaves styles with multiple dots in place :return: """ - self.assertEquals(clean_styles("color:red:foo();"), "color:red:foo();") + self.assertEqual( + "color:red:foo();", + clean_styles("color:red:foo();") + ) def test_clean_styles_adds_semicolon(self): """ Tests whether clean styles add a semicolon :return: """ - self.assertEquals(clean_styles("color:red"), "color:red;") + self.assertEqual( + "color:red;", + clean_styles("color:red") + ) - self.assertEquals( - clean_styles("color:red; font-size:10pt"), "color:red;font-size:10pt;" + self.assertEqual( + "color:red;font-size:10pt;", + clean_styles("color:red; font-size:10pt") ) def test_clean_styles_single(self): @@ -27,20 +34,29 @@ def test_clean_styles_single(self): Tests that cleaning styles removes extra spaces :return: """ - self.assertEquals(clean_styles("padding: 9px; "), "padding:9px;") + self.assertEqual( + "padding:9px;", + clean_styles("padding: 9px; ") + ) - self.assertEquals(clean_styles("margin: 9px; "), "margin:9px;") + self.assertEqual( + "margin:9px;", + clean_styles("margin: 9px; ") + ) - self.assertEquals(clean_styles("padding-top: 9px; "), "padding-top:9px;") + self.assertEqual( + "padding-top:9px;", + clean_styles("padding-top: 9px; ") + ) def test_clean_styles_multiple(self): """ Tests that cleaning styles works with multiple styles :return: """ - self.assertEquals( - clean_styles("padding: 9px; margin-top: 10px; margin-bottom: 10px;"), + self.assertEqual( "padding:9px;margin-top:10px;margin-bottom:10px;", + clean_styles("padding: 9px; margin-top: 10px; margin-bottom: 10px;") ) def test_clean_styles_invalid_element(self): @@ -48,11 +64,9 @@ def test_clean_styles_invalid_element(self): Tests that cleaning styles removes invalid elements :return: """ - self.assertEquals( - clean_styles( - "padding: 9px; some-invalid-attribute: 10px; margin-bottom: 10px;" - ), + self.assertEqual( "padding:9px;margin-bottom:10px;", + clean_styles("padding: 9px; some-invalid-attribute: 10px; margin-bottom: 10px;") ) def test_clean_styles_preserve_styles_whitespace(self): @@ -61,18 +75,27 @@ def test_clean_styles_preserve_styles_whitespace(self): :return: """ with self.settings(PRESERVE_STYLES_WHITESPACE=True): - self.assertEquals(clean_styles("padding: 9px; "), "padding: 9px;") + self.assertEqual( + "padding: 9px;", + clean_styles("padding: 9px; ") + ) - self.assertEquals(clean_styles("padding : 9px; "), "padding : 9px;") + self.assertEqual( + "padding : 9px;", + clean_styles("padding : 9px; ") + ) - self.assertEquals(clean_styles("padding: 9px; "), "padding: 9px;") + self.assertEqual( + "padding: 9px;", + clean_styles("padding: 9px; ") + ) - self.assertEquals( - clean_styles("padding: 9px; margin-top: 10px; margin-bottom: 10px;"), + self.assertEqual( "padding: 9px; margin-top: 10px; margin-bottom: 10px;", + clean_styles("padding: 9px; margin-top: 10px; margin-bottom: 10px;") ) - self.assertEquals( - clean_styles("padding: 9px;margin-top: 10px;margin-bottom: 10px;"), + self.assertEqual( "padding: 9px;margin-top: 10px;margin-bottom: 10px;", + clean_styles("padding: 9px;margin-top: 10px;margin-bottom: 10px;") ) diff --git a/tests/myapp/tests.py b/tests/myapp/tests.py index 82f1d8c..f9a0ba4 100644 --- a/tests/myapp/tests.py +++ b/tests/myapp/tests.py @@ -45,15 +45,15 @@ def test_try_save_with_invalid_content(self): :return: """ malicious_html_string = """

Groot Ipsum

- -

I am Groot. I am Groot. I am Groot. We are Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. We are Groot. We are Groot. We are Groot. We are Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. We are Groot.

-

I am Groot. I am Groot. I am Groot. We are Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. We are Groot. We are Groot. We are Groot. We are Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. We are Groot. -

-

Some title

-

I am Groot. I am Groot. I am Groot. We are Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. We are Groot. We are Groot. We are Groot. We are Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. We are Groot. -

""" + +

I am Groot. I am Groot. I am Groot. We are Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. We are Groot. We are Groot. We are Groot. We are Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. We are Groot.

+

I am Groot. I am Groot. I am Groot. We are Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. We are Groot. We are Groot. We are Groot. We are Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. We are Groot. +

+

Some title

+

I am Groot. I am Groot. I am Groot. We are Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. We are Groot. We are Groot. We are Groot. We are Groot. We are Groot. I am Groot. We are Groot. I am Groot. I am Groot. I am Groot. We are Groot. We are Groot. +

""" obj = MyModel() obj.some_html_field = malicious_html_string obj.save() diff --git a/tests/requirements.txt b/tests/requirements.txt index e69de29..bfda73f 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -0,0 +1,2 @@ +django>=4.2,<=5.2 +beautifulsoup4>=4.12,<4.13