Used 4 space hanging indent for dictionaries.
Thanks Mariusz Felisiak for auditing.
This commit is contained in:
parent
5bbf31634f
commit
0004daa536
|
@ -2087,9 +2087,11 @@ class InlineModelAdmin(BaseModelAdmin):
|
|||
'class_name': p._meta.verbose_name,
|
||||
'instance': p}
|
||||
)
|
||||
params = {'class_name': self._meta.model._meta.verbose_name,
|
||||
params = {
|
||||
'class_name': self._meta.model._meta.verbose_name,
|
||||
'instance': self.instance,
|
||||
'related_objects': get_text_list(objs, _('and'))}
|
||||
'related_objects': get_text_list(objs, _('and')),
|
||||
}
|
||||
msg = _("Deleting %(class_name)s %(instance)s would require "
|
||||
"deleting the following protected related objects: "
|
||||
"%(related_objects)s")
|
||||
|
|
|
@ -36,10 +36,12 @@ def paginator_number(cl, i):
|
|||
elif i == cl.page_num:
|
||||
return format_html('<span class="this-page">{}</span> ', i + 1)
|
||||
else:
|
||||
return format_html('<a href="{}"{}>{}</a> ',
|
||||
return format_html(
|
||||
'<a href="{}"{}>{}</a> ',
|
||||
cl.get_query_string({PAGE_VAR: i}),
|
||||
mark_safe(' class="end"' if i == cl.paginator.num_pages - 1 else ''),
|
||||
i + 1)
|
||||
i + 1,
|
||||
)
|
||||
|
||||
|
||||
def pagination(cl):
|
||||
|
@ -190,8 +192,7 @@ def result_headers(cl):
|
|||
|
||||
|
||||
def _boolean_icon(field_val):
|
||||
icon_url = static('admin/img/icon-%s.svg' %
|
||||
{True: 'yes', False: 'no', None: 'unknown'}[field_val])
|
||||
icon_url = static('admin/img/icon-%s.svg' % {True: 'yes', False: 'no', None: 'unknown'}[field_val])
|
||||
return format_html('<img src="{}" alt="{}">', icon_url, field_val)
|
||||
|
||||
|
||||
|
@ -279,11 +280,7 @@ def items_for_result(cl, result, form):
|
|||
) if cl.is_popup else '',
|
||||
result_repr)
|
||||
|
||||
yield format_html('<{}{}>{}</{}>',
|
||||
table_tag,
|
||||
row_class,
|
||||
link_or_text,
|
||||
table_tag)
|
||||
yield format_html('<{}{}>{}</{}>', table_tag, row_class, link_or_text, table_tag)
|
||||
else:
|
||||
# By default the fields come from ModelAdmin.list_editable, but if we pull
|
||||
# the fields out of the form instead of list_editable custom admins
|
||||
|
@ -334,11 +331,13 @@ def result_list(cl):
|
|||
for h in headers:
|
||||
if h['sortable'] and h['sorted']:
|
||||
num_sorted_fields += 1
|
||||
return {'cl': cl,
|
||||
return {
|
||||
'cl': cl,
|
||||
'result_hidden_fields': list(result_hidden_fields(cl)),
|
||||
'result_headers': headers,
|
||||
'num_sorted_fields': num_sorted_fields,
|
||||
'results': list(results(cl))}
|
||||
'results': list(results(cl)),
|
||||
}
|
||||
|
||||
|
||||
@register.tag(name='result_list')
|
||||
|
|
|
@ -44,8 +44,9 @@ class UserAdmin(admin.ModelAdmin):
|
|||
fieldsets = (
|
||||
(None, {'fields': ('username', 'password')}),
|
||||
(_('Personal info'), {'fields': ('first_name', 'last_name', 'email')}),
|
||||
(_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser',
|
||||
'groups', 'user_permissions')}),
|
||||
(_('Permissions'), {
|
||||
'fields': ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions'),
|
||||
}),
|
||||
(_('Important dates'), {'fields': ('last_login', 'date_joined')}),
|
||||
)
|
||||
add_fieldsets = (
|
||||
|
|
|
@ -86,7 +86,8 @@ class GeoModelAdmin(ModelAdmin):
|
|||
wms_options = ["%s: '%s'" % pair for pair in self.wms_options.items()]
|
||||
wms_options = ', %s' % ', '.join(wms_options)
|
||||
|
||||
params = {'default_lon': self.default_lon,
|
||||
params = {
|
||||
'default_lon': self.default_lon,
|
||||
'default_lat': self.default_lat,
|
||||
'default_zoom': self.default_zoom,
|
||||
'display_wkt': self.debug or self.display_wkt,
|
||||
|
|
|
@ -696,7 +696,8 @@ class MultiPolygon(GeometryCollection):
|
|||
|
||||
|
||||
# Class mapping dictionary (using the OGRwkbGeometryType as the key)
|
||||
GEO_CLASSES = {1: Point,
|
||||
GEO_CLASSES = {
|
||||
1: Point,
|
||||
2: LineString,
|
||||
3: Polygon,
|
||||
4: MultiPoint,
|
||||
|
|
|
@ -7,7 +7,8 @@ class OGRGeomType:
|
|||
wkb25bit = -2147483648
|
||||
|
||||
# Dictionary of acceptable OGRwkbGeometryType s and their string names.
|
||||
_types = {0: 'Unknown',
|
||||
_types = {
|
||||
0: 'Unknown',
|
||||
1: 'Point',
|
||||
2: 'LineString',
|
||||
3: 'Polygon',
|
||||
|
|
|
@ -48,14 +48,14 @@ class LayerMapping:
|
|||
"A class that maps OGR Layers to GeoDjango Models."
|
||||
|
||||
# Acceptable 'base' types for a multi-geometry type.
|
||||
MULTI_TYPES = {1: OGRGeomType('MultiPoint'),
|
||||
MULTI_TYPES = {
|
||||
1: OGRGeomType('MultiPoint'),
|
||||
2: OGRGeomType('MultiLineString'),
|
||||
3: OGRGeomType('MultiPolygon'),
|
||||
OGRGeomType('Point25D').num: OGRGeomType('MultiPoint25D'),
|
||||
OGRGeomType('LineString25D').num: OGRGeomType('MultiLineString25D'),
|
||||
OGRGeomType('Polygon25D').num: OGRGeomType('MultiPolygon25D'),
|
||||
}
|
||||
|
||||
# Acceptable Django field types and corresponding acceptable OGR
|
||||
# counterparts.
|
||||
FIELD_TYPES = {
|
||||
|
|
|
@ -53,12 +53,12 @@ def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None,
|
|||
|
||||
# Initializing the keyword arguments dictionary for both PostGIS
|
||||
# and SpatiaLite.
|
||||
kwargs = {'srid': srs.srid,
|
||||
kwargs = {
|
||||
'srid': srs.srid,
|
||||
'auth_name': auth_name,
|
||||
'auth_srid': auth_srid or srs.srid,
|
||||
'proj4text': srs.proj4,
|
||||
}
|
||||
|
||||
# Backend-specific fields for the SpatialRefSys model.
|
||||
srs_field_names = {f.name for f in SpatialRefSys._meta.get_fields()}
|
||||
if 'srtext' in srs_field_names:
|
||||
|
|
|
@ -854,9 +854,11 @@ class Field(RegisterLookupMixin):
|
|||
|
||||
def formfield(self, form_class=None, choices_form_class=None, **kwargs):
|
||||
"""Return a django.forms.Field instance for this field."""
|
||||
defaults = {'required': not self.blank,
|
||||
defaults = {
|
||||
'required': not self.blank,
|
||||
'label': capfirst(self.verbose_name),
|
||||
'help_text': self.help_text}
|
||||
'help_text': self.help_text,
|
||||
}
|
||||
if self.has_default():
|
||||
if callable(self.default):
|
||||
defaults['initial'] = self.default
|
||||
|
|
|
@ -427,11 +427,17 @@ def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False,
|
|||
# limit is simply max_num + DEFAULT_MAX_NUM (which is 2*DEFAULT_MAX_NUM
|
||||
# if max_num is None in the first place)
|
||||
absolute_max = max_num + DEFAULT_MAX_NUM
|
||||
attrs = {'form': form, 'extra': extra,
|
||||
'can_order': can_order, 'can_delete': can_delete,
|
||||
'min_num': min_num, 'max_num': max_num,
|
||||
'absolute_max': absolute_max, 'validate_min': validate_min,
|
||||
'validate_max': validate_max}
|
||||
attrs = {
|
||||
'form': form,
|
||||
'extra': extra,
|
||||
'can_order': can_order,
|
||||
'can_delete': can_delete,
|
||||
'min_num': min_num,
|
||||
'max_num': max_num,
|
||||
'absolute_max': absolute_max,
|
||||
'validate_min': validate_min,
|
||||
'validate_max': validate_max,
|
||||
}
|
||||
return type(form.__name__ + 'FormSet', (formset,), attrs)
|
||||
|
||||
|
||||
|
|
|
@ -399,7 +399,8 @@ class SpacelessNode(Node):
|
|||
|
||||
|
||||
class TemplateTagNode(Node):
|
||||
mapping = {'openblock': BLOCK_TAG_START,
|
||||
mapping = {
|
||||
'openblock': BLOCK_TAG_START,
|
||||
'closeblock': BLOCK_TAG_END,
|
||||
'openvariable': VARIABLE_TAG_START,
|
||||
'closevariable': VARIABLE_TAG_END,
|
||||
|
|
|
@ -198,8 +198,10 @@ class RssFeed(SyndicationFeed):
|
|||
handler.endElement("rss")
|
||||
|
||||
def rss_attributes(self):
|
||||
return {"version": self._version,
|
||||
"xmlns:atom": "http://www.w3.org/2005/Atom"}
|
||||
return {
|
||||
'version': self._version,
|
||||
'xmlns:atom': 'http://www.w3.org/2005/Atom',
|
||||
}
|
||||
|
||||
def write_items(self, handler):
|
||||
for item in self.items:
|
||||
|
|
|
@ -322,8 +322,10 @@ class ListFiltersTests(TestCase):
|
|||
request.user = self.alfred
|
||||
changelist = modeladmin.get_changelist(request)
|
||||
|
||||
request = self.request_factory.get('/', {'date_registered__gte': self.today,
|
||||
'date_registered__lt': self.tomorrow})
|
||||
request = self.request_factory.get('/', {
|
||||
'date_registered__gte': self.today,
|
||||
'date_registered__lt': self.tomorrow},
|
||||
)
|
||||
request.user = self.alfred
|
||||
changelist = modeladmin.get_changelist_instance(request)
|
||||
|
||||
|
@ -344,8 +346,10 @@ class ListFiltersTests(TestCase):
|
|||
)
|
||||
)
|
||||
|
||||
request = self.request_factory.get('/', {'date_registered__gte': self.today.replace(day=1),
|
||||
'date_registered__lt': self.next_month})
|
||||
request = self.request_factory.get('/', {
|
||||
'date_registered__gte': self.today.replace(day=1),
|
||||
'date_registered__lt': self.next_month},
|
||||
)
|
||||
request.user = self.alfred
|
||||
changelist = modeladmin.get_changelist_instance(request)
|
||||
|
||||
|
@ -370,8 +374,10 @@ class ListFiltersTests(TestCase):
|
|||
)
|
||||
)
|
||||
|
||||
request = self.request_factory.get('/', {'date_registered__gte': self.today.replace(month=1, day=1),
|
||||
'date_registered__lt': self.next_year})
|
||||
request = self.request_factory.get('/', {
|
||||
'date_registered__gte': self.today.replace(month=1, day=1),
|
||||
'date_registered__lt': self.next_year},
|
||||
)
|
||||
request.user = self.alfred
|
||||
changelist = modeladmin.get_changelist_instance(request)
|
||||
|
||||
|
|
|
@ -730,16 +730,20 @@ class RelatedPrepopulatedInline1(admin.StackedInline):
|
|||
model = RelatedPrepopulated
|
||||
extra = 1
|
||||
autocomplete_fields = ['fk', 'm2m']
|
||||
prepopulated_fields = {'slug1': ['name', 'pubdate'],
|
||||
'slug2': ['status', 'name']}
|
||||
prepopulated_fields = {
|
||||
'slug1': ['name', 'pubdate'],
|
||||
'slug2': ['status', 'name'],
|
||||
}
|
||||
|
||||
|
||||
class RelatedPrepopulatedInline2(admin.TabularInline):
|
||||
model = RelatedPrepopulated
|
||||
extra = 1
|
||||
autocomplete_fields = ['fk', 'm2m']
|
||||
prepopulated_fields = {'slug1': ['name', 'pubdate'],
|
||||
'slug2': ['status', 'name']}
|
||||
prepopulated_fields = {
|
||||
'slug1': ['name', 'pubdate'],
|
||||
'slug2': ['status', 'name'],
|
||||
}
|
||||
|
||||
|
||||
class RelatedPrepopulatedInline3(admin.TabularInline):
|
||||
|
|
|
@ -1650,11 +1650,12 @@ class AdminViewPermissionsTest(TestCase):
|
|||
|
||||
def test_add_view(self):
|
||||
"""Test add view restricts access and actually adds items."""
|
||||
add_dict = {'title': 'Døm ikke',
|
||||
add_dict = {
|
||||
'title': 'Døm ikke',
|
||||
'content': '<p>great article</p>',
|
||||
'date_0': '2008-03-18', 'date_1': '10:54:39',
|
||||
'section': self.s1.pk}
|
||||
|
||||
'section': self.s1.pk,
|
||||
}
|
||||
# Change User should not have access to add articles
|
||||
self.client.force_login(self.changeuser)
|
||||
# make sure the view removes test cookie
|
||||
|
@ -1754,10 +1755,12 @@ class AdminViewPermissionsTest(TestCase):
|
|||
|
||||
def test_change_view(self):
|
||||
"""Change view should restrict access and allow users to edit items."""
|
||||
change_dict = {'title': 'Ikke fordømt',
|
||||
change_dict = {
|
||||
'title': 'Ikke fordømt',
|
||||
'content': '<p>edited article</p>',
|
||||
'date_0': '2008-03-18', 'date_1': '10:54:39',
|
||||
'section': self.s1.pk}
|
||||
'section': self.s1.pk,
|
||||
}
|
||||
article_change_url = reverse('admin:admin_views_article_change', args=(self.a1.pk,))
|
||||
article_changelist_url = reverse('admin:admin_views_article_changelist')
|
||||
|
||||
|
@ -6023,15 +6026,16 @@ class AdminViewOnSiteTests(TestCase):
|
|||
# The form validation should fail because 'some_required_info' is
|
||||
# not included on the parent form, and the family_name of the parent
|
||||
# does not match that of the child
|
||||
post_data = {"family_name": "Test1",
|
||||
"dependentchild_set-TOTAL_FORMS": "1",
|
||||
"dependentchild_set-INITIAL_FORMS": "0",
|
||||
"dependentchild_set-MAX_NUM_FORMS": "1",
|
||||
"dependentchild_set-0-id": "",
|
||||
"dependentchild_set-0-parent": "",
|
||||
"dependentchild_set-0-family_name": "Test2"}
|
||||
response = self.client.post(reverse('admin:admin_views_parentwithdependentchildren_add'),
|
||||
post_data)
|
||||
post_data = {
|
||||
'family_name': 'Test1',
|
||||
'dependentchild_set-TOTAL_FORMS': '1',
|
||||
'dependentchild_set-INITIAL_FORMS': '0',
|
||||
'dependentchild_set-MAX_NUM_FORMS': '1',
|
||||
'dependentchild_set-0-id': '',
|
||||
'dependentchild_set-0-parent': '',
|
||||
'dependentchild_set-0-family_name': 'Test2',
|
||||
}
|
||||
response = self.client.post(reverse('admin:admin_views_parentwithdependentchildren_add'), post_data)
|
||||
self.assertFormError(response, 'adminform', 'some_required_info', ['This field is required.'])
|
||||
msg = "The form 'adminform' in context 0 does not contain the non-field error 'Error'"
|
||||
with self.assertRaisesMessage(AssertionError, msg):
|
||||
|
@ -6050,18 +6054,19 @@ class AdminViewOnSiteTests(TestCase):
|
|||
Verifying that if the parent form fails validation, the inlines also
|
||||
run validation even if validation is contingent on parent form data
|
||||
"""
|
||||
pwdc = ParentWithDependentChildren.objects.create(some_required_info=6,
|
||||
family_name="Test1")
|
||||
pwdc = ParentWithDependentChildren.objects.create(some_required_info=6, family_name='Test1')
|
||||
# The form validation should fail because 'some_required_info' is
|
||||
# not included on the parent form, and the family_name of the parent
|
||||
# does not match that of the child
|
||||
post_data = {"family_name": "Test2",
|
||||
"dependentchild_set-TOTAL_FORMS": "1",
|
||||
"dependentchild_set-INITIAL_FORMS": "0",
|
||||
"dependentchild_set-MAX_NUM_FORMS": "1",
|
||||
"dependentchild_set-0-id": "",
|
||||
"dependentchild_set-0-parent": str(pwdc.id),
|
||||
"dependentchild_set-0-family_name": "Test1"}
|
||||
post_data = {
|
||||
'family_name': 'Test2',
|
||||
'dependentchild_set-TOTAL_FORMS': '1',
|
||||
'dependentchild_set-INITIAL_FORMS': '0',
|
||||
'dependentchild_set-MAX_NUM_FORMS': '1',
|
||||
'dependentchild_set-0-id': '',
|
||||
'dependentchild_set-0-parent': str(pwdc.id),
|
||||
'dependentchild_set-0-family_name': 'Test1',
|
||||
}
|
||||
response = self.client.post(
|
||||
reverse('admin:admin_views_parentwithdependentchildren_change', args=(pwdc.id,)), post_data
|
||||
)
|
||||
|
|
|
@ -53,15 +53,19 @@ class DumpDataAssertMixin:
|
|||
use_base_manager=False, exclude_list=[], primary_keys=''):
|
||||
new_io = StringIO()
|
||||
filename = filename and os.path.join(tempfile.gettempdir(), filename)
|
||||
management.call_command('dumpdata', *args, **{'format': format,
|
||||
'stdout': new_io,
|
||||
'stderr': new_io,
|
||||
'output': filename,
|
||||
'use_natural_foreign_keys': natural_foreign_keys,
|
||||
'use_natural_primary_keys': natural_primary_keys,
|
||||
'use_base_manager': use_base_manager,
|
||||
'exclude': exclude_list,
|
||||
'primary_keys': primary_keys})
|
||||
management.call_command(
|
||||
'dumpdata',
|
||||
*args,
|
||||
format=format,
|
||||
stdout=new_io,
|
||||
stderr=new_io,
|
||||
output=filename,
|
||||
use_natural_foreign_keys=natural_foreign_keys,
|
||||
use_natural_primary_keys=natural_primary_keys,
|
||||
use_base_manager=use_base_manager,
|
||||
exclude=exclude_list,
|
||||
primary_keys=primary_keys,
|
||||
)
|
||||
if filename:
|
||||
with open(filename, "r") as f:
|
||||
command_output = f.read()
|
||||
|
|
|
@ -2872,8 +2872,14 @@ Good luck picking a username that doesn't already exist.</p>
|
|||
self.assertEqual(form.errors, {'name': ['bad value not allowed']})
|
||||
form = NameForm(data={'name': ['should be overly', 'long for the field names']})
|
||||
self.assertFalse(form.is_valid())
|
||||
self.assertEqual(form.errors, {'name': ['Ensure this value has at most 10 characters (it has 16).',
|
||||
'Ensure this value has at most 10 characters (it has 24).']})
|
||||
self.assertEqual(
|
||||
form.errors, {
|
||||
'name': [
|
||||
'Ensure this value has at most 10 characters (it has 16).',
|
||||
'Ensure this value has at most 10 characters (it has 24).',
|
||||
],
|
||||
}
|
||||
)
|
||||
form = NameForm(data={'name': ['fname', 'lname']})
|
||||
self.assertTrue(form.is_valid())
|
||||
self.assertEqual(form.cleaned_data, {'name': 'fname lname'})
|
||||
|
|
|
@ -2,6 +2,7 @@ from django.contrib.gis.sitemaps import KMLSitemap, KMZSitemap
|
|||
|
||||
from .models import City, Country
|
||||
|
||||
sitemaps = {'kml': KMLSitemap([City, Country]),
|
||||
sitemaps = {
|
||||
'kml': KMLSitemap([City, Country]),
|
||||
'kmz': KMZSitemap([City, Country]),
|
||||
}
|
||||
|
|
|
@ -365,13 +365,15 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
|
|||
if oracle:
|
||||
# SELECT SDO_UTIL.TO_WKTGEOMETRY(SDO_GEOM.SDO_POINTONSURFACE(GEOAPP_COUNTRY.MPOLY, 0.05))
|
||||
# FROM GEOAPP_COUNTRY;
|
||||
ref = {'New Zealand': fromstr('POINT (174.616364 -36.100861)', srid=4326),
|
||||
ref = {
|
||||
'New Zealand': fromstr('POINT (174.616364 -36.100861)', srid=4326),
|
||||
'Texas': fromstr('POINT (-103.002434 36.500397)', srid=4326),
|
||||
}
|
||||
else:
|
||||
# Using GEOSGeometry to compute the reference point on surface values
|
||||
# -- since PostGIS also uses GEOS these should be the same.
|
||||
ref = {'New Zealand': Country.objects.get(name='New Zealand').mpoly.point_on_surface,
|
||||
ref = {
|
||||
'New Zealand': Country.objects.get(name='New Zealand').mpoly.point_on_surface,
|
||||
'Texas': Country.objects.get(name='Texas').mpoly.point_on_surface
|
||||
}
|
||||
|
||||
|
|
|
@ -66,11 +66,11 @@ class GeographyTest(TestCase):
|
|||
# Getting the shapefile and mapping dictionary.
|
||||
shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'data'))
|
||||
co_shp = os.path.join(shp_path, 'counties', 'counties.shp')
|
||||
co_mapping = {'name': 'Name',
|
||||
co_mapping = {
|
||||
'name': 'Name',
|
||||
'state': 'State',
|
||||
'mpoly': 'MULTIPOLYGON',
|
||||
}
|
||||
|
||||
# Reference county names, number of polygons, and state names.
|
||||
names = ['Bexar', 'Galveston', 'Harris', 'Honolulu', 'Pueblo']
|
||||
num_polys = [1, 2, 1, 19, 1] # Number of polygons for each.
|
||||
|
|
|
@ -77,18 +77,21 @@ co_mapping = {
|
|||
'mpoly': 'MULTIPOLYGON', # Will convert POLYGON features into MULTIPOLYGONS.
|
||||
}
|
||||
|
||||
cofeat_mapping = {'name': 'Name',
|
||||
cofeat_mapping = {
|
||||
'name': 'Name',
|
||||
'poly': 'POLYGON',
|
||||
}
|
||||
|
||||
city_mapping = {'name': 'Name',
|
||||
city_mapping = {
|
||||
'name': 'Name',
|
||||
'population': 'Population',
|
||||
'density': 'Density',
|
||||
'dt': 'Created',
|
||||
'point': 'POINT',
|
||||
}
|
||||
|
||||
inter_mapping = {'name': 'Name',
|
||||
inter_mapping = {
|
||||
'name': 'Name',
|
||||
'length': 'Length',
|
||||
'path': 'LINESTRING',
|
||||
}
|
||||
|
|
|
@ -261,13 +261,13 @@ class LayerMapTest(TestCase):
|
|||
|
||||
def test_model_inheritance(self):
|
||||
"Tests LayerMapping on inherited models. See #12093."
|
||||
icity_mapping = {'name': 'Name',
|
||||
icity_mapping = {
|
||||
'name': 'Name',
|
||||
'population': 'Population',
|
||||
'density': 'Density',
|
||||
'point': 'POINT',
|
||||
'dt': 'Created',
|
||||
}
|
||||
|
||||
# Parent model has geometry field.
|
||||
lm1 = LayerMapping(ICity1, city_shp, icity_mapping)
|
||||
lm1.save()
|
||||
|
|
|
@ -163,10 +163,10 @@ class IntrospectionTests(TransactionTestCase):
|
|||
def test_get_key_columns(self):
|
||||
with connection.cursor() as cursor:
|
||||
key_columns = connection.introspection.get_key_columns(cursor, Article._meta.db_table)
|
||||
self.assertEqual(
|
||||
set(key_columns),
|
||||
{('reporter_id', Reporter._meta.db_table, 'id'),
|
||||
('response_to_id', Article._meta.db_table, 'id')})
|
||||
self.assertEqual(set(key_columns), {
|
||||
('reporter_id', Reporter._meta.db_table, 'id'),
|
||||
('response_to_id', Article._meta.db_table, 'id'),
|
||||
})
|
||||
|
||||
def test_get_primary_key_column(self):
|
||||
with connection.cursor() as cursor:
|
||||
|
|
|
@ -537,9 +537,10 @@ format=%(message)s
|
|||
self.temp_file = NamedTemporaryFile()
|
||||
self.temp_file.write(logging_conf.encode())
|
||||
self.temp_file.flush()
|
||||
sdict = {'LOGGING_CONFIG': '"logging.config.fileConfig"',
|
||||
'LOGGING': 'r"%s"' % self.temp_file.name}
|
||||
self.write_settings('settings.py', sdict=sdict)
|
||||
self.write_settings('settings.py', sdict={
|
||||
'LOGGING_CONFIG': '"logging.config.fileConfig"',
|
||||
'LOGGING': 'r"%s"' % self.temp_file.name,
|
||||
})
|
||||
|
||||
def tearDown(self):
|
||||
self.temp_file.close()
|
||||
|
|
|
@ -323,9 +323,13 @@ class MailTests(HeadersCheckMixin, SimpleTestCase):
|
|||
)
|
||||
|
||||
def test_unicode_headers(self):
|
||||
email = EmailMessage("Gżegżółka", "Content", "from@example.com", ["to@example.com"],
|
||||
headers={"Sender": '"Firstname Sürname" <sender@example.com>',
|
||||
"Comments": 'My Sürname is non-ASCII'})
|
||||
email = EmailMessage(
|
||||
'Gżegżółka', 'Content', 'from@example.com', ['to@example.com'],
|
||||
headers={
|
||||
'Sender': '"Firstname Sürname" <sender@example.com>',
|
||||
'Comments': 'My Sürname is non-ASCII',
|
||||
},
|
||||
)
|
||||
message = email.message()
|
||||
self.assertEqual(message['Subject'], '=?utf-8?b?R8W8ZWfFvMOzxYJrYQ==?=')
|
||||
self.assertEqual(message['Sender'], '=?utf-8?q?Firstname_S=C3=BCrname?= <sender@example.com>')
|
||||
|
|
|
@ -1297,9 +1297,11 @@ class ModelFormBasicTests(TestCase):
|
|||
|
||||
def test_basic_creation(self):
|
||||
self.assertEqual(Category.objects.count(), 0)
|
||||
f = BaseCategoryForm({'name': 'Entertainment',
|
||||
f = BaseCategoryForm({
|
||||
'name': 'Entertainment',
|
||||
'slug': 'entertainment',
|
||||
'url': 'entertainment'})
|
||||
'url': 'entertainment',
|
||||
})
|
||||
self.assertTrue(f.is_valid())
|
||||
self.assertEqual(f.cleaned_data['name'], 'Entertainment')
|
||||
self.assertEqual(f.cleaned_data['slug'], 'entertainment')
|
||||
|
@ -1712,15 +1714,23 @@ class ModelMultipleChoiceFieldTests(TestCase):
|
|||
person1 = Writer.objects.create(name="Person 1")
|
||||
person2 = Writer.objects.create(name="Person 2")
|
||||
|
||||
form = WriterForm(initial={'persons': [person1, person2]},
|
||||
data={'initial-persons': [str(person1.pk), str(person2.pk)],
|
||||
'persons': [str(person1.pk), str(person2.pk)]})
|
||||
form = WriterForm(
|
||||
initial={'persons': [person1, person2]},
|
||||
data={
|
||||
'initial-persons': [str(person1.pk), str(person2.pk)],
|
||||
'persons': [str(person1.pk), str(person2.pk)],
|
||||
},
|
||||
)
|
||||
self.assertTrue(form.is_valid())
|
||||
self.assertFalse(form.has_changed())
|
||||
|
||||
form = WriterForm(initial={'persons': [person1, person2]},
|
||||
data={'initial-persons': [str(person1.pk), str(person2.pk)],
|
||||
'persons': [str(person2.pk)]})
|
||||
form = WriterForm(
|
||||
initial={'persons': [person1, person2]},
|
||||
data={
|
||||
'initial-persons': [str(person1.pk), str(person2.pk)],
|
||||
'persons': [str(person2.pk)],
|
||||
},
|
||||
)
|
||||
self.assertTrue(form.is_valid())
|
||||
self.assertTrue(form.has_changed())
|
||||
|
||||
|
|
|
@ -296,10 +296,12 @@ class FormsetTests(TestCase):
|
|||
|
||||
def test_extraneous_query_is_not_run(self):
|
||||
Formset = modelformset_factory(Network, fields="__all__")
|
||||
data = {'test-TOTAL_FORMS': '1',
|
||||
data = {
|
||||
'test-TOTAL_FORMS': '1',
|
||||
'test-INITIAL_FORMS': '0',
|
||||
'test-MAX_NUM_FORMS': '',
|
||||
'test-0-name': 'Random Place'}
|
||||
'test-0-name': 'Random Place',
|
||||
}
|
||||
with self.assertNumQueries(1):
|
||||
formset = Formset(data, prefix="test")
|
||||
formset.save()
|
||||
|
|
|
@ -238,10 +238,12 @@ class RequestsTests(SimpleTestCase):
|
|||
|
||||
def test_stream(self):
|
||||
payload = FakePayload('name=value')
|
||||
request = WSGIRequest({'REQUEST_METHOD': 'POST',
|
||||
request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': payload})
|
||||
'wsgi.input': payload},
|
||||
)
|
||||
self.assertEqual(request.read(), b'name=value')
|
||||
|
||||
def test_read_after_value(self):
|
||||
|
@ -250,10 +252,12 @@ class RequestsTests(SimpleTestCase):
|
|||
POST or body.
|
||||
"""
|
||||
payload = FakePayload('name=value')
|
||||
request = WSGIRequest({'REQUEST_METHOD': 'POST',
|
||||
request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': payload})
|
||||
'wsgi.input': payload,
|
||||
})
|
||||
self.assertEqual(request.POST, {'name': ['value']})
|
||||
self.assertEqual(request.body, b'name=value')
|
||||
self.assertEqual(request.read(), b'name=value')
|
||||
|
@ -264,10 +268,12 @@ class RequestsTests(SimpleTestCase):
|
|||
from request.
|
||||
"""
|
||||
payload = FakePayload('name=value')
|
||||
request = WSGIRequest({'REQUEST_METHOD': 'POST',
|
||||
request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': payload})
|
||||
'wsgi.input': payload,
|
||||
})
|
||||
self.assertEqual(request.read(2), b'na')
|
||||
with self.assertRaises(RawPostDataException):
|
||||
request.body
|
||||
|
@ -310,10 +316,12 @@ class RequestsTests(SimpleTestCase):
|
|||
'value',
|
||||
'--boundary--'
|
||||
'']))
|
||||
request = WSGIRequest({'REQUEST_METHOD': 'POST',
|
||||
request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'multipart/form-data; boundary=boundary',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': payload})
|
||||
'wsgi.input': payload,
|
||||
})
|
||||
self.assertEqual(request.POST, {'name': ['value']})
|
||||
with self.assertRaises(RawPostDataException):
|
||||
request.body
|
||||
|
@ -334,10 +342,12 @@ class RequestsTests(SimpleTestCase):
|
|||
b'--boundary--'
|
||||
b''])
|
||||
payload = FakePayload(payload_data)
|
||||
request = WSGIRequest({'REQUEST_METHOD': 'POST',
|
||||
request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'multipart/related; boundary=boundary',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': payload})
|
||||
'wsgi.input': payload,
|
||||
})
|
||||
self.assertEqual(request.POST, {})
|
||||
self.assertEqual(request.body, payload_data)
|
||||
|
||||
|
@ -356,18 +366,22 @@ class RequestsTests(SimpleTestCase):
|
|||
'value',
|
||||
'--boundary--'
|
||||
'']))
|
||||
request = WSGIRequest({'REQUEST_METHOD': 'POST',
|
||||
request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'multipart/form-data; boundary=boundary',
|
||||
'CONTENT_LENGTH': 0,
|
||||
'wsgi.input': payload})
|
||||
'wsgi.input': payload,
|
||||
})
|
||||
self.assertEqual(request.POST, {})
|
||||
|
||||
def test_POST_binary_only(self):
|
||||
payload = b'\r\n\x01\x00\x00\x00ab\x00\x00\xcd\xcc,@'
|
||||
environ = {'REQUEST_METHOD': 'POST',
|
||||
environ = {
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'application/octet-stream',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': BytesIO(payload)}
|
||||
'wsgi.input': BytesIO(payload),
|
||||
}
|
||||
request = WSGIRequest(environ)
|
||||
self.assertEqual(request.POST, {})
|
||||
self.assertEqual(request.FILES, {})
|
||||
|
@ -382,10 +396,12 @@ class RequestsTests(SimpleTestCase):
|
|||
|
||||
def test_read_by_lines(self):
|
||||
payload = FakePayload('name=value')
|
||||
request = WSGIRequest({'REQUEST_METHOD': 'POST',
|
||||
request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': payload})
|
||||
'wsgi.input': payload,
|
||||
})
|
||||
self.assertEqual(list(request), [b'name=value'])
|
||||
|
||||
def test_POST_after_body_read(self):
|
||||
|
@ -393,10 +409,12 @@ class RequestsTests(SimpleTestCase):
|
|||
POST should be populated even if body is read first
|
||||
"""
|
||||
payload = FakePayload('name=value')
|
||||
request = WSGIRequest({'REQUEST_METHOD': 'POST',
|
||||
request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': payload})
|
||||
'wsgi.input': payload,
|
||||
})
|
||||
request.body # evaluate
|
||||
self.assertEqual(request.POST, {'name': ['value']})
|
||||
|
||||
|
@ -406,10 +424,12 @@ class RequestsTests(SimpleTestCase):
|
|||
the stream is read second.
|
||||
"""
|
||||
payload = FakePayload('name=value')
|
||||
request = WSGIRequest({'REQUEST_METHOD': 'POST',
|
||||
request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': payload})
|
||||
'wsgi.input': payload,
|
||||
})
|
||||
request.body # evaluate
|
||||
self.assertEqual(request.read(1), b'n')
|
||||
self.assertEqual(request.POST, {'name': ['value']})
|
||||
|
@ -426,10 +446,12 @@ class RequestsTests(SimpleTestCase):
|
|||
'value',
|
||||
'--boundary--'
|
||||
'']))
|
||||
request = WSGIRequest({'REQUEST_METHOD': 'POST',
|
||||
request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'multipart/form-data; boundary=boundary',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': payload})
|
||||
'wsgi.input': payload,
|
||||
})
|
||||
request.body # evaluate
|
||||
# Consume enough data to mess up the parsing:
|
||||
self.assertEqual(request.read(13), b'--boundary\r\nC')
|
||||
|
@ -464,11 +486,12 @@ class RequestsTests(SimpleTestCase):
|
|||
raise IOError("kaboom!")
|
||||
|
||||
payload = b'name=value'
|
||||
request = WSGIRequest({'REQUEST_METHOD': 'POST',
|
||||
request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': ExplodingBytesIO(payload)})
|
||||
|
||||
'wsgi.input': ExplodingBytesIO(payload),
|
||||
})
|
||||
with self.assertRaises(UnreadablePostError):
|
||||
request.body
|
||||
|
||||
|
@ -504,11 +527,12 @@ class RequestsTests(SimpleTestCase):
|
|||
raise IOError("kaboom!")
|
||||
|
||||
payload = b'x'
|
||||
request = WSGIRequest({'REQUEST_METHOD': 'POST',
|
||||
request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'multipart/form-data; boundary=foo_',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': ExplodingBytesIO(payload)})
|
||||
|
||||
'wsgi.input': ExplodingBytesIO(payload),
|
||||
})
|
||||
with self.assertRaises(UnreadablePostError):
|
||||
request.FILES
|
||||
|
||||
|
|
|
@ -866,14 +866,18 @@ class TemplateTests(SimpleTestCase):
|
|||
|
||||
# Use a pytz timezone as argument
|
||||
tpl = Template("{% load tz %}{{ dt|timezone:tz }}")
|
||||
ctx = Context({'dt': datetime.datetime(2011, 9, 1, 13, 20, 30),
|
||||
'tz': pytz.timezone('Europe/Paris')})
|
||||
ctx = Context({
|
||||
'dt': datetime.datetime(2011, 9, 1, 13, 20, 30),
|
||||
'tz': pytz.timezone('Europe/Paris'),
|
||||
})
|
||||
self.assertEqual(tpl.render(ctx), "2011-09-01T12:20:30+02:00")
|
||||
|
||||
# Use a pytz timezone name as argument
|
||||
tpl = Template("{% load tz %}{{ dt|timezone:'Europe/Paris' }}")
|
||||
ctx = Context({'dt': datetime.datetime(2011, 9, 1, 13, 20, 30),
|
||||
'tz': pytz.timezone('Europe/Paris')})
|
||||
ctx = Context({
|
||||
'dt': datetime.datetime(2011, 9, 1, 13, 20, 30),
|
||||
'tz': pytz.timezone('Europe/Paris'),
|
||||
})
|
||||
self.assertEqual(tpl.render(ctx), "2011-09-01T12:20:30+02:00")
|
||||
|
||||
def test_localtime_templatetag_invalid_argument(self):
|
||||
|
@ -913,8 +917,11 @@ class TemplateTests(SimpleTestCase):
|
|||
"{% endtimezone %}"
|
||||
"{% endtimezone %}"
|
||||
)
|
||||
ctx = Context({'dt': datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC),
|
||||
'tz1': ICT, 'tz2': None})
|
||||
ctx = Context({
|
||||
'dt': datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC),
|
||||
'tz1': ICT,
|
||||
'tz2': None,
|
||||
})
|
||||
self.assertEqual(
|
||||
tpl.render(ctx),
|
||||
"2011-09-01T13:20:30+03:00|2011-09-01T17:20:30+07:00|2011-09-01T13:20:30+03:00"
|
||||
|
@ -927,13 +934,17 @@ class TemplateTests(SimpleTestCase):
|
|||
tpl = Template("{% load tz %}{% timezone tz %}{{ dt }}{% endtimezone %}")
|
||||
|
||||
# Use a pytz timezone as argument
|
||||
ctx = Context({'dt': datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT),
|
||||
'tz': pytz.timezone('Europe/Paris')})
|
||||
ctx = Context({
|
||||
'dt': datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT),
|
||||
'tz': pytz.timezone('Europe/Paris'),
|
||||
})
|
||||
self.assertEqual(tpl.render(ctx), "2011-09-01T12:20:30+02:00")
|
||||
|
||||
# Use a pytz timezone name as argument
|
||||
ctx = Context({'dt': datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT),
|
||||
'tz': 'Europe/Paris'})
|
||||
ctx = Context({
|
||||
'dt': datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT),
|
||||
'tz': 'Europe/Paris',
|
||||
})
|
||||
self.assertEqual(tpl.render(ctx), "2011-09-01T12:20:30+02:00")
|
||||
|
||||
def test_timezone_templatetag_invalid_argument(self):
|
||||
|
|
|
@ -32,9 +32,7 @@ class OrderedSetTests(SimpleTestCase):
|
|||
class MultiValueDictTests(SimpleTestCase):
|
||||
|
||||
def test_multivaluedict(self):
|
||||
d = MultiValueDict({'name': ['Adrian', 'Simon'],
|
||||
'position': ['Developer']})
|
||||
|
||||
d = MultiValueDict({'name': ['Adrian', 'Simon'], 'position': ['Developer']})
|
||||
self.assertEqual(d['name'], 'Simon')
|
||||
self.assertEqual(d.get('name'), 'Simon')
|
||||
self.assertEqual(d.getlist('name'), ['Adrian', 'Simon'])
|
||||
|
@ -42,22 +40,17 @@ class MultiValueDictTests(SimpleTestCase):
|
|||
sorted(d.items()),
|
||||
[('name', 'Simon'), ('position', 'Developer')]
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
sorted(d.lists()),
|
||||
[('name', ['Adrian', 'Simon']), ('position', ['Developer'])]
|
||||
)
|
||||
|
||||
with self.assertRaises(MultiValueDictKeyError) as cm:
|
||||
d.__getitem__('lastname')
|
||||
self.assertEqual(str(cm.exception), "'lastname'")
|
||||
|
||||
self.assertIsNone(d.get('lastname'))
|
||||
self.assertEqual(d.get('lastname', 'nonexistent'), 'nonexistent')
|
||||
self.assertEqual(d.getlist('lastname'), [])
|
||||
self.assertEqual(d.getlist('doesnotexist', ['Adrian', 'Simon']),
|
||||
['Adrian', 'Simon'])
|
||||
|
||||
self.assertEqual(d.getlist('doesnotexist', ['Adrian', 'Simon']), ['Adrian', 'Simon'])
|
||||
d.setlist('lastname', ['Holovaty', 'Willison'])
|
||||
self.assertEqual(d.getlist('lastname'), ['Holovaty', 'Willison'])
|
||||
self.assertEqual(sorted(d.values()), ['Developer', 'Simon', 'Willison'])
|
||||
|
|
|
@ -728,14 +728,14 @@ class PlainTextReportTests(SimpleTestCase):
|
|||
|
||||
|
||||
class ExceptionReportTestMixin:
|
||||
|
||||
# Mixin used in the ExceptionReporterFilterTests and
|
||||
# AjaxResponseExceptionReporterFilter tests below
|
||||
|
||||
breakfast_data = {'sausage-key': 'sausage-value',
|
||||
breakfast_data = {
|
||||
'sausage-key': 'sausage-value',
|
||||
'baked-beans-key': 'baked-beans-value',
|
||||
'hash-brown-key': 'hash-brown-value',
|
||||
'bacon-key': 'bacon-value'}
|
||||
'bacon-key': 'bacon-value',
|
||||
}
|
||||
|
||||
def verify_unsafe_response(self, view, check_for_vars=True,
|
||||
check_for_POST_params=True):
|
||||
|
|
Loading…
Reference in New Issue