Skip to content

Commit 0b8da05

Browse files
committed
Support django 3.2 & 4.0, use gha. Fixes #195, #200, #207
1 parent 6e1ba35 commit 0b8da05

File tree

13 files changed

+244
-137
lines changed

13 files changed

+244
-137
lines changed

.github/workflows/test.yml

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
name: Test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
python-version: ["3.7", "3.8", "3.9", "3.10"]
11+
django-version: ["2.2", "3.2", "4.0"]
12+
grappelli: ["0"]
13+
exclude:
14+
- python-version: "3.7"
15+
django-version: "4.0"
16+
- python-version: "3.10"
17+
django-version: "2.2"
18+
# Exclude some version combos that don't need to be tested (since
19+
# the combination of python and django versions is unlikely to
20+
# be germane to django-nested-admin)
21+
- python-version: "3.8"
22+
django-version: "3.2"
23+
- python-version: "3.9"
24+
django-version: "4.0"
25+
include:
26+
- grappelli: "0"
27+
name-suffix: ""
28+
- grappelli: "1"
29+
name-suffix: " + grappelli"
30+
python-version: "3.7"
31+
django-version: "2.2"
32+
- grappelli: "1"
33+
name-suffix: " + grappelli"
34+
python-version: "3.10"
35+
django-version: "3.2"
36+
37+
runs-on: ubuntu-latest
38+
name: Django ${{ matrix.django-version }} (Python ${{ matrix.python-version }})${{ matrix.name-suffix }}
39+
40+
env:
41+
DJANGO: ${{ matrix.django-version }}
42+
GRAPPELLI: ${{ matrix.grappelli }}
43+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
44+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
45+
NODE_ENV: test
46+
47+
steps:
48+
- uses: actions/checkout@v2
49+
50+
- name: Set up Python ${{ matrix.python-version }}
51+
uses: actions/setup-python@v2
52+
with:
53+
python-version: ${{ matrix.python-version }}
54+
55+
- name: Setup chromedriver
56+
uses: nanasess/setup-chromedriver@v1.0.5
57+
58+
- name: Install tox
59+
run: |
60+
python3 -m pip install tox tox-gh-actions
61+
62+
- name: Cache instrumented static files
63+
id: cache-test-dist
64+
uses: actions/cache@v2
65+
with:
66+
path: nested_admin/tests/static
67+
key: test-dist-${{ hashFiles('package-lock.json', '.github/workflows/test.yml', 'webpack.config.js', 'package.json', '.*rc*', 'frontend/**') }}
68+
69+
- name: Cache node_modules
70+
id: cache-node_modules
71+
uses: actions/cache@v2
72+
with:
73+
path: node_modules
74+
key: node_modules-${{ hashFiles('package-lock.json') }}
75+
76+
- name: Setup nodejs 12
77+
if: steps.cache-test-dist.outputs.cache-hit != 'true' || steps.cache-node_modules.outputs.cache-hit != 'true'
78+
uses: actions/setup-node@v2
79+
with:
80+
node-version: '12'
81+
82+
- name: npm ci
83+
if: steps.cache-test-dist.outputs.cache-hit != 'true' || steps.cache-node_modules.outputs.cache-hit != 'true'
84+
run: |
85+
npm ci || npm ci || npm ci
86+
87+
- name: Build instrumented static files
88+
if: steps.cache-test-dist.outputs.cache-hit != 'true' || steps.cache-node_modules.outputs.cache-hit != 'true'
89+
run: |
90+
npm run build
91+
92+
- name: Run tests
93+
run: |
94+
tox -- -vvv --selenosis-driver=chrome-headless --numprocesses=4 --exitfirst || \
95+
tox -- -vvv --selenosis-driver=chrome-headless
96+
env:
97+
PIXELMATCH_BIN: ${{ env.GITHUB_WORKSPACE }}/node_modules/.bin/pixelmatch
98+
99+
- name: Upload junit xml
100+
if: always()
101+
uses: actions/upload-artifact@v2
102+
with:
103+
name: junit-reports
104+
path: reports/*.xml
105+
106+
- name: Upload python coverage
107+
run: |
108+
tox -e coverage-report
109+
tox -e codecov
110+
env:
111+
CODECOV_NAME: ${{ github.workflow }}
112+
113+
- name: Upload js coverage
114+
run: npm run report && npm run codecov
115+
env:
116+
CODECOV_NAME: ${{ github.workflow }}
117+
118+
report:
119+
if: always()
120+
needs: build
121+
runs-on: ubuntu-latest
122+
name: "Report Test Results"
123+
steps:
124+
- uses: actions/download-artifact@v2
125+
with:
126+
name: junit-reports
127+
128+
- name: Publish tests report
129+
uses: mikepenz/action-junit-report@5703ba1461f35871cde0208140d737d3e1eef38f
130+
with:
131+
report_paths: ./*.xml
132+
github_token: ${{ secrets.GITHUB_TOKEN }}
133+
require_tests: true
134+
fail_on_failure: true
135+
check_name: Test Report
136+
137+
success:
138+
needs: report
139+
runs-on: ubuntu-latest
140+
name: Test Successful
141+
steps:
142+
- name: Success
143+
run: echo Test Successful

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ node_modules
1717
/.nyc_output
1818
/coverage/
1919
/nested_admin/tests/static
20+
.coverage
21+
/reports/*.xml

.travis.yml

Lines changed: 0 additions & 61 deletions
This file was deleted.

nested_admin/nested.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ def _djn_js_deps(self):
4747
Returns a set of js files that, if present, ought to precede
4848
nested_admin.js in the media load order
4949
"""
50-
extra = '' if settings.DEBUG else '.min'
51-
5250
return {
5351
'admin/js/core.js',
54-
'admin/js/vendor/jquery/jquery%s.js' % extra,
52+
'admin/js/vendor/jquery/jquery.js',
53+
'admin/js/vendor/jquery/jquery.min.js',
5554
'admin/js/jquery.init.js',
56-
'admin/js/prepopulate%s.js' % extra,
55+
'admin/js/prepopulate.js',
56+
'admin/js/prepopulate.min.js',
5757
'admin/js/SelectFilter2.js',
5858
'admin/js/autocomplete.js',
5959
'jquery.grp.autocomplete_fk.js',

nested_admin/polymorphic.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import absolute_import
22
import json
3+
import six
34

45
from django.conf import settings
5-
from django.utils.encoding import force_text
66
from polymorphic.formsets import (
77
BasePolymorphicInlineFormSet, BaseGenericPolymorphicInlineFormSet)
88
from polymorphic.models import PolymorphicModelBase, PolymorphicModel
@@ -16,6 +16,11 @@
1616
NestedInlineModelAdminMixin, NestedGenericInlineModelAdminMixin,
1717
NestedInlineAdminFormsetMixin, NestedInlineAdminFormset)
1818

19+
if six.PY2:
20+
from django.utils.encoding import force_text as force_str
21+
else:
22+
from django.utils.encoding import force_str
23+
1924

2025
def get_base_polymorphic_models(child_model):
2126
models = []
@@ -88,7 +93,7 @@ def inline_formset_data(self):
8893
'childTypes': [
8994
{
9095
'type': get_model_id(model),
91-
'name': force_text(model._meta.verbose_name),
96+
'name': force_str(model._meta.verbose_name),
9297
} for model in self.formset.child_forms.keys()
9398
],
9499
})

nested_admin/tests/conftest.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ def suppress_warnings():
1414
"ignore",
1515
"name used for saved screenshot does not match file type",
1616
UserWarning)
17-
# These deprecation warnings were thrown in django-polymorphic as of 2.1.2
18-
warnings.filterwarnings("ignore", "django.utils.translation.ugettext", Warning)
19-
warnings.filterwarnings("ignore", "force_text", Warning)
17+
warnings.filterwarnings("ignore", "'grappelli' defines default_app_config")
18+
warnings.filterwarnings("ignore", 'The distutils package')

nested_admin/tests/fixtures/admin-widgets.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
</object>
99
<object pk="1" model="admin_widgets.widgetsrelated2">
1010
<field type="CharField" name="name">Kangaroo</field>
11-
<field type="DateTimeField" name="date_created">2019-01-01T00:00:00</field>
11+
<field type="DateTimeField" name="date_created">2019-01-01T00:00:00Z</field>
1212
</object>
1313
<object pk="2" model="admin_widgets.widgetsrelated2">
1414
<field type="CharField" name="name">Llama</field>
15-
<field type="DateTimeField" name="date_created">2019-01-01T00:00:00</field>
15+
<field type="DateTimeField" name="date_created">2019-01-01T00:00:00Z</field>
1616
</object>
1717
<object pk="1" model="admin_widgets.widgetsm2m">
1818
<field type="CharField" name="name">Xylophone</field>

nested_admin/tests/nested_polymorphic/base.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,11 @@
88

99
from nested_admin.tests.base import BaseNestedAdminTestCase
1010
from nested_admin.tests.utils import xpath_item, xpath_cls, is_sequence, is_integer, is_str
11-
12-
try:
13-
from polymorphic.models import PolymorphicModel
14-
except:
15-
# Temporary until django-polymorphic supports django 3.1
16-
if django.VERSION < (3, 1):
17-
raise
18-
else:
19-
class PolymorphicModel(object):
20-
pass
11+
from polymorphic.models import PolymorphicModel
2112

2213

2314
class BaseNestedPolymorphicTestCase(BaseNestedAdminTestCase):
2415

25-
@classmethod
26-
def setUpClass(cls):
27-
if django.VERSION >= (3, 1):
28-
raise SkipTest(
29-
'django-polymorphic not yet compatible with Django 3.1')
30-
super(BaseNestedPolymorphicTestCase, cls).setUpClass()
31-
3216
def get_inline_model_names(self):
3317
return self.selenium.execute_script("""
3418
return (function getGroup($group) {

nested_admin/tests/settings.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import os
33
import tempfile
44

5-
import django
6-
75
import selenosis.settings
86
import dj_database_url
97

@@ -20,12 +18,11 @@
2018

2119
SECRET_KEY = 'z-i*xqqn)r0i7leak^#clq6y5j8&tfslp^a4duaywj2$**s*0_'
2220

23-
if django.VERSION > (2, 0):
24-
MIGRATION_MODULES = {
25-
'auth': None,
26-
'contenttypes': None,
27-
'sessions': None,
28-
}
21+
MIGRATION_MODULES = {
22+
'auth': None,
23+
'contenttypes': None,
24+
'sessions': None,
25+
}
2926

3027
try:
3128
import grappelli # noqa
@@ -34,16 +31,6 @@
3431
else:
3532
INSTALLED_APPS = tuple(['grappelli'])
3633

37-
polymorphic = None
38-
39-
if django.VERSION < (3, 1):
40-
try:
41-
import polymorphic
42-
except ImportError:
43-
pass
44-
else:
45-
INSTALLED_APPS += ('polymorphic',)
46-
4734
TEMPLATES = [{
4835
'BACKEND': 'django.template.backends.django.DjangoTemplates',
4936
'DIRS': selenosis.settings.TEMPLATES[0]['DIRS'],
@@ -65,6 +52,7 @@
6552
}]
6653

6754
INSTALLED_APPS += (
55+
'polymorphic',
6856
'selenosis',
6957
'nested_admin.tests',
7058
'nested_admin',
@@ -83,10 +71,9 @@
8371
os.path.basename(os.path.dirname(p))])
8472

8573

86-
if polymorphic is not None:
87-
for p in glob.glob(os.path.join(current_dir, 'nested_polymorphic/*/models.py')):
88-
INSTALLED_APPS += tuple(["nested_admin.tests.nested_polymorphic.%s" %
89-
os.path.basename(os.path.dirname(p))])
74+
for p in glob.glob(os.path.join(current_dir, 'nested_polymorphic/*/models.py')):
75+
INSTALLED_APPS += tuple(["nested_admin.tests.nested_polymorphic.%s" %
76+
os.path.basename(os.path.dirname(p))])
9077

9178

9279
MIDDLEWARE = [
@@ -121,6 +108,7 @@
121108
MEDIA_URL = '/media/'
122109
STATIC_URL = '/static/'
123110
DEBUG_PROPAGATE_EXCEPTIONS = True
111+
USE_TZ = True
124112
TEST_RUNNER = 'selenosis.DiscoverRunner'
125113

126114
AWS_S3_REGION_NAME = "us-east-1"

0 commit comments

Comments
 (0)