From ddd662dc7f555b47c55315e0f2f852afa8375274 Mon Sep 17 00:00:00 2001 From: Davide Date: Fri, 6 Oct 2023 10:14:28 +0200 Subject: [PATCH 1/7] Test against django 5.0a and python 3.12 --- .github/workflows/ci.yaml | 2 +- .vscode/settings.json | 6 +++++- setup.cfg | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a1fa512..03da5d2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v3 diff --git a/.vscode/settings.json b/.vscode/settings.json index 5164756..94195e9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,6 +11,10 @@ "**/*.pytest_cache": true, ".ropeproject": true, ".coverage": true, + ".tox": true, + ".venv": true, + ".eggs": true, + "*.egg-info": true, }, "python.analysis.extraPaths": [ "${workspaceFolder}/tests/" @@ -21,5 +25,5 @@ "python.testing.pytestArgs": [ "--reuse-db" ], - "python.formatting.provider": "black" + "black-formatter.importStrategy": "fromEnvironment", } \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index dde32e2..e8b2f48 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,6 +16,7 @@ classifiers = Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 Framework :: Django Framework :: Django :: 3.2 Framework :: Django :: 4.0 @@ -63,8 +64,8 @@ DJANGO_SETTINGS_MODULE = tests.example_project.settings [tox:tox] envlist = py{37,38,39,310}-django32 - py{38,39,310,311}-django{40,41,42} - py{310,311}-djangomaster + py{38,39,310,311,312}-django{40,41,42} + py{310,311,312}-django{50,master} [testenv] usedevelop = true @@ -77,4 +78,5 @@ deps= django40: Django>=4.0,<4.1 django41: Django>=4.1,<4.2 django42: Django>=4.2,<4.3 + django50: Django>=5.0a,<5.1 djangomaster: https://github.com/django/django/archive/main.tar.gz From 8775d04e1512f1fa61280eda4be0da60c2ee2b70 Mon Sep 17 00:00:00 2001 From: Davide Date: Fri, 6 Oct 2023 10:28:00 +0200 Subject: [PATCH 2/7] Try tox-gh --- .github/workflows/ci.yaml | 16 ++++++++++------ setup.cfg | 9 +++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 03da5d2..3d68edd 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2,6 +2,10 @@ name: Linters/Tests on: pull_request +concurrency: + group: check-${{ github.ref }} + cancel-in-progress: true + jobs: tests: @@ -20,13 +24,13 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip wheel setuptools - python -m pip install --upgrade tox tox-py - - name: Run tox targets for ${{ matrix.python-version }} - run: tox --py current + - name: Install tox + run: python -m pip install tox-gh>=1.2 + - name: Setup test suite + run: tox -vv --notest + - name: Run test suite + run: tox --skip-pkg-install lint: name: Run black diff --git a/setup.cfg b/setup.cfg index e8b2f48..cb19b92 100644 --- a/setup.cfg +++ b/setup.cfg @@ -67,6 +67,15 @@ envlist = py{38,39,310,311,312}-django{40,41,42} py{310,311,312}-django{50,master} +[tox:gh] +python = + 3.12 = py312 + 3.11 = py311 + 3.10 = py310 + 3.9 = py39 + 3.8 = py38 + 3.7 = py37 + [testenv] usedevelop = true extras = tests From 849530ecb27930031e6f707494b11642a7b35eda Mon Sep 17 00:00:00 2001 From: Davide Date: Fri, 6 Oct 2023 10:38:36 +0200 Subject: [PATCH 3/7] Update setup.cgg --- setup.cfg | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index cb19b92..205e632 100644 --- a/setup.cfg +++ b/setup.cfg @@ -67,7 +67,7 @@ envlist = py{38,39,310,311,312}-django{40,41,42} py{310,311,312}-django{50,master} -[tox:gh] +[gh] python = 3.12 = py312 3.11 = py311 @@ -78,10 +78,13 @@ python = [testenv] usedevelop = true -extras = tests whitelist_externals = py.test commands = py.test deps= + pytest + pytest-cov + pytest-django + django-guardian~=2.4.0 django32: Django>=3.2,<3.3 django32: Django>=3.2,<3.3 django40: Django>=4.0,<4.1 From ee7b1c12e07f2b4a0e6f2a4e04f8dbcf4b9382b9 Mon Sep 17 00:00:00 2001 From: Davide Date: Fri, 6 Oct 2023 11:20:06 +0200 Subject: [PATCH 4/7] Retry adding test extras --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 205e632..3bf5e39 100644 --- a/setup.cfg +++ b/setup.cfg @@ -78,6 +78,7 @@ python = [testenv] usedevelop = true +extras = tests whitelist_externals = py.test commands = py.test deps= From 8198c74d11322bc001506ef594f1b5955a7311e9 Mon Sep 17 00:00:00 2001 From: Davide Date: Fri, 6 Oct 2023 11:23:08 +0200 Subject: [PATCH 5/7] Add init to test package --- tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 From ecbfd47b602f250e6b61710dd937edd740010bb4 Mon Sep 17 00:00:00 2001 From: Davide Date: Fri, 6 Oct 2023 11:55:48 +0200 Subject: [PATCH 6/7] Fix tox configuration --- setup.cfg | 3 ++- tests/__init__.py | 0 tests/test_command.py | 27 ++++++++++++++++----------- tests/test_database.py | 9 +++++++-- tests/test_testing_utils.py | 19 ++++++++++++------- 5 files changed, 37 insertions(+), 21 deletions(-) delete mode 100644 tests/__init__.py diff --git a/setup.cfg b/setup.cfg index 3bf5e39..6c2d4ee 100644 --- a/setup.cfg +++ b/setup.cfg @@ -77,7 +77,8 @@ python = 3.7 = py37 [testenv] -usedevelop = true +change_dir = tests +package = editable-legacy extras = tests whitelist_externals = py.test commands = py.test diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_command.py b/tests/test_command.py index 4a03fc8..f2bfb23 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -1,4 +1,5 @@ from io import StringIO +from django import VERSION from django.contrib.auth.models import Group from django.core.management import call_command from django.test import TestCase @@ -6,6 +7,10 @@ class CommandTestCase(TestCase): + if VERSION < (4, 2): + def assertQuerySetEqual(self, *args, **kwargs): + return super().assertQuerysetEqual(*args, **kwargs) + @classmethod def setUpTestData(cls): group_maps = { @@ -42,7 +47,7 @@ def test_apply_every_role(self): ) self.assertEqual(Group.objects.all().count(), 7) group = Group.objects.get_by_natural_key("Users") - self.assertQuerysetEqual( + self.assertQuerySetEqual( group.permissions.all(), [ ("view_group", "auth", "group"), @@ -53,7 +58,7 @@ def test_apply_every_role(self): ordered=False, ) group = Group.objects.get_by_natural_key("User-Managers") - self.assertQuerysetEqual( + self.assertQuerySetEqual( group.permissions.all(), [ ("view_group", "auth", "group"), @@ -66,7 +71,7 @@ def test_apply_every_role(self): ordered=False, ) group = Group.objects.get_by_natural_key("Group Managers") - self.assertQuerysetEqual( + self.assertQuerySetEqual( group.permissions.all(), [ ("view_group", "auth", "group"), @@ -78,7 +83,7 @@ def test_apply_every_role(self): ordered=False, ) group = Group.objects.get_by_natural_key("Top-Managers") - self.assertQuerysetEqual( + self.assertQuerySetEqual( group.permissions.all(), [ ("view_user", "auth", "user"), @@ -118,7 +123,7 @@ def test_apply_every_role_clear(self): ) self.assertEqual(Group.objects.all().count(), 7) group = Group.objects.get_by_natural_key("Users") - self.assertQuerysetEqual( + self.assertQuerySetEqual( group.permissions.all(), [ ("view_group", "auth", "group"), @@ -128,7 +133,7 @@ def test_apply_every_role_clear(self): ordered=False, ) group = Group.objects.get_by_natural_key("User-Managers") - self.assertQuerysetEqual( + self.assertQuerySetEqual( group.permissions.all(), [ ("view_group", "auth", "group"), @@ -140,7 +145,7 @@ def test_apply_every_role_clear(self): ordered=False, ) group = Group.objects.get_by_natural_key("Group Managers") - self.assertQuerysetEqual( + self.assertQuerySetEqual( group.permissions.all(), [ ("view_group", "auth", "group"), @@ -152,7 +157,7 @@ def test_apply_every_role_clear(self): ordered=False, ) group = Group.objects.get_by_natural_key("Top-Managers") - self.assertQuerysetEqual( + self.assertQuerySetEqual( group.permissions.all(), [ ("view_user", "auth", "user"), @@ -182,7 +187,7 @@ def test_apply_single_role_clear(self): ) self.assertEqual(Group.objects.all().count(), 3) group = Group.objects.get_by_natural_key("Users") - self.assertQuerysetEqual( + self.assertQuerySetEqual( group.permissions.all(), [ ("view_group", "auth", "group"), @@ -193,7 +198,7 @@ def test_apply_single_role_clear(self): ) # user managers group was not modified group = Group.objects.get_by_natural_key("User-Managers") - self.assertQuerysetEqual( + self.assertQuerySetEqual( group.permissions.all(), [ ("view_user", "auth", "user"), @@ -222,7 +227,7 @@ def test_apply_single_role_fuzzy_dash(self): ], ) group = Group.objects.get_by_natural_key("Group Managers") - self.assertQuerysetEqual( + self.assertQuerySetEqual( group.permissions.all(), [ ("view_group", "auth", "group"), diff --git a/tests/test_database.py b/tests/test_database.py index a06bc5c..1eb9b9e 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -1,3 +1,4 @@ +from django import VERSION from django.contrib.auth.models import Group from django.test import TestCase from guardian.shortcuts import assign_perm @@ -5,6 +6,10 @@ class DatabaseSetupTestCase(TestCase): + if VERSION < (4, 2): + def assertQuerySetEqual(self, *args, **kwargs): + return super().assertQuerysetEqual(*args, **kwargs) + def test_create_role_group_if_not_exists(self): with self.assertRaises(Group.DoesNotExist): Group.objects.get_by_natural_key("Users") @@ -26,7 +31,7 @@ def test_group_permissions_assignment(self): self.assertFalse(role.group.permissions.all().exists()) assign_perm("auth.delete_user", role.group) role.setup_permissions() - self.assertQuerysetEqual( + self.assertQuerySetEqual( role.group.permissions.values_list("codename", flat=True), ["view_user", "view_group", "delete_user"], transform=str, @@ -39,7 +44,7 @@ def test_group_permissions_assignment_with_reset(self): self.assertFalse(role.group.permissions.all().exists()) assign_perm("auth.delete_user", role.group) role.setup_permissions(True) - self.assertQuerysetEqual( + self.assertQuerySetEqual( role.group.permissions.values_list("codename", flat=True), [ "view_user", diff --git a/tests/test_testing_utils.py b/tests/test_testing_utils.py index 0e61221..7659e57 100644 --- a/tests/test_testing_utils.py +++ b/tests/test_testing_utils.py @@ -1,9 +1,14 @@ +from django import VERSION from django.contrib.auth.models import Group from django.test import TestCase from django_group_role.test import RoleEnabledTestMixin class BaseTestingTestCase(RoleEnabledTestMixin, TestCase): + if VERSION < (4, 2): + def assertQuerySetEqual(self, *args, **kwargs): + return super().assertQuerysetEqual(*args, **kwargs) + clear_role_registry = True force_role_reload = True @@ -12,7 +17,7 @@ class OnlySelectedTestCase(BaseTestingTestCase): roles = ["Users", "User-Managers"] def test_roles(self): - self.assertQuerysetEqual( + self.assertQuerySetEqual( Group.objects.values_list("name", flat=True).order_by("name"), [ "User-Managers", @@ -21,7 +26,7 @@ def test_roles(self): transform=str, ) group = Group.objects.get_by_natural_key("Users") - self.assertQuerysetEqual( + self.assertQuerySetEqual( group.permissions.all(), [ ("view_group", "auth", "group"), @@ -31,7 +36,7 @@ def test_roles(self): ordered=False, ) group = Group.objects.get_by_natural_key("User-Managers") - self.assertQuerysetEqual( + self.assertQuerySetEqual( group.permissions.all(), [ ("view_group", "auth", "group"), @@ -48,7 +53,7 @@ class OverrideFromRolesTestCase(BaseTestingTestCase): roles_from = "example_project.roles_secondary" def test_roles(self): - self.assertQuerysetEqual( + self.assertQuerySetEqual( Group.objects.values_list("name", flat=True).order_by("name"), [ "Base", @@ -58,7 +63,7 @@ def test_roles(self): transform=str, ) group = Group.objects.get_by_natural_key("Base") - self.assertQuerysetEqual( + self.assertQuerySetEqual( group.permissions.all(), [ ("view_group", "auth", "group"), @@ -68,7 +73,7 @@ def test_roles(self): ordered=False, ) group = Group.objects.get_by_natural_key("Managers") - self.assertQuerysetEqual( + self.assertQuerySetEqual( group.permissions.all(), [ ("view_group", "auth", "group"), @@ -80,7 +85,7 @@ def test_roles(self): ordered=False, ) group = Group.objects.get_by_natural_key("Groupers") - self.assertQuerysetEqual( + self.assertQuerySetEqual( group.permissions.all(), [ ("view_group", "auth", "group"), From ce94cae1ec03e353f545fefa36e35a304885baf5 Mon Sep 17 00:00:00 2001 From: Davide Date: Fri, 6 Oct 2023 11:58:54 +0200 Subject: [PATCH 7/7] Update classifier for django 5.0 --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 6c2d4ee..7e8349e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,6 +22,7 @@ classifiers = Framework :: Django :: 4.0 Framework :: Django :: 4.1 Framework :: Django :: 4.2 + Framework :: Django :: 5.0 License :: OSI Approved :: Apache Software License Operating System :: OS Independent Intended Audience :: Developers