8000 Django 4.0 by webs86 · Pull Request #1698 · django-extensions/django-extensions · GitHub
[go: up one dir, main page]

Skip to content

Django 4.0 #1698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ jobs:
- pypy3
tox-django-version:
- "22"
- "30"
- "31"
- "32"
- "40"
# GH Actions don't support something like allow-failure ?
# - "master"
exclude:
- python-version: "3.6"
tox-django-version: "40"
- python-version: "3.7"
tox-django-version: "40"
- python-version: "pypy3"
tox-django-version: "40"
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- repo: git://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
sha: v0.9.1
hooks:
- id: trailing-whitespace
Expand All @@ -20,11 +20,11 @@
args:
- --django
exclude: ^tests/testapp|^tests/management/|^tests/collisions/|^tests/pythonrc.py|^tests/runner.py
- repo: git://github.com/Lucas-C/pre-commit-hooks.git
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
sha: v1.0.1
hooks:
- id: forbid-crlf
- repo: git://github.com/trbs/pre-commit-hooks-trbs.git
- repo: https://github.com/trbs/pre-commit-hooks-trbs.git
sha: e233916fb2b4b9019b4a3cc0497994c7926fe36b
hooks:
- id: forbid-executables
Expand Down
4 changes: 2 additions & 2 deletions django_extensions/management/commands/dumpscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
)
from django.db.models.deletion import Collector
from django.utils import timezone
from django.utils.encoding import force_str, smart_text
from django.utils.encoding import force_str, smart_str

from django_extensions.management.utils import signalcommand

Expand Down Expand Up @@ -205,7 +205,7 @@ def get_imports(self):
Return a dictionary of import statements, with the variable being
defined as the key.
"""
return {self.model.__name__: smart_text(self.model.__module__)}
return {self.model.__name__: smart_str(self.model.__module__)}
imports = property(get_imports)

def get_lines(self):
Expand Down
4 changes: 2 additions & 2 deletions django_extensions/management/commands/show_template_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.core.management import color
from django.core.management import BaseCommand
from django.utils import termcolors
from django.utils.encoding import smart_text
from django.utils.encoding import smart_str

from django_extensions.compat import load_tag_library
from django_extensions.management.color import _dummy_style_func
Expand Down Expand Up @@ -41,7 +41,7 @@ def format_block(block, nlspaces=0):
http://code.activestate.com/recipes/145672/
"""
# separate block into lines
lines = smart_text(block).split('\n')
lines = smart_str(block).split('\n')

# remove leading/trailing empty lines
while lines and not lines[0]:
Expand Down
70 changes: 53 additions & 17 deletions tests/management/commands/test_show_urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-
from io import StringIO

from django.conf.urls import url
from django.urls import path
from django.core.management import CommandError, call_command
from django.http import HttpResponse
from django.test import TestCase
from django.test.utils import override_settings
from django.views.generic.base import View
from django import VERSION

from unittest.mock import Mock, patch

Expand All @@ -20,9 +21,9 @@ class ClassView(View):


urlpatterns = [
url(r'lambda/view', lambda request: HttpResponse('OK')),
url(r'function/based/', function_based_view, name='function-based-view'),
url(r'class/based/', ClassView.as_view(), name='class-based-view'),
path('lambda/view', lambda request: HttpResponse('OK')),
path('function/based/', function_based_view, name='function-based-view'),
path('class/based/', ClassView.as_view(), name='class-based-view'),
]


