Skip to content
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

Add support for Django 3.2 #78

Open
wants to merge 6 commits into
base: pre_release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
60 changes: 60 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Tests

on:
push:
pull_request:

jobs:
test:
strategy:
fail-fast: false
matrix:
versions:
- python: "3.6"
django: "2.0"
- python: "3.6"
django: "2.1"
- python: "3.6"
django: "2.2"
- python: "3.6"
django: "3.1"
- python: "3.6"
django: "3.2"

- python: "3.7"
django: "2.0"
- python: "3.7"
django: "2.1"
- python: "3.7"
django: "2.2"
- python: "3.7"
django: "3.1"
- python: "3.7"
django: "3.2"

- python: "3.8"
django: "2.2"
- python: "3.8"
django: "3.1"
- python: "3.8"
django: "3.2"

- python: "3.9"
django: "2.2"
- python: "3.9"
django: "3.1"
- python: "3.9"
django: "3.2"

name: "Python ${{ matrix.versions.python }} - Django ${{ matrix.versions.django }}"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.versions.python }}
- name: Install Dependencies
run: pip install "Django~=${{ matrix.versions.django }}.0"
- name: Run Tests
run: ./tests_manage.py test tests
2 changes: 2 additions & 0 deletions admin_auto_filters/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
class AutocompleteJsonView(Base):
"""Overriding django admin's AutocompleteJsonView"""

model_admin = None

@staticmethod
def display_text(obj):
"""
Expand Down
11 changes: 9 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@
],
classifiers=[
'Framework :: Django',
'Framework :: Django :: 2.0', # replace "X.Y" as appropriate
'Framework :: Django :: 2.0',
'Framework :: Django :: 2.1',
'Framework :: Django :: 2.2',
'Framework :: Django :: 3.0',
'Framework :: Django :: 3.1',
'Framework :: Django :: 3.2',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Software Development :: Libraries :: Python Modules',
],
Expand Down
36 changes: 34 additions & 2 deletions tests/testapp/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""Define tests for the test app."""

import json
import unittest
from urllib.parse import urlencode

import django
from django.contrib.admin.utils import flatten
from django.contrib.auth.models import User
from django.core import exceptions
Expand Down Expand Up @@ -81,16 +85,44 @@ def test_admin_changelist_search(self):
html=False, msg_prefix=str(url)
)

def test_admin_autocomplete_load(self):
@unittest.skipIf(django.VERSION >= (3, 2), reason='Autocomplete URL for Django < 3.2')
def test_admin_autocomplete_load_pre_32(self):
"""
Test that the admin autocomplete endpoint loads.
Test that the admin autocomplete endpoint loads on Django 3.2 and before.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these docstrings have been switched

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have they? This test is skipped if Django >= 3.2, so that's for 3.1 and earlier... Let me know if I'm missing something!

This docstring is still wrong, this test doesn't actually include 3.2, it should be <3.2 not <=3.2 🤦🏻

I'll update the reason in the skipIf decorator as it's a bit redundant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blep, it was me reading it wrong (skip if, not run if!)

"""
for model_name in MODEL_NAMES:
with self.subTest(model_name=model_name):
url = reverse('admin:testapp_%s_autocomplete' % model_name)
response = self.client.get(url, follow=False)
self.assertContains(response, '"results"')

@unittest.skipIf(django.VERSION < (3, 2), reason='Autocomplete URL for Django >= 3.2')
def test_admin_autocomplete_load_32_plus(self):
"""
Test that the admin autocomplete endpoint loads on Django 3.2 or later.
"""
model_field_name = [
# (Food, 'person'),
(Collection, 'curators'),
(Person, 'best_friend'),
(Person, 'twin'),
(Person, 'siblings'),
(Person, 'favorite_food'),
(Book, 'author'),
(Book, 'coll'),
]
for model, field_name in model_field_name:
with self.subTest(model_name=model.__name__, field_name=field_name):
url = reverse('admin:autocomplete')
query_params = {
'app_label': model._meta.app_label,
'model_name': model._meta.model_name,
'field_name': field_name,
}
url = url + '?' + urlencode(query_params)
response = self.client.get(url, follow=False)
self.assertContains(response, '"results"')

def test_admin_changelist_filters(self):
"""
Test that the admin changelist page loads with filters applied, at a basic level.
Expand Down
2 changes: 2 additions & 0 deletions tests/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "tests", "static"),
]

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'