Drop django 1.10 or lower and Django 1.11 or higher support.

This commit is contained in:
Chihiro Kaneko 2018-09-21 18:44:47 +09:00 committed by hirokinko
parent ec49e08b64
commit 944f2b51ee
5 changed files with 31 additions and 60 deletions

View file

@ -32,12 +32,8 @@ else:
u = str
if VERSION < (1, 9):
def get_field(model, name):
return model._meta.get_field_by_name(name)[0]
else:
def get_field(model, name):
return model._meta.get_field(name)
def get_field(model, name):
return model._meta.get_field(name)
class MultiSelectTestCase(TestCase):
@ -77,12 +73,8 @@ class MultiSelectTestCase(TestCase):
# call Field.from_db_field, it simply returns a Python representation
# of the data in the database (which in our case is a string of
# comma-separated values). The bug was fixed in Django 1.8+.
if VERSION >= (1, 6) and VERSION < (1, 8):
self.assertStringEqual(tag_list_list, [u('sex,work,happy')])
self.assertStringEqual(categories_list_list, [u('1,3,5')])
else:
self.assertListEqual(tag_list_list, [['sex', 'work', 'happy']])
self.assertListEqual(categories_list_list, [['1', '3', '5']])
self.assertListEqual(tag_list_list, [['sex', 'work', 'happy']])
self.assertListEqual(categories_list_list, [['1', '3', '5']])
def test_form(self):
form_class = modelform_factory(Book, fields=('title', 'tags', 'categories'))
@ -139,7 +131,7 @@ class MultiSelectTestCase(TestCase):
self.assertEqual(len(form_class.base_fields), 1)
form = form_class(initial={'published_in': ['BC', 'AK']})
expected_html = u("""<p><label for="id_published_in_0">Province or State:</label> <ul id="id_published_in"><li>Canada - Provinces<ul id="id_published_in_0"><li><label for="id_published_in_0_0"><input id="id_published_in_0_0" name="published_in" type="checkbox" value="AB" /> Alberta</label></li>\n"""
expected_html = u("""<p><label>Province or State:</label> <ul id="id_published_in"><li>Canada - Provinces<ul id="id_published_in_0"><li><label for="id_published_in_0_0"><input id="id_published_in_0_0" name="published_in" type="checkbox" value="AB" /> Alberta</label></li>\n"""
"""<li><label for="id_published_in_0_1"><input checked="checked" id="id_published_in_0_1" name="published_in" type="checkbox" value="BC" /> British Columbia</label></li></ul></li>\n"""
"""<li>USA - States<ul id="id_published_in_1"><li><label for="id_published_in_1_0"><input checked="checked" id="id_published_in_1_0" name="published_in" type="checkbox" value="AK" /> Alaska</label></li>\n"""
"""<li><label for="id_published_in_1_1"><input id="id_published_in_1_1" name="published_in" type="checkbox" value="AL" /> Alabama</label></li>\n"""
@ -147,18 +139,10 @@ class MultiSelectTestCase(TestCase):
actual_html = form.as_p()
if (1, 11) <= VERSION < (2, 0):
# Django 1.11+ does not assign 'for' attributes on labels if they
# are group labels
expected_html = expected_html.replace('label for="id_published_in_0"', 'label')
if VERSION >= (2, 0):
expected_html = expected_html.replace('input checked="checked"', 'input checked')
if VERSION < (1, 6):
# Django 1.6 renders the Python repr() for each group (eg: tuples
# with HTML entities), so we skip the test for that version
self.assertEqual(expected_html.replace('\n', ''), actual_html.replace('\n', ''))
if VERSION >= (1, 7):
self.assertHTMLEqual(expected_html, actual_html)
self.assertHTMLEqual(expected_html, actual_html)
class MultiSelectUtilsTestCase(TestCase):

View file

@ -19,7 +19,7 @@ from django.conf import settings
from django.contrib.auth import login
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.http import HttpResponseRedirect