Removed unneeded force_text calls in the test suite
This commit is contained in:
parent
5b95d421f7
commit
2366100872
|
@ -11,7 +11,6 @@ from django.contrib.auth.admin import UserAdmin
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.test import RequestFactory, TestCase, override_settings
|
from django.test import RequestFactory, TestCase, override_settings
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
from .models import Book, Bookmark, Department, Employee, TaggedItem
|
from .models import Book, Bookmark, Department, Employee, TaggedItem
|
||||||
|
|
||||||
|
@ -332,7 +331,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][4]
|
filterspec = changelist.get_filters(request)[0][4]
|
||||||
self.assertEqual(force_text(filterspec.title), 'date registered')
|
self.assertEqual(filterspec.title, 'date registered')
|
||||||
choice = select_by(filterspec.choices(changelist), "display", "Today")
|
choice = select_by(filterspec.choices(changelist), "display", "Today")
|
||||||
self.assertIs(choice['selected'], True)
|
self.assertIs(choice['selected'], True)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -357,7 +356,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][4]
|
filterspec = changelist.get_filters(request)[0][4]
|
||||||
self.assertEqual(force_text(filterspec.title), 'date registered')
|
self.assertEqual(filterspec.title, 'date registered')
|
||||||
choice = select_by(filterspec.choices(changelist), "display", "This month")
|
choice = select_by(filterspec.choices(changelist), "display", "This month")
|
||||||
self.assertIs(choice['selected'], True)
|
self.assertIs(choice['selected'], True)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -382,7 +381,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][4]
|
filterspec = changelist.get_filters(request)[0][4]
|
||||||
self.assertEqual(force_text(filterspec.title), 'date registered')
|
self.assertEqual(filterspec.title, 'date registered')
|
||||||
choice = select_by(filterspec.choices(changelist), "display", "This year")
|
choice = select_by(filterspec.choices(changelist), "display", "This year")
|
||||||
self.assertIs(choice['selected'], True)
|
self.assertIs(choice['selected'], True)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -405,7 +404,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][4]
|
filterspec = changelist.get_filters(request)[0][4]
|
||||||
self.assertEqual(force_text(filterspec.title), 'date registered')
|
self.assertEqual(filterspec.title, 'date registered')
|
||||||
choice = select_by(filterspec.choices(changelist), "display", "Past 7 days")
|
choice = select_by(filterspec.choices(changelist), "display", "Past 7 days")
|
||||||
self.assertIs(choice['selected'], True)
|
self.assertIs(choice['selected'], True)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -427,7 +426,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][4]
|
filterspec = changelist.get_filters(request)[0][4]
|
||||||
self.assertEqual(force_text(filterspec.title), 'date registered')
|
self.assertEqual(filterspec.title, 'date registered')
|
||||||
choice = select_by(filterspec.choices(changelist), 'display', 'No date')
|
choice = select_by(filterspec.choices(changelist), 'display', 'No date')
|
||||||
self.assertIs(choice['selected'], True)
|
self.assertIs(choice['selected'], True)
|
||||||
self.assertEqual(choice['query_string'], '?date_registered__isnull=True')
|
self.assertEqual(choice['query_string'], '?date_registered__isnull=True')
|
||||||
|
@ -442,7 +441,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][4]
|
filterspec = changelist.get_filters(request)[0][4]
|
||||||
self.assertEqual(force_text(filterspec.title), 'date registered')
|
self.assertEqual(filterspec.title, 'date registered')
|
||||||
choice = select_by(filterspec.choices(changelist), 'display', 'Has date')
|
choice = select_by(filterspec.choices(changelist), 'display', 'Has date')
|
||||||
self.assertIs(choice['selected'], True)
|
self.assertIs(choice['selected'], True)
|
||||||
self.assertEqual(choice['query_string'], '?date_registered__isnull=False')
|
self.assertEqual(choice['query_string'], '?date_registered__isnull=False')
|
||||||
|
@ -469,7 +468,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the last choice is None and is selected
|
# Make sure the last choice is None and is selected
|
||||||
filterspec = changelist.get_filters(request)[0][0]
|
filterspec = changelist.get_filters(request)[0][0]
|
||||||
self.assertEqual(force_text(filterspec.title), 'year')
|
self.assertEqual(filterspec.title, 'year')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertIs(choices[-1]['selected'], True)
|
self.assertIs(choices[-1]['selected'], True)
|
||||||
self.assertEqual(choices[-1]['query_string'], '?year__isnull=True')
|
self.assertEqual(choices[-1]['query_string'], '?year__isnull=True')
|
||||||
|
@ -479,7 +478,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][0]
|
filterspec = changelist.get_filters(request)[0][0]
|
||||||
self.assertEqual(force_text(filterspec.title), 'year')
|
self.assertEqual(filterspec.title, 'year')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertIs(choices[2]['selected'], True)
|
self.assertIs(choices[2]['selected'], True)
|
||||||
self.assertEqual(choices[2]['query_string'], '?year=2002')
|
self.assertEqual(choices[2]['query_string'], '?year=2002')
|
||||||
|
@ -520,7 +519,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the last choice is None and is selected
|
# Make sure the last choice is None and is selected
|
||||||
filterspec = changelist.get_filters(request)[0][1]
|
filterspec = changelist.get_filters(request)[0][1]
|
||||||
self.assertEqual(force_text(filterspec.title), 'Verbose Author')
|
self.assertEqual(filterspec.title, 'Verbose Author')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertIs(choices[-1]['selected'], True)
|
self.assertIs(choices[-1]['selected'], True)
|
||||||
self.assertEqual(choices[-1]['query_string'], '?author__isnull=True')
|
self.assertEqual(choices[-1]['query_string'], '?author__isnull=True')
|
||||||
|
@ -530,7 +529,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][1]
|
filterspec = changelist.get_filters(request)[0][1]
|
||||||
self.assertEqual(force_text(filterspec.title), 'Verbose Author')
|
self.assertEqual(filterspec.title, 'Verbose Author')
|
||||||
# order of choices depends on User model, which has no order
|
# order of choices depends on User model, which has no order
|
||||||
choice = select_by(filterspec.choices(changelist), "display", "alfred")
|
choice = select_by(filterspec.choices(changelist), "display", "alfred")
|
||||||
self.assertIs(choice['selected'], True)
|
self.assertIs(choice['selected'], True)
|
||||||
|
@ -556,7 +555,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the last choice is None and is selected
|
# Make sure the last choice is None and is selected
|
||||||
filterspec = changelist.get_filters(request)[0][2]
|
filterspec = changelist.get_filters(request)[0][2]
|
||||||
self.assertEqual(force_text(filterspec.title), 'Verbose Contributors')
|
self.assertEqual(filterspec.title, 'Verbose Contributors')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertIs(choices[-1]['selected'], True)
|
self.assertIs(choices[-1]['selected'], True)
|
||||||
self.assertEqual(choices[-1]['query_string'], '?contributors__isnull=True')
|
self.assertEqual(choices[-1]['query_string'], '?contributors__isnull=True')
|
||||||
|
@ -566,7 +565,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][2]
|
filterspec = changelist.get_filters(request)[0][2]
|
||||||
self.assertEqual(force_text(filterspec.title), 'Verbose Contributors')
|
self.assertEqual(filterspec.title, 'Verbose Contributors')
|
||||||
choice = select_by(filterspec.choices(changelist), "display", "bob")
|
choice = select_by(filterspec.choices(changelist), "display", "bob")
|
||||||
self.assertIs(choice['selected'], True)
|
self.assertIs(choice['selected'], True)
|
||||||
self.assertEqual(choice['query_string'], '?contributors__id__exact=%d' % self.bob.pk)
|
self.assertEqual(choice['query_string'], '?contributors__id__exact=%d' % self.bob.pk)
|
||||||
|
@ -584,7 +583,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the last choice is None and is selected
|
# Make sure the last choice is None and is selected
|
||||||
filterspec = changelist.get_filters(request)[0][0]
|
filterspec = changelist.get_filters(request)[0][0]
|
||||||
self.assertEqual(force_text(filterspec.title), 'book')
|
self.assertEqual(filterspec.title, 'book')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertIs(choices[-1]['selected'], True)
|
self.assertIs(choices[-1]['selected'], True)
|
||||||
self.assertEqual(choices[-1]['query_string'], '?books_authored__isnull=True')
|
self.assertEqual(choices[-1]['query_string'], '?books_authored__isnull=True')
|
||||||
|
@ -594,7 +593,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][0]
|
filterspec = changelist.get_filters(request)[0][0]
|
||||||
self.assertEqual(force_text(filterspec.title), 'book')
|
self.assertEqual(filterspec.title, 'book')
|
||||||
choice = select_by(filterspec.choices(changelist), "display", self.bio_book.title)
|
choice = select_by(filterspec.choices(changelist), "display", self.bio_book.title)
|
||||||
self.assertIs(choice['selected'], True)
|
self.assertIs(choice['selected'], True)
|
||||||
self.assertEqual(choice['query_string'], '?books_authored__id__exact=%d' % self.bio_book.pk)
|
self.assertEqual(choice['query_string'], '?books_authored__id__exact=%d' % self.bio_book.pk)
|
||||||
|
@ -609,7 +608,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the last choice is None and is selected
|
# Make sure the last choice is None and is selected
|
||||||
filterspec = changelist.get_filters(request)[0][1]
|
filterspec = changelist.get_filters(request)[0][1]
|
||||||
self.assertEqual(force_text(filterspec.title), 'book')
|
self.assertEqual(filterspec.title, 'book')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertIs(choices[-1]['selected'], True)
|
self.assertIs(choices[-1]['selected'], True)
|
||||||
self.assertEqual(choices[-1]['query_string'], '?books_contributed__isnull=True')
|
self.assertEqual(choices[-1]['query_string'], '?books_contributed__isnull=True')
|
||||||
|
@ -619,7 +618,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][1]
|
filterspec = changelist.get_filters(request)[0][1]
|
||||||
self.assertEqual(force_text(filterspec.title), 'book')
|
self.assertEqual(filterspec.title, 'book')
|
||||||
choice = select_by(filterspec.choices(changelist), "display", self.django_book.title)
|
choice = select_by(filterspec.choices(changelist), "display", self.django_book.title)
|
||||||
self.assertIs(choice['selected'], True)
|
self.assertIs(choice['selected'], True)
|
||||||
self.assertEqual(choice['query_string'], '?books_contributed__id__exact=%d' % self.django_book.pk)
|
self.assertEqual(choice['query_string'], '?books_contributed__id__exact=%d' % self.django_book.pk)
|
||||||
|
@ -715,7 +714,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][3]
|
filterspec = changelist.get_filters(request)[0][3]
|
||||||
self.assertEqual(force_text(filterspec.title), 'is best seller')
|
self.assertEqual(filterspec.title, 'is best seller')
|
||||||
choice = select_by(filterspec.choices(changelist), "display", "No")
|
choice = select_by(filterspec.choices(changelist), "display", "No")
|
||||||
self.assertIs(choice['selected'], True)
|
self.assertIs(choice['selected'], True)
|
||||||
self.assertEqual(choice['query_string'], '?is_best_seller__exact=0')
|
self.assertEqual(choice['query_string'], '?is_best_seller__exact=0')
|
||||||
|
@ -729,7 +728,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][3]
|
filterspec = changelist.get_filters(request)[0][3]
|
||||||
self.assertEqual(force_text(filterspec.title), 'is best seller')
|
self.assertEqual(filterspec.title, 'is best seller')
|
||||||
choice = select_by(filterspec.choices(changelist), "display", "Yes")
|
choice = select_by(filterspec.choices(changelist), "display", "Yes")
|
||||||
self.assertIs(choice['selected'], True)
|
self.assertIs(choice['selected'], True)
|
||||||
self.assertEqual(choice['query_string'], '?is_best_seller__exact=1')
|
self.assertEqual(choice['query_string'], '?is_best_seller__exact=1')
|
||||||
|
@ -743,7 +742,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][3]
|
filterspec = changelist.get_filters(request)[0][3]
|
||||||
self.assertEqual(force_text(filterspec.title), 'is best seller')
|
self.assertEqual(filterspec.title, 'is best seller')
|
||||||
choice = select_by(filterspec.choices(changelist), "display", "Unknown")
|
choice = select_by(filterspec.choices(changelist), "display", "Unknown")
|
||||||
self.assertIs(choice['selected'], True)
|
self.assertIs(choice['selected'], True)
|
||||||
self.assertEqual(choice['query_string'], '?is_best_seller__isnull=True')
|
self.assertEqual(choice['query_string'], '?is_best_seller__isnull=True')
|
||||||
|
@ -777,7 +776,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][1]
|
filterspec = changelist.get_filters(request)[0][1]
|
||||||
self.assertEqual(force_text(filterspec.title), 'publication decade')
|
self.assertEqual(filterspec.title, 'publication decade')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertEqual(choices[0]['display'], 'All')
|
self.assertEqual(choices[0]['display'], 'All')
|
||||||
self.assertIs(choices[0]['selected'], True)
|
self.assertIs(choices[0]['selected'], True)
|
||||||
|
@ -793,7 +792,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][1]
|
filterspec = changelist.get_filters(request)[0][1]
|
||||||
self.assertEqual(force_text(filterspec.title), 'publication decade')
|
self.assertEqual(filterspec.title, 'publication decade')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertEqual(choices[1]['display'], 'the 1980\'s')
|
self.assertEqual(choices[1]['display'], 'the 1980\'s')
|
||||||
self.assertIs(choices[1]['selected'], True)
|
self.assertIs(choices[1]['selected'], True)
|
||||||
|
@ -809,7 +808,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][1]
|
filterspec = changelist.get_filters(request)[0][1]
|
||||||
self.assertEqual(force_text(filterspec.title), 'publication decade')
|
self.assertEqual(filterspec.title, 'publication decade')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertEqual(choices[2]['display'], 'the 1990\'s')
|
self.assertEqual(choices[2]['display'], 'the 1990\'s')
|
||||||
self.assertIs(choices[2]['selected'], True)
|
self.assertIs(choices[2]['selected'], True)
|
||||||
|
@ -825,7 +824,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][1]
|
filterspec = changelist.get_filters(request)[0][1]
|
||||||
self.assertEqual(force_text(filterspec.title), 'publication decade')
|
self.assertEqual(filterspec.title, 'publication decade')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertEqual(choices[3]['display'], 'the 2000\'s')
|
self.assertEqual(choices[3]['display'], 'the 2000\'s')
|
||||||
self.assertIs(choices[3]['selected'], True)
|
self.assertIs(choices[3]['selected'], True)
|
||||||
|
@ -841,7 +840,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choices are selected
|
# Make sure the correct choices are selected
|
||||||
filterspec = changelist.get_filters(request)[0][1]
|
filterspec = changelist.get_filters(request)[0][1]
|
||||||
self.assertEqual(force_text(filterspec.title), 'publication decade')
|
self.assertEqual(filterspec.title, 'publication decade')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertEqual(choices[3]['display'], 'the 2000\'s')
|
self.assertEqual(choices[3]['display'], 'the 2000\'s')
|
||||||
self.assertIs(choices[3]['selected'], True)
|
self.assertIs(choices[3]['selected'], True)
|
||||||
|
@ -851,7 +850,7 @@ class ListFiltersTests(TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
filterspec = changelist.get_filters(request)[0][0]
|
filterspec = changelist.get_filters(request)[0][0]
|
||||||
self.assertEqual(force_text(filterspec.title), 'Verbose Author')
|
self.assertEqual(filterspec.title, 'Verbose Author')
|
||||||
choice = select_by(filterspec.choices(changelist), "display", "alfred")
|
choice = select_by(filterspec.choices(changelist), "display", "alfred")
|
||||||
self.assertIs(choice['selected'], True)
|
self.assertIs(choice['selected'], True)
|
||||||
self.assertEqual(choice['query_string'], '?author__id__exact=%s&publication-decade=the+00s' % self.alfred.pk)
|
self.assertEqual(choice['query_string'], '?author__id__exact=%s&publication-decade=the+00s' % self.alfred.pk)
|
||||||
|
@ -903,7 +902,7 @@ class ListFiltersTests(TestCase):
|
||||||
changelist = self.get_changelist(request, Book, modeladmin)
|
changelist = self.get_changelist(request, Book, modeladmin)
|
||||||
|
|
||||||
filterspec = changelist.get_filters(request)[0][0]
|
filterspec = changelist.get_filters(request)[0][0]
|
||||||
self.assertEqual(force_text(filterspec.title), 'publication decade')
|
self.assertEqual(filterspec.title, 'publication decade')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertEqual(len(choices), 3)
|
self.assertEqual(len(choices), 3)
|
||||||
|
|
||||||
|
@ -932,7 +931,7 @@ class ListFiltersTests(TestCase):
|
||||||
self.assertEqual(list(queryset), [self.bio_book])
|
self.assertEqual(list(queryset), [self.bio_book])
|
||||||
|
|
||||||
filterspec = changelist.get_filters(request)[0][-1]
|
filterspec = changelist.get_filters(request)[0][-1]
|
||||||
self.assertEqual(force_text(filterspec.title), 'number')
|
self.assertEqual(filterspec.title, 'number')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertIs(choices[2]['selected'], True)
|
self.assertIs(choices[2]['selected'], True)
|
||||||
self.assertEqual(choices[2]['query_string'], '?no=207')
|
self.assertEqual(choices[2]['query_string'], '?no=207')
|
||||||
|
@ -953,7 +952,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][0]
|
filterspec = changelist.get_filters(request)[0][0]
|
||||||
self.assertEqual(force_text(filterspec.title), 'publication decade')
|
self.assertEqual(filterspec.title, 'publication decade')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertEqual(choices[2]['display'], 'the 1990\'s')
|
self.assertEqual(choices[2]['display'], 'the 1990\'s')
|
||||||
self.assertIs(choices[2]['selected'], True)
|
self.assertIs(choices[2]['selected'], True)
|
||||||
|
@ -970,7 +969,7 @@ class ListFiltersTests(TestCase):
|
||||||
|
|
||||||
# Make sure the correct choice is selected
|
# Make sure the correct choice is selected
|
||||||
filterspec = changelist.get_filters(request)[0][0]
|
filterspec = changelist.get_filters(request)[0][0]
|
||||||
self.assertEqual(force_text(filterspec.title), 'publication decade')
|
self.assertEqual(filterspec.title, 'publication decade')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertEqual(choices[2]['display'], 'the 1990\'s')
|
self.assertEqual(choices[2]['display'], 'the 1990\'s')
|
||||||
self.assertIs(choices[2]['selected'], True)
|
self.assertIs(choices[2]['selected'], True)
|
||||||
|
@ -990,7 +989,7 @@ class ListFiltersTests(TestCase):
|
||||||
self.assertEqual(list(queryset), [self.john])
|
self.assertEqual(list(queryset), [self.john])
|
||||||
|
|
||||||
filterspec = changelist.get_filters(request)[0][-1]
|
filterspec = changelist.get_filters(request)[0][-1]
|
||||||
self.assertEqual(force_text(filterspec.title), 'department')
|
self.assertEqual(filterspec.title, 'department')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertEqual(choices[1]['display'], 'DEV')
|
self.assertEqual(choices[1]['display'], 'DEV')
|
||||||
self.assertIs(choices[1]['selected'], True)
|
self.assertIs(choices[1]['selected'], True)
|
||||||
|
@ -1010,7 +1009,7 @@ class ListFiltersTests(TestCase):
|
||||||
self.assertEqual(list(queryset), [self.john])
|
self.assertEqual(list(queryset), [self.john])
|
||||||
|
|
||||||
filterspec = changelist.get_filters(request)[0][-1]
|
filterspec = changelist.get_filters(request)[0][-1]
|
||||||
self.assertEqual(force_text(filterspec.title), 'department')
|
self.assertEqual(filterspec.title, 'department')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
self.assertEqual(choices[1]['display'], 'DEV')
|
self.assertEqual(choices[1]['display'], 'DEV')
|
||||||
self.assertIs(choices[1]['selected'], True)
|
self.assertIs(choices[1]['selected'], True)
|
||||||
|
@ -1030,7 +1029,7 @@ class ListFiltersTests(TestCase):
|
||||||
self.assertEqual(list(queryset), [self.jack, self.john])
|
self.assertEqual(list(queryset), [self.jack, self.john])
|
||||||
|
|
||||||
filterspec = changelist.get_filters(request)[0][-1]
|
filterspec = changelist.get_filters(request)[0][-1]
|
||||||
self.assertEqual(force_text(filterspec.title), 'department')
|
self.assertEqual(filterspec.title, 'department')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
|
|
||||||
self.assertEqual(choices[0]['display'], 'All')
|
self.assertEqual(choices[0]['display'], 'All')
|
||||||
|
@ -1055,7 +1054,7 @@ class ListFiltersTests(TestCase):
|
||||||
self.assertEqual(list(queryset), [self.john])
|
self.assertEqual(list(queryset), [self.john])
|
||||||
|
|
||||||
filterspec = changelist.get_filters(request)[0][-1]
|
filterspec = changelist.get_filters(request)[0][-1]
|
||||||
self.assertEqual(force_text(filterspec.title), 'department')
|
self.assertEqual(filterspec.title, 'department')
|
||||||
choices = list(filterspec.choices(changelist))
|
choices = list(filterspec.choices(changelist))
|
||||||
|
|
||||||
self.assertEqual(choices[0]['display'], 'All')
|
self.assertEqual(choices[0]['display'], 'All')
|
||||||
|
@ -1079,7 +1078,7 @@ class ListFiltersTests(TestCase):
|
||||||
def _test_choices(request, expected_displays):
|
def _test_choices(request, expected_displays):
|
||||||
changelist = self.get_changelist(request, Book, modeladmin)
|
changelist = self.get_changelist(request, Book, modeladmin)
|
||||||
filterspec = changelist.get_filters(request)[0][0]
|
filterspec = changelist.get_filters(request)[0][0]
|
||||||
self.assertEqual(force_text(filterspec.title), 'publication decade')
|
self.assertEqual(filterspec.title, 'publication decade')
|
||||||
choices = tuple(c['display'] for c in filterspec.choices(changelist))
|
choices = tuple(c['display'] for c in filterspec.choices(changelist))
|
||||||
self.assertEqual(choices, expected_displays)
|
self.assertEqual(choices, expected_displays)
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ from django.db.migrations.recorder import MigrationRecorder
|
||||||
from django.test import (
|
from django.test import (
|
||||||
LiveServerTestCase, SimpleTestCase, TestCase, override_settings,
|
LiveServerTestCase, SimpleTestCase, TestCase, override_settings,
|
||||||
)
|
)
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
custom_templates_dir = os.path.join(os.path.dirname(__file__), 'custom_templates')
|
custom_templates_dir = os.path.join(os.path.dirname(__file__), 'custom_templates')
|
||||||
|
|
||||||
|
@ -196,7 +195,6 @@ class AdminScriptTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def assertOutput(self, stream, msg, regex=False):
|
def assertOutput(self, stream, msg, regex=False):
|
||||||
"Utility assertion: assert that the given message exists in the output"
|
"Utility assertion: assert that the given message exists in the output"
|
||||||
stream = force_text(stream)
|
|
||||||
if regex:
|
if regex:
|
||||||
self.assertIsNotNone(
|
self.assertIsNotNone(
|
||||||
re.search(msg, stream),
|
re.search(msg, stream),
|
||||||
|
@ -207,7 +205,6 @@ class AdminScriptTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def assertNotInOutput(self, stream, msg):
|
def assertNotInOutput(self, stream, msg):
|
||||||
"Utility assertion: assert that the given message doesn't exist in the output"
|
"Utility assertion: assert that the given message doesn't exist in the output"
|
||||||
stream = force_text(stream)
|
|
||||||
self.assertNotIn(msg, stream, "'%s' matches actual output text '%s'" % (msg, stream))
|
self.assertNotIn(msg, stream, "'%s' matches actual output text '%s'" % (msg, stream))
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -2021,7 +2018,7 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
|
||||||
self.assertNoOutput(err)
|
self.assertNoOutput(err)
|
||||||
test_manage_py = os.path.join(testproject_dir, 'manage.py')
|
test_manage_py = os.path.join(testproject_dir, 'manage.py')
|
||||||
with open(test_manage_py, 'r') as fp:
|
with open(test_manage_py, 'r') as fp:
|
||||||
content = force_text(fp.read())
|
content = fp.read()
|
||||||
self.assertIn("project_name = 'another_project'", content)
|
self.assertIn("project_name = 'another_project'", content)
|
||||||
self.assertIn("project_directory = '%s'" % testproject_dir, content)
|
self.assertIn("project_directory = '%s'" % testproject_dir, content)
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ from django.http import QueryDict
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
from django.test.utils import ignore_warnings, patch_logger
|
from django.test.utils import ignore_warnings, patch_logger
|
||||||
from django.utils.deprecation import RemovedInDjango21Warning
|
from django.utils.deprecation import RemovedInDjango21Warning
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
from .models import CustomUser, UUIDUser
|
from .models import CustomUser, UUIDUser
|
||||||
from .settings import AUTH_TEMPLATES
|
from .settings import AUTH_TEMPLATES
|
||||||
|
@ -52,7 +51,7 @@ class AuthViewsTestCase(TestCase):
|
||||||
def assertFormError(self, response, error):
|
def assertFormError(self, response, error):
|
||||||
"""Assert that error is found in response.context['form'] errors"""
|
"""Assert that error is found in response.context['form'] errors"""
|
||||||
form_errors = list(itertools.chain(*response.context['form'].errors.values()))
|
form_errors = list(itertools.chain(*response.context['form'].errors.values()))
|
||||||
self.assertIn(force_text(error), form_errors)
|
self.assertIn(str(error), form_errors)
|
||||||
|
|
||||||
def assertURLEqual(self, url, expected, parse_qs=False):
|
def assertURLEqual(self, url, expected, parse_qs=False):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -16,7 +16,6 @@ from django.core.mail import EmailMultiAlternatives
|
||||||
from django.forms.fields import CharField, Field, IntegerField
|
from django.forms.fields import CharField, Field, IntegerField
|
||||||
from django.test import SimpleTestCase, TestCase, override_settings
|
from django.test import SimpleTestCase, TestCase, override_settings
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
from django.utils.encoding import force_text
|
|
||||||
from django.utils.text import capfirst
|
from django.utils.text import capfirst
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
|
@ -51,7 +50,7 @@ class UserCreationFormTest(TestDataMixin, TestCase):
|
||||||
form = UserCreationForm(data)
|
form = UserCreationForm(data)
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
self.assertEqual(form["username"].errors,
|
self.assertEqual(form["username"].errors,
|
||||||
[force_text(User._meta.get_field('username').error_messages['unique'])])
|
[str(User._meta.get_field('username').error_messages['unique'])])
|
||||||
|
|
||||||
def test_invalid_data(self):
|
def test_invalid_data(self):
|
||||||
data = {
|
data = {
|
||||||
|
@ -62,7 +61,7 @@ class UserCreationFormTest(TestDataMixin, TestCase):
|
||||||
form = UserCreationForm(data)
|
form = UserCreationForm(data)
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
validator = next(v for v in User._meta.get_field('username').validators if v.code == 'invalid')
|
validator = next(v for v in User._meta.get_field('username').validators if v.code == 'invalid')
|
||||||
self.assertEqual(form["username"].errors, [force_text(validator.message)])
|
self.assertEqual(form["username"].errors, [str(validator.message)])
|
||||||
|
|
||||||
def test_password_verification(self):
|
def test_password_verification(self):
|
||||||
# The verification password is incorrect.
|
# The verification password is incorrect.
|
||||||
|
@ -74,13 +73,13 @@ class UserCreationFormTest(TestDataMixin, TestCase):
|
||||||
form = UserCreationForm(data)
|
form = UserCreationForm(data)
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
self.assertEqual(form["password2"].errors,
|
self.assertEqual(form["password2"].errors,
|
||||||
[force_text(form.error_messages['password_mismatch'])])
|
[str(form.error_messages['password_mismatch'])])
|
||||||
|
|
||||||
def test_both_passwords(self):
|
def test_both_passwords(self):
|
||||||
# One (or both) passwords weren't given
|
# One (or both) passwords weren't given
|
||||||
data = {'username': 'jsmith'}
|
data = {'username': 'jsmith'}
|
||||||
form = UserCreationForm(data)
|
form = UserCreationForm(data)
|
||||||
required_error = [force_text(Field.default_error_messages['required'])]
|
required_error = [str(Field.default_error_messages['required'])]
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
self.assertEqual(form['password1'].errors, required_error)
|
self.assertEqual(form['password1'].errors, required_error)
|
||||||
self.assertEqual(form['password2'].errors, required_error)
|
self.assertEqual(form['password2'].errors, required_error)
|
||||||
|
@ -257,9 +256,9 @@ class AuthenticationFormTest(TestDataMixin, TestCase):
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
form.non_field_errors(), [
|
form.non_field_errors(), [
|
||||||
force_text(form.error_messages['invalid_login'] % {
|
form.error_messages['invalid_login'] % {
|
||||||
'username': User._meta.get_field('username').verbose_name
|
'username': User._meta.get_field('username').verbose_name
|
||||||
})
|
}
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -271,7 +270,7 @@ class AuthenticationFormTest(TestDataMixin, TestCase):
|
||||||
}
|
}
|
||||||
form = AuthenticationForm(None, data)
|
form = AuthenticationForm(None, data)
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
self.assertEqual(form.non_field_errors(), [force_text(form.error_messages['inactive'])])
|
self.assertEqual(form.non_field_errors(), [str(form.error_messages['inactive'])])
|
||||||
|
|
||||||
def test_login_failed(self):
|
def test_login_failed(self):
|
||||||
signal_calls = []
|
signal_calls = []
|
||||||
|
@ -300,7 +299,7 @@ class AuthenticationFormTest(TestDataMixin, TestCase):
|
||||||
}
|
}
|
||||||
form = AuthenticationForm(None, data)
|
form = AuthenticationForm(None, data)
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
self.assertEqual(form.non_field_errors(), [force_text(form.error_messages['inactive'])])
|
self.assertEqual(form.non_field_errors(), [str(form.error_messages['inactive'])])
|
||||||
|
|
||||||
def test_custom_login_allowed_policy(self):
|
def test_custom_login_allowed_policy(self):
|
||||||
# The user is inactive, but our custom form policy allows them to log in.
|
# The user is inactive, but our custom form policy allows them to log in.
|
||||||
|
@ -421,7 +420,7 @@ class SetPasswordFormTest(TestDataMixin, TestCase):
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
form["new_password2"].errors,
|
form["new_password2"].errors,
|
||||||
[force_text(form.error_messages['password_mismatch'])]
|
[str(form.error_messages['password_mismatch'])]
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch('django.contrib.auth.password_validation.password_changed')
|
@mock.patch('django.contrib.auth.password_validation.password_changed')
|
||||||
|
@ -499,7 +498,7 @@ class PasswordChangeFormTest(TestDataMixin, TestCase):
|
||||||
}
|
}
|
||||||
form = PasswordChangeForm(user, data)
|
form = PasswordChangeForm(user, data)
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
self.assertEqual(form["old_password"].errors, [force_text(form.error_messages['password_incorrect'])])
|
self.assertEqual(form["old_password"].errors, [str(form.error_messages['password_incorrect'])])
|
||||||
|
|
||||||
def test_password_verification(self):
|
def test_password_verification(self):
|
||||||
# The two new passwords do not match.
|
# The two new passwords do not match.
|
||||||
|
@ -511,7 +510,7 @@ class PasswordChangeFormTest(TestDataMixin, TestCase):
|
||||||
}
|
}
|
||||||
form = PasswordChangeForm(user, data)
|
form = PasswordChangeForm(user, data)
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
self.assertEqual(form["new_password2"].errors, [force_text(form.error_messages['password_mismatch'])])
|
self.assertEqual(form["new_password2"].errors, [str(form.error_messages['password_mismatch'])])
|
||||||
|
|
||||||
@mock.patch('django.contrib.auth.password_validation.password_changed')
|
@mock.patch('django.contrib.auth.password_validation.password_changed')
|
||||||
def test_success(self, password_changed):
|
def test_success(self, password_changed):
|
||||||
|
@ -557,7 +556,7 @@ class UserChangeFormTest(TestDataMixin, TestCase):
|
||||||
form = UserChangeForm(data, instance=user)
|
form = UserChangeForm(data, instance=user)
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
validator = next(v for v in User._meta.get_field('username').validators if v.code == 'invalid')
|
validator = next(v for v in User._meta.get_field('username').validators if v.code == 'invalid')
|
||||||
self.assertEqual(form["username"].errors, [force_text(validator.message)])
|
self.assertEqual(form["username"].errors, [str(validator.message)])
|
||||||
|
|
||||||
def test_bug_14242(self):
|
def test_bug_14242(self):
|
||||||
# A regression test, introduce by adding an optimization for the
|
# A regression test, introduce by adding an optimization for the
|
||||||
|
|
|
@ -7,7 +7,7 @@ from django.contrib.auth.views import (
|
||||||
)
|
)
|
||||||
from django.test import RequestFactory, TestCase, override_settings
|
from django.test import RequestFactory, TestCase, override_settings
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.encoding import force_bytes, force_text
|
from django.utils.encoding import force_bytes
|
||||||
from django.utils.http import urlsafe_base64_encode
|
from django.utils.http import urlsafe_base64_encode
|
||||||
|
|
||||||
from .client import PasswordResetConfirmClient
|
from .client import PasswordResetConfirmClient
|
||||||
|
@ -48,7 +48,7 @@ class AuthTemplateTests(TestCase):
|
||||||
client = PasswordResetConfirmClient()
|
client = PasswordResetConfirmClient()
|
||||||
default_token_generator = PasswordResetTokenGenerator()
|
default_token_generator = PasswordResetTokenGenerator()
|
||||||
token = default_token_generator.make_token(self.user)
|
token = default_token_generator.make_token(self.user)
|
||||||
uidb64 = force_text(urlsafe_base64_encode(force_bytes(self.user.pk)))
|
uidb64 = urlsafe_base64_encode(force_bytes(self.user.pk)).decode()
|
||||||
url = reverse('password_reset_confirm', kwargs={'uidb64': uidb64, 'token': token})
|
url = reverse('password_reset_confirm', kwargs={'uidb64': uidb64, 'token': token})
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
self.assertContains(response, '<title>Enter new password</title>')
|
self.assertContains(response, '<title>Enter new password</title>')
|
||||||
|
|
|
@ -68,7 +68,7 @@ class AuthViewsTestCase(TestCase):
|
||||||
def assertFormError(self, response, error):
|
def assertFormError(self, response, error):
|
||||||
"""Assert that error is found in response.context['form'] errors"""
|
"""Assert that error is found in response.context['form'] errors"""
|
||||||
form_errors = list(itertools.chain(*response.context['form'].errors.values()))
|
form_errors = list(itertools.chain(*response.context['form'].errors.values()))
|
||||||
self.assertIn(force_text(error), form_errors)
|
self.assertIn(str(error), form_errors)
|
||||||
|
|
||||||
def assertURLEqual(self, url, expected, parse_qs=False):
|
def assertURLEqual(self, url, expected, parse_qs=False):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -41,7 +41,6 @@ from django.utils.cache import (
|
||||||
patch_response_headers, patch_vary_headers,
|
patch_response_headers, patch_vary_headers,
|
||||||
)
|
)
|
||||||
from django.utils.deprecation import RemovedInDjango21Warning
|
from django.utils.deprecation import RemovedInDjango21Warning
|
||||||
from django.utils.encoding import force_text
|
|
||||||
from django.views.decorators.cache import cache_page
|
from django.views.decorators.cache import cache_page
|
||||||
|
|
||||||
from .models import Poll, expensive_calculation
|
from .models import Poll, expensive_calculation
|
||||||
|
@ -1789,7 +1788,7 @@ class CacheI18nTest(TestCase):
|
||||||
request = self.factory.get(self.path)
|
request = self.factory.get(self.path)
|
||||||
# This is tightly coupled to the implementation,
|
# This is tightly coupled to the implementation,
|
||||||
# but it's the most straightforward way to test the key.
|
# but it's the most straightforward way to test the key.
|
||||||
tz = force_text(timezone.get_current_timezone_name(), errors='ignore')
|
tz = timezone.get_current_timezone_name()
|
||||||
tz = tz.encode('ascii', 'ignore').decode('ascii').replace(' ', '_')
|
tz = tz.encode('ascii', 'ignore').decode('ascii').replace(' ', '_')
|
||||||
response = HttpResponse()
|
response = HttpResponse()
|
||||||
key = learn_cache_key(request, response)
|
key = learn_cache_key(request, response)
|
||||||
|
@ -1801,7 +1800,7 @@ class CacheI18nTest(TestCase):
|
||||||
def test_cache_key_no_i18n(self):
|
def test_cache_key_no_i18n(self):
|
||||||
request = self.factory.get(self.path)
|
request = self.factory.get(self.path)
|
||||||
lang = translation.get_language()
|
lang = translation.get_language()
|
||||||
tz = force_text(timezone.get_current_timezone_name(), errors='ignore')
|
tz = timezone.get_current_timezone_name()
|
||||||
tz = tz.encode('ascii', 'ignore').decode('ascii').replace(' ', '_')
|
tz = tz.encode('ascii', 'ignore').decode('ascii').replace(' ', '_')
|
||||||
response = HttpResponse()
|
response = HttpResponse()
|
||||||
key = learn_cache_key(request, response)
|
key = learn_cache_key(request, response)
|
||||||
|
|
|
@ -12,7 +12,6 @@ from django.test import SimpleTestCase
|
||||||
from django.test.utils import (
|
from django.test.utils import (
|
||||||
isolate_apps, override_settings, override_system_checks,
|
isolate_apps, override_settings, override_system_checks,
|
||||||
)
|
)
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
from .models import SimpleModel, my_check
|
from .models import SimpleModel, my_check
|
||||||
|
|
||||||
|
@ -73,39 +72,39 @@ class MessageTests(SimpleTestCase):
|
||||||
def test_printing(self):
|
def test_printing(self):
|
||||||
e = Error("Message", hint="Hint", obj=DummyObj())
|
e = Error("Message", hint="Hint", obj=DummyObj())
|
||||||
expected = "obj: Message\n\tHINT: Hint"
|
expected = "obj: Message\n\tHINT: Hint"
|
||||||
self.assertEqual(force_text(e), expected)
|
self.assertEqual(str(e), expected)
|
||||||
|
|
||||||
def test_printing_no_hint(self):
|
def test_printing_no_hint(self):
|
||||||
e = Error("Message", obj=DummyObj())
|
e = Error("Message", obj=DummyObj())
|
||||||
expected = "obj: Message"
|
expected = "obj: Message"
|
||||||
self.assertEqual(force_text(e), expected)
|
self.assertEqual(str(e), expected)
|
||||||
|
|
||||||
def test_printing_no_object(self):
|
def test_printing_no_object(self):
|
||||||
e = Error("Message", hint="Hint")
|
e = Error("Message", hint="Hint")
|
||||||
expected = "?: Message\n\tHINT: Hint"
|
expected = "?: Message\n\tHINT: Hint"
|
||||||
self.assertEqual(force_text(e), expected)
|
self.assertEqual(str(e), expected)
|
||||||
|
|
||||||
def test_printing_with_given_id(self):
|
def test_printing_with_given_id(self):
|
||||||
e = Error("Message", hint="Hint", obj=DummyObj(), id="ID")
|
e = Error("Message", hint="Hint", obj=DummyObj(), id="ID")
|
||||||
expected = "obj: (ID) Message\n\tHINT: Hint"
|
expected = "obj: (ID) Message\n\tHINT: Hint"
|
||||||
self.assertEqual(force_text(e), expected)
|
self.assertEqual(str(e), expected)
|
||||||
|
|
||||||
def test_printing_field_error(self):
|
def test_printing_field_error(self):
|
||||||
field = SimpleModel._meta.get_field('field')
|
field = SimpleModel._meta.get_field('field')
|
||||||
e = Error("Error", obj=field)
|
e = Error("Error", obj=field)
|
||||||
expected = "check_framework.SimpleModel.field: Error"
|
expected = "check_framework.SimpleModel.field: Error"
|
||||||
self.assertEqual(force_text(e), expected)
|
self.assertEqual(str(e), expected)
|
||||||
|
|
||||||
def test_printing_model_error(self):
|
def test_printing_model_error(self):
|
||||||
e = Error("Error", obj=SimpleModel)
|
e = Error("Error", obj=SimpleModel)
|
||||||
expected = "check_framework.SimpleModel: Error"
|
expected = "check_framework.SimpleModel: Error"
|
||||||
self.assertEqual(force_text(e), expected)
|
self.assertEqual(str(e), expected)
|
||||||
|
|
||||||
def test_printing_manager_error(self):
|
def test_printing_manager_error(self):
|
||||||
manager = SimpleModel.manager
|
manager = SimpleModel.manager
|
||||||
e = Error("Error", obj=manager)
|
e = Error("Error", obj=manager)
|
||||||
expected = "check_framework.SimpleModel.manager: Error"
|
expected = "check_framework.SimpleModel.manager: Error"
|
||||||
self.assertEqual(force_text(e), expected)
|
self.assertEqual(str(e), expected)
|
||||||
|
|
||||||
def test_equal_to_self(self):
|
def test_equal_to_self(self):
|
||||||
e = Error("Error", obj=SimpleModel)
|
e = Error("Error", obj=SimpleModel)
|
||||||
|
|
|
@ -16,7 +16,6 @@ from django.test import (
|
||||||
SimpleTestCase, TestCase, TransactionTestCase, override_settings,
|
SimpleTestCase, TestCase, TransactionTestCase, override_settings,
|
||||||
)
|
)
|
||||||
from django.test.utils import captured_stdout, isolate_apps
|
from django.test.utils import captured_stdout, isolate_apps
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
Article, Author, ModelWithNullFKToSite, Post, SchemeIncludedURL,
|
Article, Author, ModelWithNullFKToSite, Post, SchemeIncludedURL,
|
||||||
|
@ -134,7 +133,7 @@ class ContentTypesViewsTests(TestCase):
|
||||||
ct = ContentType.objects.get_for_model(ModelCreatedOnTheFly)
|
ct = ContentType.objects.get_for_model(ModelCreatedOnTheFly)
|
||||||
self.assertEqual(ct.app_label, 'my_great_app')
|
self.assertEqual(ct.app_label, 'my_great_app')
|
||||||
self.assertEqual(ct.model, 'modelcreatedonthefly')
|
self.assertEqual(ct.model, 'modelcreatedonthefly')
|
||||||
self.assertEqual(force_text(ct), 'modelcreatedonthefly')
|
self.assertEqual(str(ct), 'modelcreatedonthefly')
|
||||||
|
|
||||||
|
|
||||||
@override_settings(SILENCED_SYSTEM_CHECKS=['fields.W342']) # ForeignKey(unique=True)
|
@override_settings(SILENCED_SYSTEM_CHECKS=['fields.W342']) # ForeignKey(unique=True)
|
||||||
|
@ -144,9 +143,7 @@ class GenericForeignKeyTests(SimpleTestCase):
|
||||||
def test_str(self):
|
def test_str(self):
|
||||||
class Model(models.Model):
|
class Model(models.Model):
|
||||||
field = GenericForeignKey()
|
field = GenericForeignKey()
|
||||||
expected = "contenttypes_tests.Model.field"
|
self.assertEqual(str(Model.field), "contenttypes_tests.Model.field")
|
||||||
actual = force_text(Model.field)
|
|
||||||
self.assertEqual(expected, actual)
|
|
||||||
|
|
||||||
def test_missing_content_type_field(self):
|
def test_missing_content_type_field(self):
|
||||||
class TaggedItem(models.Model):
|
class TaggedItem(models.Model):
|
||||||
|
|
|
@ -2,14 +2,13 @@ from django.http import HttpRequest
|
||||||
from django.middleware.csrf import _compare_salted_tokens as equivalent_tokens
|
from django.middleware.csrf import _compare_salted_tokens as equivalent_tokens
|
||||||
from django.template.context_processors import csrf
|
from django.template.context_processors import csrf
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
|
|
||||||
class TestContextProcessor(SimpleTestCase):
|
class TestContextProcessor(SimpleTestCase):
|
||||||
|
|
||||||
def test_force_text_on_token(self):
|
def test_force_token_to_string(self):
|
||||||
request = HttpRequest()
|
request = HttpRequest()
|
||||||
test_token = '1bcdefghij2bcdefghij3bcdefghij4bcdefghij5bcdefghij6bcdefghijABCD'
|
test_token = '1bcdefghij2bcdefghij3bcdefghij4bcdefghij5bcdefghij6bcdefghijABCD'
|
||||||
request.META['CSRF_COOKIE'] = test_token
|
request.META['CSRF_COOKIE'] = test_token
|
||||||
token = csrf(request).get('csrf_token')
|
token = csrf(request).get('csrf_token')
|
||||||
self.assertTrue(equivalent_tokens(force_text(token), test_token))
|
self.assertTrue(equivalent_tokens(str(token), test_token))
|
||||||
|
|
|
@ -15,7 +15,6 @@ from django.core.management.commands.dumpdata import ProxyModelWarning
|
||||||
from django.core.serializers.base import ProgressBar
|
from django.core.serializers.base import ProgressBar
|
||||||
from django.db import IntegrityError, connection
|
from django.db import IntegrityError, connection
|
||||||
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
|
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
Article, Category, PrimaryKeyUUIDModel, ProxySpy, Spy, Tag, Visa,
|
Article, Category, PrimaryKeyUUIDModel, ProxySpy, Spy, Tag, Visa,
|
||||||
|
@ -584,7 +583,7 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
|
||||||
def test_loaddata_verbosity_three(self):
|
def test_loaddata_verbosity_three(self):
|
||||||
output = StringIO()
|
output = StringIO()
|
||||||
management.call_command('loaddata', 'fixture1.json', verbosity=3, stdout=output, stderr=output)
|
management.call_command('loaddata', 'fixture1.json', verbosity=3, stdout=output, stderr=output)
|
||||||
command_output = force_text(output.getvalue())
|
command_output = output.getvalue()
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
"\rProcessed 1 object(s).\rProcessed 2 object(s)."
|
"\rProcessed 1 object(s).\rProcessed 2 object(s)."
|
||||||
"\rProcessed 3 object(s).\rProcessed 4 object(s).\n",
|
"\rProcessed 3 object(s).\rProcessed 4 object(s).\n",
|
||||||
|
|
|
@ -20,7 +20,6 @@ from django.http import QueryDict
|
||||||
from django.template import Context, Template
|
from django.template import Context, Template
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.utils.datastructures import MultiValueDict
|
from django.utils.datastructures import MultiValueDict
|
||||||
from django.utils.encoding import force_text
|
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
|
|
||||||
|
@ -3361,7 +3360,7 @@ Good luck picking a username that doesn't already exist.</p>
|
||||||
if not self:
|
if not self:
|
||||||
return ''
|
return ''
|
||||||
return '<div class="errorlist">%s</div>' % ''.join(
|
return '<div class="errorlist">%s</div>' % ''.join(
|
||||||
'<div class="error">%s</div>' % force_text(e) for e in self)
|
'<div class="error">%s</div>' % e for e in self)
|
||||||
|
|
||||||
class CommentForm(Form):
|
class CommentForm(Form):
|
||||||
name = CharField(max_length=50, required=False)
|
name = CharField(max_length=50, required=False)
|
||||||
|
@ -3471,9 +3470,9 @@ Good luck picking a username that doesn't already exist.</p>
|
||||||
|
|
||||||
form = SimpleForm()
|
form = SimpleForm()
|
||||||
self.assertTrue(hasattr(SimpleForm, '__html__'))
|
self.assertTrue(hasattr(SimpleForm, '__html__'))
|
||||||
self.assertEqual(force_text(form), form.__html__())
|
self.assertEqual(str(form), form.__html__())
|
||||||
self.assertTrue(hasattr(form['username'], '__html__'))
|
self.assertTrue(hasattr(form['username'], '__html__'))
|
||||||
self.assertEqual(force_text(form['username']), form['username'].__html__())
|
self.assertEqual(str(form['username']), form['username'].__html__())
|
||||||
|
|
||||||
def test_use_required_attribute_true(self):
|
def test_use_required_attribute_true(self):
|
||||||
class MyForm(Form):
|
class MyForm(Form):
|
||||||
|
|
|
@ -9,7 +9,6 @@ from django.forms import (
|
||||||
from django.forms.formsets import BaseFormSet, formset_factory
|
from django.forms.formsets import BaseFormSet, formset_factory
|
||||||
from django.forms.utils import ErrorList
|
from django.forms.utils import ErrorList
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
|
|
||||||
class Choice(Form):
|
class Choice(Form):
|
||||||
|
@ -1251,7 +1250,7 @@ class FormsFormsetTestCase(SimpleTestCase):
|
||||||
def test_html_safe(self):
|
def test_html_safe(self):
|
||||||
formset = self.make_choiceformset()
|
formset = self.make_choiceformset()
|
||||||
self.assertTrue(hasattr(formset, '__html__'))
|
self.assertTrue(hasattr(formset, '__html__'))
|
||||||
self.assertEqual(force_text(formset), formset.__html__())
|
self.assertEqual(str(formset), formset.__html__())
|
||||||
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from django.forms import CharField, Form, Media, MultiWidget, TextInput
|
from django.forms import CharField, Form, Media, MultiWidget, TextInput
|
||||||
from django.template import Context, Template
|
from django.template import Context, Template
|
||||||
from django.test import SimpleTestCase, override_settings
|
from django.test import SimpleTestCase, override_settings
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
|
@ -518,4 +517,4 @@ class FormsMediaTestCase(SimpleTestCase):
|
||||||
def test_html_safe(self):
|
def test_html_safe(self):
|
||||||
media = Media(css={'all': ['/path/to/css']}, js=['/path/to/js'])
|
media = Media(css={'all': ['/path/to/css']}, js=['/path/to/js'])
|
||||||
self.assertTrue(hasattr(Media, '__html__'))
|
self.assertTrue(hasattr(Media, '__html__'))
|
||||||
self.assertEqual(force_text(media), media.__html__())
|
self.assertEqual(str(media), media.__html__())
|
||||||
|
|
|
@ -3,7 +3,6 @@ import copy
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.forms.utils import ErrorDict, ErrorList, flatatt
|
from django.forms.utils import ErrorDict, ErrorList, flatatt
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.utils.encoding import force_text
|
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import ugettext_lazy
|
from django.utils.translation import ugettext_lazy
|
||||||
|
|
||||||
|
@ -158,9 +157,9 @@ class FormsUtilsTestCase(SimpleTestCase):
|
||||||
e = ErrorDict()
|
e = ErrorDict()
|
||||||
e['username'] = 'Invalid username.'
|
e['username'] = 'Invalid username.'
|
||||||
self.assertTrue(hasattr(ErrorDict, '__html__'))
|
self.assertTrue(hasattr(ErrorDict, '__html__'))
|
||||||
self.assertEqual(force_text(e), e.__html__())
|
self.assertEqual(str(e), e.__html__())
|
||||||
|
|
||||||
def test_error_list_html_safe(self):
|
def test_error_list_html_safe(self):
|
||||||
e = ErrorList(['Invalid username.'])
|
e = ErrorList(['Invalid username.'])
|
||||||
self.assertTrue(hasattr(ErrorList, '__html__'))
|
self.assertTrue(hasattr(ErrorList, '__html__'))
|
||||||
self.assertEqual(force_text(e), e.__html__())
|
self.assertEqual(str(e), e.__html__())
|
||||||
|
|
|
@ -15,7 +15,6 @@ from django.core.management.utils import find_command
|
||||||
from django.test import SimpleTestCase, override_settings
|
from django.test import SimpleTestCase, override_settings
|
||||||
from django.test.utils import captured_stderr, captured_stdout
|
from django.test.utils import captured_stderr, captured_stdout
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
from django.utils.encoding import force_text
|
|
||||||
from django.utils.translation import ugettext
|
from django.utils.translation import ugettext
|
||||||
|
|
||||||
from .utils import RunInTmpDirMixin, copytree
|
from .utils import RunInTmpDirMixin, copytree
|
||||||
|
@ -49,7 +48,7 @@ class PoFileTests(MessageCompilationTests):
|
||||||
try:
|
try:
|
||||||
call_command('compilemessages', locale=['en'], stderr=err_buffer, verbosity=0)
|
call_command('compilemessages', locale=['en'], stderr=err_buffer, verbosity=0)
|
||||||
err = err_buffer.getvalue()
|
err = err_buffer.getvalue()
|
||||||
self.assertIn("not writable location", force_text(err))
|
self.assertIn("not writable location", err)
|
||||||
finally:
|
finally:
|
||||||
os.chmod(mo_file_en, old_mode)
|
os.chmod(mo_file_en, old_mode)
|
||||||
|
|
||||||
|
@ -168,15 +167,15 @@ class FuzzyTranslationTest(ProjectAndAppTests):
|
||||||
with override_settings(LOCALE_PATHS=[os.path.join(self.test_dir, 'locale')]):
|
with override_settings(LOCALE_PATHS=[os.path.join(self.test_dir, 'locale')]):
|
||||||
call_command('compilemessages', locale=[self.LOCALE], stdout=StringIO())
|
call_command('compilemessages', locale=[self.LOCALE], stdout=StringIO())
|
||||||
with translation.override(self.LOCALE):
|
with translation.override(self.LOCALE):
|
||||||
self.assertEqual(ugettext('Lenin'), force_text('Ленин'))
|
self.assertEqual(ugettext('Lenin'), 'Ленин')
|
||||||
self.assertEqual(ugettext('Vodka'), force_text('Vodka'))
|
self.assertEqual(ugettext('Vodka'), 'Vodka')
|
||||||
|
|
||||||
def test_fuzzy_compiling(self):
|
def test_fuzzy_compiling(self):
|
||||||
with override_settings(LOCALE_PATHS=[os.path.join(self.test_dir, 'locale')]):
|
with override_settings(LOCALE_PATHS=[os.path.join(self.test_dir, 'locale')]):
|
||||||
call_command('compilemessages', locale=[self.LOCALE], fuzzy=True, stdout=StringIO())
|
call_command('compilemessages', locale=[self.LOCALE], fuzzy=True, stdout=StringIO())
|
||||||
with translation.override(self.LOCALE):
|
with translation.override(self.LOCALE):
|
||||||
self.assertEqual(ugettext('Lenin'), force_text('Ленин'))
|
self.assertEqual(ugettext('Lenin'), 'Ленин')
|
||||||
self.assertEqual(ugettext('Vodka'), force_text('Водка'))
|
self.assertEqual(ugettext('Vodka'), 'Водка')
|
||||||
|
|
||||||
|
|
||||||
class AppCompilationTest(ProjectAndAppTests):
|
class AppCompilationTest(ProjectAndAppTests):
|
||||||
|
|
|
@ -16,7 +16,6 @@ from django.core.management.commands.makemessages import \
|
||||||
from django.core.management.utils import find_command
|
from django.core.management.utils import find_command
|
||||||
from django.test import SimpleTestCase, override_settings
|
from django.test import SimpleTestCase, override_settings
|
||||||
from django.test.utils import captured_stderr, captured_stdout
|
from django.test.utils import captured_stderr, captured_stdout
|
||||||
from django.utils.encoding import force_text
|
|
||||||
from django.utils.translation import TranslatorCommentWarning
|
from django.utils.translation import TranslatorCommentWarning
|
||||||
|
|
||||||
from .utils import POFileAssertionMixin, RunInTmpDirMixin, copytree
|
from .utils import POFileAssertionMixin, RunInTmpDirMixin, copytree
|
||||||
|
@ -56,7 +55,7 @@ class ExtractorTests(POFileAssertionMixin, RunInTmpDirMixin, SimpleTestCase):
|
||||||
|
|
||||||
def _assertPoLocComment(self, assert_presence, po_filename, line_number, *comment_parts):
|
def _assertPoLocComment(self, assert_presence, po_filename, line_number, *comment_parts):
|
||||||
with open(po_filename, 'r') as fp:
|
with open(po_filename, 'r') as fp:
|
||||||
po_contents = force_text(fp.read())
|
po_contents = fp.read()
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
# #: .\path\to\file.html:123
|
# #: .\path\to\file.html:123
|
||||||
cwd_prefix = '%s%s' % (os.curdir, os.sep)
|
cwd_prefix = '%s%s' % (os.curdir, os.sep)
|
||||||
|
@ -82,7 +81,7 @@ class ExtractorTests(POFileAssertionMixin, RunInTmpDirMixin, SimpleTestCase):
|
||||||
def _get_token_line_number(self, path, token):
|
def _get_token_line_number(self, path, token):
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
for line, content in enumerate(f, 1):
|
for line, content in enumerate(f, 1):
|
||||||
if token in force_text(content):
|
if token in content:
|
||||||
return line
|
return line
|
||||||
self.fail("The token '%s' could not be found in %s, please check the test config" % (token, path))
|
self.fail("The token '%s' could not be found in %s, please check the test config" % (token, path))
|
||||||
|
|
||||||
|
@ -182,7 +181,7 @@ class BasicExtractorTests(ExtractorTests):
|
||||||
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
||||||
self.assertTrue(os.path.exists(self.PO_FILE))
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
||||||
with open(self.PO_FILE, 'r') as fp:
|
with open(self.PO_FILE, 'r') as fp:
|
||||||
po_contents = force_text(fp.read())
|
po_contents = fp.read()
|
||||||
# should not be trimmed
|
# should not be trimmed
|
||||||
self.assertNotMsgId('Text with a few line breaks.', po_contents)
|
self.assertNotMsgId('Text with a few line breaks.', po_contents)
|
||||||
# should be trimmed
|
# should be trimmed
|
||||||
|
@ -209,8 +208,7 @@ class BasicExtractorTests(ExtractorTests):
|
||||||
shutil.copyfile('./not_utf8.sample', './not_utf8.txt')
|
shutil.copyfile('./not_utf8.sample', './not_utf8.txt')
|
||||||
out = StringIO()
|
out = StringIO()
|
||||||
management.call_command('makemessages', locale=[LOCALE], stdout=out)
|
management.call_command('makemessages', locale=[LOCALE], stdout=out)
|
||||||
self.assertIn("UnicodeDecodeError: skipped file not_utf8.txt in .",
|
self.assertIn("UnicodeDecodeError: skipped file not_utf8.txt in .", out.getvalue())
|
||||||
force_text(out.getvalue()))
|
|
||||||
|
|
||||||
def test_unicode_file_name(self):
|
def test_unicode_file_name(self):
|
||||||
open(os.path.join(self.test_dir, 'vidéo.txt'), 'a').close()
|
open(os.path.join(self.test_dir, 'vidéo.txt'), 'a').close()
|
||||||
|
@ -221,7 +219,7 @@ class BasicExtractorTests(ExtractorTests):
|
||||||
shutil.copyfile('./code.sample', './code_sample.py')
|
shutil.copyfile('./code.sample', './code_sample.py')
|
||||||
out = StringIO()
|
out = StringIO()
|
||||||
management.call_command('makemessages', locale=[LOCALE], stdout=out)
|
management.call_command('makemessages', locale=[LOCALE], stdout=out)
|
||||||
self.assertIn("code_sample.py:4", force_text(out.getvalue()))
|
self.assertIn("code_sample.py:4", out.getvalue())
|
||||||
|
|
||||||
def test_template_message_context_extractor(self):
|
def test_template_message_context_extractor(self):
|
||||||
"""
|
"""
|
||||||
|
@ -231,7 +229,7 @@ class BasicExtractorTests(ExtractorTests):
|
||||||
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
||||||
self.assertTrue(os.path.exists(self.PO_FILE))
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
||||||
with open(self.PO_FILE, 'r') as fp:
|
with open(self.PO_FILE, 'r') as fp:
|
||||||
po_contents = force_text(fp.read())
|
po_contents = fp.read()
|
||||||
# {% trans %}
|
# {% trans %}
|
||||||
self.assertIn('msgctxt "Special trans context #1"', po_contents)
|
self.assertIn('msgctxt "Special trans context #1"', po_contents)
|
||||||
self.assertMsgId("Translatable literal #7a", po_contents)
|
self.assertMsgId("Translatable literal #7a", po_contents)
|
||||||
|
@ -261,7 +259,7 @@ class BasicExtractorTests(ExtractorTests):
|
||||||
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
||||||
self.assertTrue(os.path.exists(self.PO_FILE))
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
||||||
with open(self.PO_FILE, 'r') as fp:
|
with open(self.PO_FILE, 'r') as fp:
|
||||||
po_contents = force_text(fp.read())
|
po_contents = fp.read()
|
||||||
# {% trans %}
|
# {% trans %}
|
||||||
self.assertIn('msgctxt "Context wrapped in double quotes"', po_contents)
|
self.assertIn('msgctxt "Context wrapped in double quotes"', po_contents)
|
||||||
self.assertIn('msgctxt "Context wrapped in single quotes"', po_contents)
|
self.assertIn('msgctxt "Context wrapped in single quotes"', po_contents)
|
||||||
|
@ -301,7 +299,7 @@ class BasicExtractorTests(ExtractorTests):
|
||||||
# Now test .po file contents
|
# Now test .po file contents
|
||||||
self.assertTrue(os.path.exists(self.PO_FILE))
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
||||||
with open(self.PO_FILE, 'r') as fp:
|
with open(self.PO_FILE, 'r') as fp:
|
||||||
po_contents = force_text(fp.read())
|
po_contents = fp.read()
|
||||||
|
|
||||||
self.assertMsgId('Translatable literal #9a', po_contents)
|
self.assertMsgId('Translatable literal #9a', po_contents)
|
||||||
self.assertNotIn('ignored comment #1', po_contents)
|
self.assertNotIn('ignored comment #1', po_contents)
|
||||||
|
@ -390,7 +388,7 @@ class BasicExtractorTests(ExtractorTests):
|
||||||
management.call_command('makemessages', locale=['pt_BR'], verbosity=0)
|
management.call_command('makemessages', locale=['pt_BR'], verbosity=0)
|
||||||
self.assertTrue(os.path.exists(BR_PO_BASE + '.po'))
|
self.assertTrue(os.path.exists(BR_PO_BASE + '.po'))
|
||||||
with open(BR_PO_BASE + '.po', 'r', encoding='utf-8') as fp:
|
with open(BR_PO_BASE + '.po', 'r', encoding='utf-8') as fp:
|
||||||
po_contents = force_text(fp.read())
|
po_contents = fp.read()
|
||||||
self.assertMsgStr("Größe", po_contents)
|
self.assertMsgStr("Größe", po_contents)
|
||||||
|
|
||||||
|
|
||||||
|
@ -492,7 +490,7 @@ class SymlinkExtractorTests(ExtractorTests):
|
||||||
management.call_command('makemessages', locale=[LOCALE], verbosity=0, symlinks=True)
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0, symlinks=True)
|
||||||
self.assertTrue(os.path.exists(self.PO_FILE))
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
||||||
with open(self.PO_FILE, 'r') as fp:
|
with open(self.PO_FILE, 'r') as fp:
|
||||||
po_contents = force_text(fp.read())
|
po_contents = fp.read()
|
||||||
self.assertMsgId('This literal should be included.', po_contents)
|
self.assertMsgId('This literal should be included.', po_contents)
|
||||||
self.assertLocationCommentPresent(self.PO_FILE, None, 'templates_symlinked', 'test.html')
|
self.assertLocationCommentPresent(self.PO_FILE, None, 'templates_symlinked', 'test.html')
|
||||||
else:
|
else:
|
||||||
|
@ -507,7 +505,7 @@ class CopyPluralFormsExtractorTests(ExtractorTests):
|
||||||
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
||||||
self.assertTrue(os.path.exists(self.PO_FILE))
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
||||||
with open(self.PO_FILE, 'r') as fp:
|
with open(self.PO_FILE, 'r') as fp:
|
||||||
po_contents = force_text(fp.read())
|
po_contents = fp.read()
|
||||||
self.assertIn('Plural-Forms: nplurals=2; plural=(n != 1)', po_contents)
|
self.assertIn('Plural-Forms: nplurals=2; plural=(n != 1)', po_contents)
|
||||||
|
|
||||||
def test_override_plural_forms(self):
|
def test_override_plural_forms(self):
|
||||||
|
@ -528,7 +526,7 @@ class CopyPluralFormsExtractorTests(ExtractorTests):
|
||||||
management.call_command('makemessages', locale=[LOCALE], extensions=['html', 'djtpl'], verbosity=0)
|
management.call_command('makemessages', locale=[LOCALE], extensions=['html', 'djtpl'], verbosity=0)
|
||||||
self.assertTrue(os.path.exists(self.PO_FILE))
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
||||||
with open(self.PO_FILE, 'r') as fp:
|
with open(self.PO_FILE, 'r') as fp:
|
||||||
po_contents = force_text(fp.read())
|
po_contents = fp.read()
|
||||||
self.assertNotIn("#-#-#-#-# django.pot (PACKAGE VERSION) #-#-#-#-#\\n", po_contents)
|
self.assertNotIn("#-#-#-#-# django.pot (PACKAGE VERSION) #-#-#-#-#\\n", po_contents)
|
||||||
self.assertMsgId('First `trans`, then `blocktrans` with a plural', po_contents)
|
self.assertMsgId('First `trans`, then `blocktrans` with a plural', po_contents)
|
||||||
self.assertMsgIdPlural('Plural for a `trans` and `blocktrans` collision case', po_contents)
|
self.assertMsgIdPlural('Plural for a `trans` and `blocktrans` collision case', po_contents)
|
||||||
|
@ -540,7 +538,7 @@ class NoWrapExtractorTests(ExtractorTests):
|
||||||
management.call_command('makemessages', locale=[LOCALE], verbosity=0, no_wrap=True)
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0, no_wrap=True)
|
||||||
self.assertTrue(os.path.exists(self.PO_FILE))
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
||||||
with open(self.PO_FILE, 'r') as fp:
|
with open(self.PO_FILE, 'r') as fp:
|
||||||
po_contents = force_text(fp.read())
|
po_contents = fp.read()
|
||||||
self.assertMsgId(
|
self.assertMsgId(
|
||||||
'This literal should also be included wrapped or not wrapped '
|
'This literal should also be included wrapped or not wrapped '
|
||||||
'depending on the use of the --no-wrap option.',
|
'depending on the use of the --no-wrap option.',
|
||||||
|
@ -551,7 +549,7 @@ class NoWrapExtractorTests(ExtractorTests):
|
||||||
management.call_command('makemessages', locale=[LOCALE], verbosity=0, no_wrap=False)
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0, no_wrap=False)
|
||||||
self.assertTrue(os.path.exists(self.PO_FILE))
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
||||||
with open(self.PO_FILE, 'r') as fp:
|
with open(self.PO_FILE, 'r') as fp:
|
||||||
po_contents = force_text(fp.read())
|
po_contents = fp.read()
|
||||||
self.assertMsgId(
|
self.assertMsgId(
|
||||||
'""\n"This literal should also be included wrapped or not '
|
'""\n"This literal should also be included wrapped or not '
|
||||||
'wrapped depending on the "\n"use of the --no-wrap option."',
|
'wrapped depending on the "\n"use of the --no-wrap option."',
|
||||||
|
@ -583,7 +581,7 @@ class LocationCommentsTests(ExtractorTests):
|
||||||
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
||||||
self.assertTrue(os.path.exists(self.PO_FILE))
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
||||||
with open(self.PO_FILE, 'r') as fp:
|
with open(self.PO_FILE, 'r') as fp:
|
||||||
po_contents = force_text(fp.read())
|
po_contents = fp.read()
|
||||||
self.assertMsgId('#: templates/test.html.py', po_contents)
|
self.assertMsgId('#: templates/test.html.py', po_contents)
|
||||||
self.assertLocationCommentNotPresent(self.PO_FILE, None, '.html.py')
|
self.assertLocationCommentNotPresent(self.PO_FILE, None, '.html.py')
|
||||||
self.assertLocationCommentPresent(self.PO_FILE, 5, 'templates', 'test.html')
|
self.assertLocationCommentPresent(self.PO_FILE, 5, 'templates', 'test.html')
|
||||||
|
@ -695,11 +693,11 @@ class CustomLayoutExtractionTests(ExtractorTests):
|
||||||
self.assertTrue(os.path.exists(app_de_locale))
|
self.assertTrue(os.path.exists(app_de_locale))
|
||||||
|
|
||||||
with open(project_de_locale, 'r') as fp:
|
with open(project_de_locale, 'r') as fp:
|
||||||
po_contents = force_text(fp.read())
|
po_contents = fp.read()
|
||||||
self.assertMsgId('This app has no locale directory', po_contents)
|
self.assertMsgId('This app has no locale directory', po_contents)
|
||||||
self.assertMsgId('This is a project-level string', po_contents)
|
self.assertMsgId('This is a project-level string', po_contents)
|
||||||
with open(app_de_locale, 'r') as fp:
|
with open(app_de_locale, 'r') as fp:
|
||||||
po_contents = force_text(fp.read())
|
po_contents = fp.read()
|
||||||
self.assertMsgId('This app has a locale directory', po_contents)
|
self.assertMsgId('This app has a locale directory', po_contents)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ import os
|
||||||
|
|
||||||
from django.template import Context, Template
|
from django.template import Context, Template
|
||||||
from django.test import SimpleTestCase, override_settings
|
from django.test import SimpleTestCase, override_settings
|
||||||
from django.utils.encoding import force_text
|
|
||||||
from django.utils.translation import activate, get_language, trans_real
|
from django.utils.translation import activate, get_language, trans_real
|
||||||
|
|
||||||
from .utils import POFileAssertionMixin
|
from .utils import POFileAssertionMixin
|
||||||
|
@ -40,7 +39,7 @@ class ExtractingStringsWithPercentSigns(POFileAssertionMixin, FrenchTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ExtractingStringsWithPercentSigns, self).setUp()
|
super(ExtractingStringsWithPercentSigns, self).setUp()
|
||||||
with open(self.PO_FILE, 'r') as fp:
|
with open(self.PO_FILE, 'r') as fp:
|
||||||
self.po_contents = force_text(fp.read())
|
self.po_contents = fp.read()
|
||||||
|
|
||||||
def test_trans_tag_with_percent_symbol_at_the_end(self):
|
def test_trans_tag_with_percent_symbol_at_the_end(self):
|
||||||
self.assertMsgId('Literal with a percent symbol at the end %%', self.po_contents)
|
self.assertMsgId('Literal with a percent symbol at the end %%', self.po_contents)
|
||||||
|
|
|
@ -5,7 +5,6 @@ from unittest import mock, skipUnless
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.test import TestCase, skipUnlessDBFeature
|
from django.test import TestCase, skipUnlessDBFeature
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
from .models import ColumnTypes
|
from .models import ColumnTypes
|
||||||
|
|
||||||
|
@ -264,7 +263,7 @@ class InspectDBTestCase(TestCase):
|
||||||
with mock.patch('django.db.backends.base.introspection.BaseDatabaseIntrospection.table_names',
|
with mock.patch('django.db.backends.base.introspection.BaseDatabaseIntrospection.table_names',
|
||||||
return_value=['nonexistent']):
|
return_value=['nonexistent']):
|
||||||
call_command('inspectdb', stdout=out)
|
call_command('inspectdb', stdout=out)
|
||||||
output = force_text(out.getvalue())
|
output = out.getvalue()
|
||||||
self.assertIn("# Unable to inspect table 'nonexistent'", output)
|
self.assertIn("# Unable to inspect table 'nonexistent'", output)
|
||||||
# The error message depends on the backend
|
# The error message depends on the backend
|
||||||
self.assertIn("# The error was:", output)
|
self.assertIn("# The error was:", output)
|
||||||
|
|
|
@ -7,7 +7,6 @@ from django.contrib.contenttypes.fields import (
|
||||||
)
|
)
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
|
|
||||||
class OnlyFred(models.Manager):
|
class OnlyFred(models.Manager):
|
||||||
|
@ -123,7 +122,7 @@ class RelatedModel(models.Model):
|
||||||
exact = models.NullBooleanField()
|
exact = models.NullBooleanField()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return force_text(self.pk)
|
return str(self.pk)
|
||||||
|
|
||||||
|
|
||||||
class RelationModel(models.Model):
|
class RelationModel(models.Model):
|
||||||
|
@ -136,4 +135,4 @@ class RelationModel(models.Model):
|
||||||
gfk = GenericForeignKey(ct_field='gfk_ctype', fk_field='gfk_id')
|
gfk = GenericForeignKey(ct_field='gfk_ctype', fk_field='gfk_id')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return force_text(self.pk)
|
return str(self.pk)
|
||||||
|
|
|
@ -2,7 +2,6 @@ from django.db import models
|
||||||
from django.template import Context, Template
|
from django.template import Context, Template
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
from django.test.utils import isolate_apps
|
from django.test.utils import isolate_apps
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
AbstractBase1, AbstractBase2, AbstractBase3, Child1, Child2, Child3,
|
AbstractBase1, AbstractBase2, AbstractBase3, Child1, Child2, Child3,
|
||||||
|
@ -148,7 +147,7 @@ class ManagersRegressionTests(TestCase):
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
t.render(Context({'related': related})),
|
t.render(Context({'related': related})),
|
||||||
''.join([force_text(relation.pk)] * 3),
|
''.join([str(relation.pk)] * 3),
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_field_can_be_called_exact(self):
|
def test_field_can_be_called_exact(self):
|
||||||
|
|
|
@ -16,7 +16,6 @@ from django.db.migrations.exceptions import (
|
||||||
)
|
)
|
||||||
from django.db.migrations.recorder import MigrationRecorder
|
from django.db.migrations.recorder import MigrationRecorder
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
from .models import UnicodeModel, UnserializableModel
|
from .models import UnicodeModel, UnserializableModel
|
||||||
from .routers import TestRouter
|
from .routers import TestRouter
|
||||||
|
@ -649,7 +648,7 @@ class MakeMigrationsTests(MigrationTestBase):
|
||||||
self.assertTrue(os.path.exists(init_file))
|
self.assertTrue(os.path.exists(init_file))
|
||||||
|
|
||||||
with open(init_file, 'r') as fp:
|
with open(init_file, 'r') as fp:
|
||||||
content = force_text(fp.read())
|
content = fp.read()
|
||||||
self.assertEqual(content, '')
|
self.assertEqual(content, '')
|
||||||
|
|
||||||
# Check for existing 0001_initial.py file in migration folder
|
# Check for existing 0001_initial.py file in migration folder
|
||||||
|
|
|
@ -5,7 +5,6 @@ from django.db.migrations.exceptions import (
|
||||||
)
|
)
|
||||||
from django.db.migrations.graph import RECURSION_DEPTH_WARNING, MigrationGraph
|
from django.db.migrations.graph import RECURSION_DEPTH_WARNING, MigrationGraph
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
|
|
||||||
class GraphTests(SimpleTestCase):
|
class GraphTests(SimpleTestCase):
|
||||||
|
@ -395,7 +394,7 @@ class GraphTests(SimpleTestCase):
|
||||||
|
|
||||||
def test_stringify(self):
|
def test_stringify(self):
|
||||||
graph = MigrationGraph()
|
graph = MigrationGraph()
|
||||||
self.assertEqual(force_text(graph), "Graph: 0 nodes, 0 edges")
|
self.assertEqual(str(graph), "Graph: 0 nodes, 0 edges")
|
||||||
|
|
||||||
graph.add_node(("app_a", "0001"), None)
|
graph.add_node(("app_a", "0001"), None)
|
||||||
graph.add_node(("app_a", "0002"), None)
|
graph.add_node(("app_a", "0002"), None)
|
||||||
|
@ -406,5 +405,5 @@ class GraphTests(SimpleTestCase):
|
||||||
graph.add_dependency("app_a.0003", ("app_a", "0003"), ("app_a", "0002"))
|
graph.add_dependency("app_a.0003", ("app_a", "0003"), ("app_a", "0002"))
|
||||||
graph.add_dependency("app_a.0003", ("app_a", "0003"), ("app_b", "0002"))
|
graph.add_dependency("app_a.0003", ("app_a", "0003"), ("app_b", "0002"))
|
||||||
|
|
||||||
self.assertEqual(force_text(graph), "Graph: 5 nodes, 3 edges")
|
self.assertEqual(str(graph), "Graph: 5 nodes, 3 edges")
|
||||||
self.assertEqual(repr(graph), "<MigrationGraph: nodes=5, edges=3>")
|
self.assertEqual(repr(graph), "<MigrationGraph: nodes=5, edges=3>")
|
||||||
|
|
|
@ -5,7 +5,6 @@ from django.db.models import Prefetch, QuerySet
|
||||||
from django.db.models.query import get_prefetcher
|
from django.db.models.query import get_prefetcher
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
from django.test.utils import CaptureQueriesContext
|
from django.test.utils import CaptureQueriesContext
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
Author, Author2, AuthorAddress, AuthorWithAge, Bio, Book, Bookmark,
|
Author, Author2, AuthorAddress, AuthorWithAge, Bio, Book, Bookmark,
|
||||||
|
@ -1260,7 +1259,7 @@ class Ticket21760Tests(TestCase):
|
||||||
def test_bug(self):
|
def test_bug(self):
|
||||||
prefetcher = get_prefetcher(self.rooms[0], 'house', 'house')[0]
|
prefetcher = get_prefetcher(self.rooms[0], 'house', 'house')[0]
|
||||||
queryset = prefetcher.get_prefetch_queryset(list(Room.objects.all()))[0]
|
queryset = prefetcher.get_prefetch_queryset(list(Room.objects.all()))[0]
|
||||||
self.assertNotIn(' JOIN ', force_text(queryset.query))
|
self.assertNotIn(' JOIN ', str(queryset.query))
|
||||||
|
|
||||||
|
|
||||||
class Ticket25546Tests(TestCase):
|
class Ticket25546Tests(TestCase):
|
||||||
|
|
|
@ -33,7 +33,6 @@ from django.test import (
|
||||||
)
|
)
|
||||||
from django.test.utils import patch_logger
|
from django.test.utils import patch_logger
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
from .models import SessionStore as CustomDatabaseSession
|
from .models import SessionStore as CustomDatabaseSession
|
||||||
|
|
||||||
|
@ -388,7 +387,7 @@ class DatabaseSessionTests(SessionTestsMixin, TestCase):
|
||||||
session_key = self.session.session_key
|
session_key = self.session.session_key
|
||||||
s = self.model.objects.get(session_key=session_key)
|
s = self.model.objects.get(session_key=session_key)
|
||||||
|
|
||||||
self.assertEqual(force_text(s), session_key)
|
self.assertEqual(str(s), session_key)
|
||||||
|
|
||||||
def test_session_get_decoded(self):
|
def test_session_get_decoded(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -7,7 +7,6 @@ from django.conf import settings
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.template import Context, Template
|
from django.template import Context, Template
|
||||||
from django.test import SimpleTestCase, override_settings
|
from django.test import SimpleTestCase, override_settings
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
from .settings import TEST_SETTINGS
|
from .settings import TEST_SETTINGS
|
||||||
|
|
||||||
|
@ -20,7 +19,7 @@ class BaseStaticFilesMixin:
|
||||||
def assertFileContains(self, filepath, text):
|
def assertFileContains(self, filepath, text):
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
text,
|
text,
|
||||||
self._get_file(force_text(filepath)),
|
self._get_file(filepath),
|
||||||
"'%s' not in '%s'" % (text, filepath),
|
"'%s' not in '%s'" % (text, filepath),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ from django.test import override_settings
|
||||||
from django.test.utils import extend_sys_path
|
from django.test.utils import extend_sys_path
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils._os import symlinks_supported
|
from django.utils._os import symlinks_supported
|
||||||
from django.utils.encoding import force_text
|
|
||||||
from django.utils.functional import empty
|
from django.utils.functional import empty
|
||||||
|
|
||||||
from .cases import CollectionTestCase, StaticFilesTestCase, TestDefaults
|
from .cases import CollectionTestCase, StaticFilesTestCase, TestDefaults
|
||||||
|
@ -41,7 +40,7 @@ class TestFindStatic(TestDefaults, CollectionTestCase):
|
||||||
"""
|
"""
|
||||||
def _get_file(self, filepath):
|
def _get_file(self, filepath):
|
||||||
path = call_command('findstatic', filepath, all=False, verbosity=0, stdout=StringIO())
|
path = call_command('findstatic', filepath, all=False, verbosity=0, stdout=StringIO())
|
||||||
with codecs.open(force_text(path), "r", "utf-8") as f:
|
with codecs.open(path, "r", "utf-8") as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
def test_all_files(self):
|
def test_all_files(self):
|
||||||
|
@ -51,8 +50,8 @@ class TestFindStatic(TestDefaults, CollectionTestCase):
|
||||||
result = call_command('findstatic', 'test/file.txt', verbosity=1, stdout=StringIO())
|
result = call_command('findstatic', 'test/file.txt', verbosity=1, stdout=StringIO())
|
||||||
lines = [l.strip() for l in result.split('\n')]
|
lines = [l.strip() for l in result.split('\n')]
|
||||||
self.assertEqual(len(lines), 3) # three because there is also the "Found <file> here" line
|
self.assertEqual(len(lines), 3) # three because there is also the "Found <file> here" line
|
||||||
self.assertIn('project', force_text(lines[1]))
|
self.assertIn('project', lines[1])
|
||||||
self.assertIn('apps', force_text(lines[2]))
|
self.assertIn('apps', lines[2])
|
||||||
|
|
||||||
def test_all_files_less_verbose(self):
|
def test_all_files_less_verbose(self):
|
||||||
"""
|
"""
|
||||||
|
@ -61,8 +60,8 @@ class TestFindStatic(TestDefaults, CollectionTestCase):
|
||||||
result = call_command('findstatic', 'test/file.txt', verbosity=0, stdout=StringIO())
|
result = call_command('findstatic', 'test/file.txt', verbosity=0, stdout=StringIO())
|
||||||
lines = [l.strip() for l in result.split('\n')]
|
lines = [l.strip() for l in result.split('\n')]
|
||||||
self.assertEqual(len(lines), 2)
|
self.assertEqual(len(lines), 2)
|
||||||
self.assertIn('project', force_text(lines[0]))
|
self.assertIn('project', lines[0])
|
||||||
self.assertIn('apps', force_text(lines[1]))
|
self.assertIn('apps', lines[1])
|
||||||
|
|
||||||
def test_all_files_more_verbose(self):
|
def test_all_files_more_verbose(self):
|
||||||
"""
|
"""
|
||||||
|
@ -71,10 +70,10 @@ class TestFindStatic(TestDefaults, CollectionTestCase):
|
||||||
"""
|
"""
|
||||||
result = call_command('findstatic', 'test/file.txt', verbosity=2, stdout=StringIO())
|
result = call_command('findstatic', 'test/file.txt', verbosity=2, stdout=StringIO())
|
||||||
lines = [l.strip() for l in result.split('\n')]
|
lines = [l.strip() for l in result.split('\n')]
|
||||||
self.assertIn('project', force_text(lines[1]))
|
self.assertIn('project', lines[1])
|
||||||
self.assertIn('apps', force_text(lines[2]))
|
self.assertIn('apps', lines[2])
|
||||||
self.assertIn("Looking in the following locations:", force_text(lines[3]))
|
self.assertIn("Looking in the following locations:", lines[3])
|
||||||
searched_locations = ', '.join(force_text(x) for x in lines[4:])
|
searched_locations = ', '.join(lines[4:])
|
||||||
# AppDirectoriesFinder searched locations
|
# AppDirectoriesFinder searched locations
|
||||||
self.assertIn(os.path.join('staticfiles_tests', 'apps', 'test', 'static'), searched_locations)
|
self.assertIn(os.path.join('staticfiles_tests', 'apps', 'test', 'static'), searched_locations)
|
||||||
self.assertIn(os.path.join('staticfiles_tests', 'apps', 'no_label', 'static'), searched_locations)
|
self.assertIn(os.path.join('staticfiles_tests', 'apps', 'no_label', 'static'), searched_locations)
|
||||||
|
@ -195,7 +194,7 @@ class TestInteractiveMessages(CollectionTestCase):
|
||||||
with mock.patch('builtins.input', side_effect=self.mock_input(stdout)):
|
with mock.patch('builtins.input', side_effect=self.mock_input(stdout)):
|
||||||
call_command('collectstatic', interactive=True, clear=True, stdout=stdout)
|
call_command('collectstatic', interactive=True, clear=True, stdout=stdout)
|
||||||
|
|
||||||
output = force_text(stdout.getvalue())
|
output = stdout.getvalue()
|
||||||
self.assertNotIn(self.overwrite_warning_msg, output)
|
self.assertNotIn(self.overwrite_warning_msg, output)
|
||||||
self.assertIn(self.delete_warning_msg, output)
|
self.assertIn(self.delete_warning_msg, output)
|
||||||
|
|
||||||
|
@ -204,7 +203,7 @@ class TestInteractiveMessages(CollectionTestCase):
|
||||||
self.run_collectstatic()
|
self.run_collectstatic()
|
||||||
with mock.patch('builtins.input', side_effect=self.mock_input(stdout)):
|
with mock.patch('builtins.input', side_effect=self.mock_input(stdout)):
|
||||||
call_command('collectstatic', interactive=True, stdout=stdout)
|
call_command('collectstatic', interactive=True, stdout=stdout)
|
||||||
output = force_text(stdout.getvalue())
|
output = stdout.getvalue()
|
||||||
self.assertIn(self.overwrite_warning_msg, output)
|
self.assertIn(self.overwrite_warning_msg, output)
|
||||||
self.assertNotIn(self.delete_warning_msg, output)
|
self.assertNotIn(self.delete_warning_msg, output)
|
||||||
|
|
||||||
|
@ -212,7 +211,7 @@ class TestInteractiveMessages(CollectionTestCase):
|
||||||
stdout = StringIO()
|
stdout = StringIO()
|
||||||
shutil.rmtree(settings.STATIC_ROOT)
|
shutil.rmtree(settings.STATIC_ROOT)
|
||||||
call_command('collectstatic', interactive=True, stdout=stdout)
|
call_command('collectstatic', interactive=True, stdout=stdout)
|
||||||
output = force_text(stdout.getvalue())
|
output = stdout.getvalue()
|
||||||
self.assertNotIn(self.overwrite_warning_msg, output)
|
self.assertNotIn(self.overwrite_warning_msg, output)
|
||||||
self.assertNotIn(self.delete_warning_msg, output)
|
self.assertNotIn(self.delete_warning_msg, output)
|
||||||
self.assertIn(self.files_copied_msg, output)
|
self.assertIn(self.files_copied_msg, output)
|
||||||
|
@ -223,7 +222,7 @@ class TestInteractiveMessages(CollectionTestCase):
|
||||||
with override_settings(STATIC_ROOT=static_dir):
|
with override_settings(STATIC_ROOT=static_dir):
|
||||||
call_command('collectstatic', interactive=True, stdout=stdout)
|
call_command('collectstatic', interactive=True, stdout=stdout)
|
||||||
shutil.rmtree(static_dir)
|
shutil.rmtree(static_dir)
|
||||||
output = force_text(stdout.getvalue())
|
output = stdout.getvalue()
|
||||||
self.assertNotIn(self.overwrite_warning_msg, output)
|
self.assertNotIn(self.overwrite_warning_msg, output)
|
||||||
self.assertNotIn(self.delete_warning_msg, output)
|
self.assertNotIn(self.delete_warning_msg, output)
|
||||||
self.assertIn(self.files_copied_msg, output)
|
self.assertIn(self.files_copied_msg, output)
|
||||||
|
@ -349,7 +348,7 @@ class TestCollectionOverwriteWarning(CollectionTestCase):
|
||||||
"""
|
"""
|
||||||
out = StringIO()
|
out = StringIO()
|
||||||
call_command('collectstatic', interactive=False, verbosity=3, stdout=out, **kwargs)
|
call_command('collectstatic', interactive=False, verbosity=3, stdout=out, **kwargs)
|
||||||
return force_text(out.getvalue())
|
return out.getvalue()
|
||||||
|
|
||||||
def test_no_warning(self):
|
def test_no_warning(self):
|
||||||
"""
|
"""
|
||||||
|
@ -409,7 +408,7 @@ class TestCollectionNeverCopyStorage(CollectionTestCase):
|
||||||
"""
|
"""
|
||||||
stdout = StringIO()
|
stdout = StringIO()
|
||||||
self.run_collectstatic(stdout=stdout, verbosity=2)
|
self.run_collectstatic(stdout=stdout, verbosity=2)
|
||||||
output = force_text(stdout.getvalue())
|
output = stdout.getvalue()
|
||||||
self.assertIn("Skipping 'test.txt' (not modified)", output)
|
self.assertIn("Skipping 'test.txt' (not modified)", output)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ from django.contrib.staticfiles.management.commands.collectstatic import \
|
||||||
from django.core.cache.backends.base import BaseCache
|
from django.core.cache.backends.base import BaseCache
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
from django.utils.encoding import force_text
|
|
||||||
|
|
||||||
from .cases import CollectionTestCase
|
from .cases import CollectionTestCase
|
||||||
from .settings import TEST_ROOT
|
from .settings import TEST_ROOT
|
||||||
|
@ -380,7 +379,7 @@ class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase):
|
||||||
manifest_content = storage.staticfiles_storage.read_manifest()
|
manifest_content = storage.staticfiles_storage.read_manifest()
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
'"version": "%s"' % storage.staticfiles_storage.manifest_version,
|
'"version": "%s"' % storage.staticfiles_storage.manifest_version,
|
||||||
force_text(manifest_content)
|
manifest_content
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_parse_cache(self):
|
def test_parse_cache(self):
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from django.template.defaultfilters import slugify
|
from django.template.defaultfilters import slugify
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.utils.encoding import force_text
|
|
||||||
from django.utils.functional import lazy
|
from django.utils.functional import lazy
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
|
@ -42,7 +41,7 @@ class FunctionTests(SimpleTestCase):
|
||||||
self.assertEqual(slugify(123), '123')
|
self.assertEqual(slugify(123), '123')
|
||||||
|
|
||||||
def test_slugify_lazy_string(self):
|
def test_slugify_lazy_string(self):
|
||||||
lazy_str = lazy(lambda string: force_text(string), str)
|
lazy_str = lazy(lambda string: string, str)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
slugify(lazy_str(' Jack & Jill like numbers 1,2,3 and 4 and silly characters ?%.$!/')),
|
slugify(lazy_str(' Jack & Jill like numbers 1,2,3 and 4 and silly characters ?%.$!/')),
|
||||||
'jack-jill-like-numbers-123-and-4-and-silly-characters',
|
'jack-jill-like-numbers-123-and-4-and-silly-characters',
|
||||||
|
|
|
@ -24,7 +24,7 @@ class TestEncodingUtils(unittest.TestCase):
|
||||||
|
|
||||||
def test_force_text_lazy(self):
|
def test_force_text_lazy(self):
|
||||||
s = SimpleLazyObject(lambda: 'x')
|
s = SimpleLazyObject(lambda: 'x')
|
||||||
self.assertTrue(issubclass(type(force_text(s)), str))
|
self.assertTrue(type(force_text(s)), str)
|
||||||
|
|
||||||
def test_force_bytes_exception(self):
|
def test_force_bytes_exception(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -3,7 +3,6 @@ from datetime import datetime
|
||||||
|
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.utils import html, safestring
|
from django.utils import html, safestring
|
||||||
from django.utils.encoding import force_text
|
|
||||||
from django.utils.functional import lazystr
|
from django.utils.functional import lazystr
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,7 +98,7 @@ class TestUtilsHtml(SimpleTestCase):
|
||||||
for filename in ('strip_tags1.html', 'strip_tags2.txt'):
|
for filename in ('strip_tags1.html', 'strip_tags2.txt'):
|
||||||
path = os.path.join(os.path.dirname(__file__), 'files', filename)
|
path = os.path.join(os.path.dirname(__file__), 'files', filename)
|
||||||
with open(path, 'r') as fp:
|
with open(path, 'r') as fp:
|
||||||
content = force_text(fp.read())
|
content = fp.read()
|
||||||
start = datetime.now()
|
start = datetime.now()
|
||||||
stripped = html.strip_tags(content)
|
stripped = html.strip_tags(content)
|
||||||
elapsed = datetime.now() - start
|
elapsed = datetime.now() - start
|
||||||
|
@ -173,7 +172,7 @@ class TestUtilsHtml(SimpleTestCase):
|
||||||
html_obj = HtmlClass()
|
html_obj = HtmlClass()
|
||||||
self.assertTrue(hasattr(HtmlClass, '__html__'))
|
self.assertTrue(hasattr(HtmlClass, '__html__'))
|
||||||
self.assertTrue(hasattr(html_obj, '__html__'))
|
self.assertTrue(hasattr(html_obj, '__html__'))
|
||||||
self.assertEqual(force_text(html_obj), html_obj.__html__())
|
self.assertEqual(str(html_obj), html_obj.__html__())
|
||||||
|
|
||||||
def test_html_safe_subclass(self):
|
def test_html_safe_subclass(self):
|
||||||
class BaseClass:
|
class BaseClass:
|
||||||
|
@ -191,7 +190,7 @@ class TestUtilsHtml(SimpleTestCase):
|
||||||
return 'some html safe content'
|
return 'some html safe content'
|
||||||
|
|
||||||
subclass_obj = Subclass()
|
subclass_obj = Subclass()
|
||||||
self.assertEqual(force_text(subclass_obj), subclass_obj.__html__())
|
self.assertEqual(str(subclass_obj), subclass_obj.__html__())
|
||||||
|
|
||||||
def test_html_safe_defines_html_error(self):
|
def test_html_safe_defines_html_error(self):
|
||||||
msg = "can't apply @html_safe to HtmlClass because it defines __html__()."
|
msg = "can't apply @html_safe to HtmlClass because it defines __html__()."
|
||||||
|
|
|
@ -14,7 +14,7 @@ from django.template import TemplateDoesNotExist
|
||||||
from django.test import RequestFactory, SimpleTestCase, override_settings
|
from django.test import RequestFactory, SimpleTestCase, override_settings
|
||||||
from django.test.utils import LoggingCaptureMixin, patch_logger
|
from django.test.utils import LoggingCaptureMixin, patch_logger
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.encoding import force_bytes, force_text
|
from django.utils.encoding import force_bytes
|
||||||
from django.utils.functional import SimpleLazyObject
|
from django.utils.functional import SimpleLazyObject
|
||||||
from django.views.debug import (
|
from django.views.debug import (
|
||||||
CLEANSED_SUBSTITUTE, CallableSettingWrapper, ExceptionReporter,
|
CLEANSED_SUBSTITUTE, CallableSettingWrapper, ExceptionReporter,
|
||||||
|
@ -740,14 +740,14 @@ class ExceptionReportTestMixin:
|
||||||
email = mail.outbox[0]
|
email = mail.outbox[0]
|
||||||
|
|
||||||
# Frames vars are never shown in plain text email reports.
|
# Frames vars are never shown in plain text email reports.
|
||||||
body_plain = force_text(email.body)
|
body_plain = str(email.body)
|
||||||
self.assertNotIn('cooked_eggs', body_plain)
|
self.assertNotIn('cooked_eggs', body_plain)
|
||||||
self.assertNotIn('scrambled', body_plain)
|
self.assertNotIn('scrambled', body_plain)
|
||||||
self.assertNotIn('sauce', body_plain)
|
self.assertNotIn('sauce', body_plain)
|
||||||
self.assertNotIn('worcestershire', body_plain)
|
self.assertNotIn('worcestershire', body_plain)
|
||||||
|
|
||||||
# Frames vars are shown in html email reports.
|
# Frames vars are shown in html email reports.
|
||||||
body_html = force_text(email.alternatives[0][0])
|
body_html = str(email.alternatives[0][0])
|
||||||
self.assertIn('cooked_eggs', body_html)
|
self.assertIn('cooked_eggs', body_html)
|
||||||
self.assertIn('scrambled', body_html)
|
self.assertIn('scrambled', body_html)
|
||||||
self.assertIn('sauce', body_html)
|
self.assertIn('sauce', body_html)
|
||||||
|
@ -773,14 +773,14 @@ class ExceptionReportTestMixin:
|
||||||
email = mail.outbox[0]
|
email = mail.outbox[0]
|
||||||
|
|
||||||
# Frames vars are never shown in plain text email reports.
|
# Frames vars are never shown in plain text email reports.
|
||||||
body_plain = force_text(email.body)
|
body_plain = str(email.body)
|
||||||
self.assertNotIn('cooked_eggs', body_plain)
|
self.assertNotIn('cooked_eggs', body_plain)
|
||||||
self.assertNotIn('scrambled', body_plain)
|
self.assertNotIn('scrambled', body_plain)
|
||||||
self.assertNotIn('sauce', body_plain)
|
self.assertNotIn('sauce', body_plain)
|
||||||
self.assertNotIn('worcestershire', body_plain)
|
self.assertNotIn('worcestershire', body_plain)
|
||||||
|
|
||||||
# Frames vars are shown in html email reports.
|
# Frames vars are shown in html email reports.
|
||||||
body_html = force_text(email.alternatives[0][0])
|
body_html = str(email.alternatives[0][0])
|
||||||
self.assertIn('cooked_eggs', body_html)
|
self.assertIn('cooked_eggs', body_html)
|
||||||
self.assertIn('scrambled', body_html)
|
self.assertIn('scrambled', body_html)
|
||||||
self.assertIn('sauce', body_html)
|
self.assertIn('sauce', body_html)
|
||||||
|
@ -812,7 +812,7 @@ class ExceptionReportTestMixin:
|
||||||
self.assertEqual(len(mail.outbox), 1)
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
email = mail.outbox[0]
|
email = mail.outbox[0]
|
||||||
# Frames vars are never shown in plain text email reports.
|
# Frames vars are never shown in plain text email reports.
|
||||||
body = force_text(email.body)
|
body = str(email.body)
|
||||||
self.assertNotIn('cooked_eggs', body)
|
self.assertNotIn('cooked_eggs', body)
|
||||||
self.assertNotIn('scrambled', body)
|
self.assertNotIn('scrambled', body)
|
||||||
self.assertNotIn('sauce', body)
|
self.assertNotIn('sauce', body)
|
||||||
|
|
Loading…
Reference in New Issue