diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a1fa512..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: @@ -10,7 +14,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 @@ -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/.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..7e8349e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,11 +16,13 @@ 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 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 @@ -63,18 +65,33 @@ 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} + +[gh] +python = + 3.12 = py312 + 3.11 = py311 + 3.10 = py310 + 3.9 = py39 + 3.8 = py38 + 3.7 = py37 [testenv] -usedevelop = true +change_dir = tests +package = editable-legacy 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 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 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"),