Skip to content

Commit

Permalink
Merge commit 'refs/pull/78/head' of https://github.com/farhan0581/dja…
Browse files Browse the repository at this point in the history
  • Loading branch information
meocong committed Mar 6, 2024
2 parents 4ec6612 + 91ce835 commit 7b8f14d
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 4 deletions.
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='URL moved in 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.
"""
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='URL moved in Django 3.2')
def test_admin_autocomplete_load_32_plus(self):
"""
Test that the admin autocomplete endpoint loads on Django >= 3.2.
"""
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'

0 comments on commit 7b8f14d

Please sign in to comment.