Expand Down Expand Up @@ -57,44 +58,69 @@ def test_should_show_urls_unsorted_but_same_order_as_found_in_url_patterns(self,
lines = m_stdout.getvalue().splitlines()
self.assertIn('/lambda/view\ttests.management.commands.test_show_urls.<lambda>', lines[0])
self.assertIn('/function/based/\ttests.management.commands.test_show_urls.function_based_view\tfunction-based-view', lines[1])
self.assertIn('/class/based/\ttests.management.commands.test_show_urls.ClassView\tclass-based-view', lines[2])

if VERSION >= (4, 0):
self.assertIn('/class/based/\ttests.management.commands.test_show_urls.view\tclass-based-view', lines[2])
else:
self.assertIn('/class/based/\ttests.management.commands.test_show_urls.ClassView\tclass-based-view', lines[2])

@patch('sys.stdout', new_callable=StringIO)
def test_should_show_urls_sorted_alphabetically(self, m_stdout):
call_command('show_urls', verbosity=3)

lines = m_stdout.getvalue().splitlines()
self.assertEqual('/class/based/\ttests.management.commands.test_show_urls.ClassView\tclass-based-view', lines[0])

if VERSION >= (4, 0):
self.assertEqual('/class/based/\ttests.management.commands.test_show_urls.view\tclass-based-view', lines[0])
else:
self.assertEqual('/class/based/\ttests.management.commands.test_show_urls.ClassView\tclass-based-view', lines[0])

self.assertEqual('/function/based/\ttests.management.commands.test_show_urls.function_based_view\tfunction-based-view', lines[1])
self.assertEqual('/lambda/view\ttests.management.commands.test_show_urls.<lambda>', lines[2])

@patch('sys.stdout', new_callable=StringIO)
def test_should_show_urls_in_json_format(self, m_stdout):
call_command('show_urls', '--format=json')

self.assertJSONEqual(m_stdout.getvalue(), [
json = [
{"url": "/lambda/view", "module": "tests.management.commands.test_show_urls.<lambda>", "name": "", "decorators": ""},
{"url": "/function/based/", "module": "tests.management.commands.test_show_urls.function_based_view", "name": "function-based-view", "decorators": ""},
{"url": "/class/based/", "module": "tests.management.commands.test_show_urls.ClassView", "name": "class-based-view", "decorators": ""}
])
{"url": "/function/based/", "module": "tests.management.commands.test_show_urls.function_based_view", "name": "function-based-view", "decorators": ""}
]

if VERSION >= (4, 0):
json.append({"url": "/class/based/", "module": "tests.management.commands.test_show_urls.view", "name": "class-based-view", "decorators": ""})
else:
json.append({"url": "/class/based/", "module": "tests.management.commands.test_show_urls.ClassView", "name": "class-based-view", "decorators": ""})

self.assertJSONEqual(m_stdout.getvalue(), json)
self.assertEqual(len(m_stdout.getvalue().splitlines()), 1)

@patch('sys.stdout', new_callable=StringIO)
def test_should_show_urls_in_pretty_json_format(self, m_stdout):
call_command('show_urls', '--format=pretty-json')

self.assertJSONEqual(m_stdout.getvalue(), [
json = [
{"url": "/lambda/view", "module": "tests.management.commands.test_show_urls.<lambda>", "name": "", "decorators": ""},
{"url": "/function/based/", "module": "tests.management.commands.test_show_urls.function_based_view", "name": "function-based-view", "decorators": ""},
{"url A935 ": "/class/based/", "module": "tests.management.commands.test_show_urls.ClassView", "name": "class-based-view", "decorators": ""}
])
{"url": "/function/based/", "module": "tests.management.commands.test_show_urls.function_based_view", "name": "function-based-view", "decorators": ""}
]

if VERSION >= (4, 0):
json.append({"url": "/class/based/", "module": "tests.management.commands.test_show_urls.view", "name": "class-based-view", "decorators": ""})
else:
json.append({"url": "/class/based/", "module": "tests.management.commands.test_show_urls.ClassView", "name": "class-based-view", "decorators": ""})

self.assertJSONEqual(m_stdout.getvalue(), json)
self.assertEqual(len(m_stdout.getvalue().splitlines()), 20)

@patch('sys.stdout', new_callable=StringIO)
def test_should_show_urls_in_table_format(self, m_stdout):
call_command('show_urls', '--format=table')

self.assertIn('/class/based/ | tests.management.commands.test_show_urls.ClassView | class-based-view |', m_stdout.getvalue())
if VERSION >= (4, 0):
self.assertIn('/class/based/ | tests.management.commands.test_show_urls.view | class-based-view |', m_stdout.getvalue())
else:
self.assertIn('/class/based/ | tests.management.commands.test_show_urls.ClassView | class-based-view |', m_stdout.getvalue())

self.assertIn('/function/based/ | tests.management.commands.test_show_urls.function_based_view | function-based-view |', m_stdout.getvalue())
self.assertIn('/lambda/view | tests.management.commands.test_show_urls.<lambda> | |', m_stdout.getvalue())

Expand All @@ -103,7 +129,12 @@ def test_should_show_urls_in_aligned_format(self, m_stdout):
call_command('show_urls', '--format=aligned')

lines = m_stdout.getvalue().splitlines()
self.assertEqual('/class/based/ tests.management.commands.test_show_urls.ClassView class-based-view ', lines[0])

if VERSION >= (4, 0):
self.assertEqual('/class/based/ tests.management.commands.test_show_urls.view class-based-view ', lines[0])
else:
self.assertEqual('/class/based/ tests.management.commands.test_show_urls.ClassView class-based-view ', lines[0])

self.assertEqual('/function/based/ tests.management.commands.test_show_urls.function_based_view function-based-view ', lines[1])
self.assertEqual('/lambda/view tests.management.commands.test_show_urls.<lambda> ', lines[2])

Expand All @@ -112,6 +143,11 @@ def test_should_show_urls_with_no_color_option(self, m_stdout):
call_command('show_urls', '--no-color')

lines = m_stdout.getvalue().splitlines()
self.assertEqual('/class/based/\ttests.management.commands.test_show_urls.ClassView\tclass-based-view', lines[0])

if VERSION >= (4, 0):
self.assertEqual('/class/based/\ttests.management.commands.test_show_urls.view\tclass-based-view', lines[0])
else:
self.assertEqual('/class/based/\ttests.management.commands.test_show_urls.ClassView\tclass-based-view', lines[0])

self.assertEqual('/function/based/\ttests.management.commands.test_show_urls.function_based_view\tfunction-based-view', lines[1])
self.assertEqual('/lambda/view\ttests.management.commands.test_show_urls.<lambda>', lines[2])
8 changes: 4 additions & 4 deletions tests/testapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.urls import path
from django.contrib import admin
from django.contrib.auth import views as auth_views

login_view = auth_views.LoginView.as_view() if hasattr(auth_views, 'LoginView') else auth_views.login
logout_view = auth_views.LogoutView.as_view() if hasattr(auth_views, 'LogoutView') else auth_views.logout

urlpatterns = [
url(r'^login/$', login_view, {'template_name': 'login.html'}, name="login"),
url(r'^logout/$', logout_view, name="logout"),
url(r'^admin/', admin.site.urls),
path('login/', login_view, {'template_name': 'login.html'}, name="login"),
path('logout/', logout_view, name="logout"),
path('admin/', admin.site.urls),
]
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ envlist =
mypy
{py37,py38,py39,py310}-flake8
{py36,py37,py38,py39,py310,pypy}-dj22
{py36,py37,py38,py39,py310,pypy}-dj30
{py36,py37,py38,py39,py310,pypy}-dj31
{py36,py37,py38,py39,py310,pypy}-dj32
{py38,py39,py310,pypy}-dj40
{py38,py39,py310,pypy}-djmaster
py310-dj32-postgres
py310-dj40-postgres
py310-dj32-mysql
py310-dj40-mysql
py310-djmaster-postgres

[testenv]
Expand All @@ -39,9 +40,8 @@ deps =
pip >= 21.1
-rrequirements-dev.txt
dj22: Django==2.2
dj30: Django>=3.0,<3.1
dj31: Django>=3.1,<3.2
dj32: Django>=3.2,<4.0
dj40: Django>=4.0,<4.1
djmaster: https://github.com/django/django/archive/refs/heads/main.zip
postgres: psycopg2-binary
mysql: mysqlclient
Expand Down
0