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