Skip to content

Commit

Permalink
Test against django 5.0a and python 3.12 (#10)
Browse files Browse the repository at this point in the history
* Test against django 5.0a and python 3.12

* Try tox-gh

* Update setup.cgg

* Retry adding test extras

* Add init to test package

* Fix tox configuration

* Update classifier for django 5.0
  • Loading branch information
sevdog authored Oct 6, 2023
1 parent 3c62244 commit 1f34115
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 31 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Linters/Tests

on: pull_request

concurrency:
group: check-${{ github.ref }}
cancel-in-progress: true

jobs:

tests:
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand All @@ -21,5 +25,5 @@
"python.testing.pytestArgs": [
"--reuse-db"
],
"python.formatting.provider": "black"
"black-formatter.importStrategy": "fromEnvironment",
}
23 changes: 20 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
27 changes: 16 additions & 11 deletions tests/test_command.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
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
from guardian.shortcuts import assign_perm


class CommandTestCase(TestCase):
if VERSION < (4, 2):
def assertQuerySetEqual(self, *args, **kwargs):
return super().assertQuerysetEqual(*args, **kwargs)

@classmethod
def setUpTestData(cls):
group_maps = {
Expand Down Expand Up @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down
9 changes: 7 additions & 2 deletions tests/test_database.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from django import VERSION
from django.contrib.auth.models import Group
from django.test import TestCase
from guardian.shortcuts import assign_perm
from example_project.roles import BasicRole


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")
Expand All @@ -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,
Expand All @@ -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",
Expand Down
19 changes: 12 additions & 7 deletions tests/test_testing_utils.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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",
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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",
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down

0 comments on commit 1f34115

Please sign in to comment.