summaryrefslogtreecommitdiff
path: root/tests/regressiontests
diff options
context:
space:
mode:
authorDerek Anderson <public@kered.org>2007-08-06 16:50:17 +0000
committerDerek Anderson <public@kered.org>2007-08-06 16:50:17 +0000
commit5aa017255827b2c06bd9a5f7f069828ef625da18 (patch)
tree22ec9db537e3eeda5c8e21dbfe35f252a97e375d /tests/regressiontests
parent0af6ed0c4853e11086e277ba352d27db4c466c89 (diff)
schema-evolution: update from HEAD (v5821)
git-svn-id: http://code.djangoproject.com/svn/django/branches/schema-evolution@5822 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
-rw-r--r--tests/regressiontests/bug639/models.py2
-rw-r--r--tests/regressiontests/datatypes/models.py2
-rw-r--r--tests/regressiontests/fixtures_regress/models.py8
-rw-r--r--tests/regressiontests/forms/tests.py81
-rw-r--r--tests/regressiontests/initial_sql_regress/models.py2
-rw-r--r--tests/regressiontests/invalid_admin_options/models.py74
-rw-r--r--tests/regressiontests/many_to_one_regress/models.py6
-rw-r--r--tests/regressiontests/maxlength/__init__.py0
-rw-r--r--tests/regressiontests/maxlength/models.py0
-rw-r--r--tests/regressiontests/maxlength/tests.py160
-rw-r--r--tests/regressiontests/model_regress/models.py2
-rw-r--r--tests/regressiontests/null_queries/models.py4
-rw-r--r--tests/regressiontests/one_to_one_regress/models.py6
-rw-r--r--tests/regressiontests/serializers_regress/models.py16
-rw-r--r--tests/regressiontests/string_lookup/models.py12
15 files changed, 301 insertions, 74 deletions
diff --git a/tests/regressiontests/bug639/models.py b/tests/regressiontests/bug639/models.py
index 7cfdfc82ef..fc241aba8c 100644
--- a/tests/regressiontests/bug639/models.py
+++ b/tests/regressiontests/bug639/models.py
@@ -2,7 +2,7 @@ import tempfile
from django.db import models
class Photo(models.Model):
- title = models.CharField(maxlength=30)
+ title = models.CharField(max_length=30)
image = models.FileField(upload_to=tempfile.gettempdir())
# Support code for the tests; this keeps track of how many times save() gets
diff --git a/tests/regressiontests/datatypes/models.py b/tests/regressiontests/datatypes/models.py
index 8c5c8c285d..ff9666bc0c 100644
--- a/tests/regressiontests/datatypes/models.py
+++ b/tests/regressiontests/datatypes/models.py
@@ -7,7 +7,7 @@ from django.db import models
from django.conf import settings
class Donut(models.Model):
- name = models.CharField(maxlength=100)
+ name = models.CharField(max_length=100)
is_frosted = models.BooleanField(default=False)
has_sprinkles = models.NullBooleanField()
baked_date = models.DateField(null=True)
diff --git a/tests/regressiontests/fixtures_regress/models.py b/tests/regressiontests/fixtures_regress/models.py
index 41ef8c26bf..2c92839f0f 100644
--- a/tests/regressiontests/fixtures_regress/models.py
+++ b/tests/regressiontests/fixtures_regress/models.py
@@ -2,21 +2,21 @@ from django.db import models
from django.contrib.auth.models import User
class Animal(models.Model):
- name = models.CharField(maxlength=150)
- latin_name = models.CharField(maxlength=150)
+ name = models.CharField(max_length=150)
+ latin_name = models.CharField(max_length=150)
def __unicode__(self):
return self.common_name
class Plant(models.Model):
- name = models.CharField(maxlength=150)
+ name = models.CharField(max_length=150)
class Meta:
# For testing when upper case letter in app name; regression for #4057
db_table = "Fixtures_regress_plant"
class Stuff(models.Model):
- name = models.CharField(maxlength=20, null=True)
+ name = models.CharField(max_length=20, null=True)
owner = models.ForeignKey(User, null=True)
def __unicode__(self):
diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py
index 52cc9ccfa5..2386a7f8b1 100644
--- a/tests/regressiontests/forms/tests.py
+++ b/tests/regressiontests/forms/tests.py
@@ -173,27 +173,29 @@ u'<input type="hidden" class="special" value="foo@example.com" name="email" />'
# FileInput Widget ############################################################
+FileInput widgets don't ever show the value, because the old value is of no use
+if you are updating the form or if the provided file generated an error.
>>> w = FileInput()
>>> w.render('email', '')
u'<input type="file" name="email" />'
>>> w.render('email', None)
u'<input type="file" name="email" />'
>>> w.render('email', 'test@example.com')
-u'<input type="file" name="email" value="test@example.com" />'
+u'<input type="file" name="email" />'
>>> w.render('email', 'some "quoted" & ampersanded value')
-u'<input type="file" name="email" value="some &quot;quoted&quot; &amp; ampersanded value" />'
+u'<input type="file" name="email" />'
>>> w.render('email', 'test@example.com', attrs={'class': 'fun'})
-u'<input type="file" name="email" value="test@example.com" class="fun" />'
+u'<input type="file" name="email" class="fun" />'
You can also pass 'attrs' to the constructor:
>>> w = FileInput(attrs={'class': 'fun'})
>>> w.render('email', '')
u'<input type="file" class="fun" name="email" />'
>>> w.render('email', 'foo@example.com')
-u'<input type="file" class="fun" value="foo@example.com" name="email" />'
+u'<input type="file" class="fun" name="email" />'
>>> w.render('email', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'})
-u'<input type="file" class="fun" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" name="email" />'
+u'<input type="file" class="fun" name="email" />'
# Textarea Widget #############################################################
@@ -1532,6 +1534,42 @@ Traceback (most recent call last):
...
ValidationError: [u'Ensure this value has at most 15 characters (it has 20).']
+# FileField ##################################################################
+
+>>> f = FileField()
+>>> f.clean('')
+Traceback (most recent call last):
+...
+ValidationError: [u'This field is required.']
+
+>>> f.clean(None)
+Traceback (most recent call last):
+...
+ValidationError: [u'This field is required.']
+
+>>> f.clean({})
+Traceback (most recent call last):
+...
+ValidationError: [u'No file was submitted.']
+
+>>> f.clean('some content that is not a file')
+Traceback (most recent call last):
+...
+ValidationError: [u'No file was submitted. Check the encoding type on the form.']
+
+>>> f.clean({'filename': 'name', 'content':None})
+Traceback (most recent call last):
+...
+ValidationError: [u'The submitted file is empty.']
+
+>>> f.clean({'filename': 'name', 'content':''})
+Traceback (most recent call last):
+...
+ValidationError: [u'The submitted file is empty.']
+
+>>> type(f.clean({'filename': 'name', 'content':'Some File Content'}))
+<class 'django.newforms.fields.UploadedFile'>
+
# URLField ##################################################################
>>> f = URLField()
@@ -2573,7 +2611,7 @@ Instances of a dynamic Form do not persist fields from one Form instance to
the next.
>>> class MyForm(Form):
... def __init__(self, data=None, auto_id=False, field_list=[]):
-... Form.__init__(self, data, auto_id)
+... Form.__init__(self, data, auto_id=auto_id)
... for field in field_list:
... self.fields[field[0]] = field[1]
>>> field_list = [('field1', CharField()), ('field2', CharField())]
@@ -2591,7 +2629,7 @@ the next.
... default_field_1 = CharField()
... default_field_2 = CharField()
... def __init__(self, data=None, auto_id=False, field_list=[]):
-... Form.__init__(self, data, auto_id)
+... Form.__init__(self, data, auto_id=auto_id)
... for field in field_list:
... self.fields[field[0]] = field[1]
>>> field_list = [('field1', CharField()), ('field2', CharField())]
@@ -3246,6 +3284,35 @@ is different than its data. This is handled transparently, though.
<option value="3" selected="selected">No</option>
</select>
+# Forms with FileFields ################################################
+
+FileFields are a special case because they take their data from the request.FILES,
+not request.POST.
+
+>>> class FileForm(Form):
+... file1 = FileField()
+>>> f = FileForm(auto_id=False)
+>>> print f
+<tr><th>File1:</th><td><input type="file" name="file1" /></td></tr>
+
+>>> f = FileForm(data={}, files={}, auto_id=False)
+>>> print f
+<tr><th>File1:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="file" name="file1" /></td></tr>
+
+>>> f = FileForm(data={}, files={'file1': {'filename': 'name', 'content':''}}, auto_id=False)
+>>> print f
+<tr><th>File1:</th><td><ul class="errorlist"><li>The submitted file is empty.</li></ul><input type="file" name="file1" /></td></tr>
+
+>>> f = FileForm(data={}, files={'file1': 'something that is not a file'}, auto_id=False)
+>>> print f
+<tr><th>File1:</th><td><ul class="errorlist"><li>No file was submitted. Check the encoding type on the form.</li></ul><input type="file" name="file1" /></td></tr>
+
+>>> f = FileForm(data={}, files={'file1': {'filename': 'name', 'content':'some content'}}, auto_id=False)
+>>> print f
+<tr><th>File1:</th><td><input type="file" name="file1" /></td></tr>
+>>> f.is_valid()
+True
+
# Basic form processing in a view #############################################
>>> from django.template import Template, Context
diff --git a/tests/regressiontests/initial_sql_regress/models.py b/tests/regressiontests/initial_sql_regress/models.py
index dedbba8e5c..7cf725991a 100644
--- a/tests/regressiontests/initial_sql_regress/models.py
+++ b/tests/regressiontests/initial_sql_regress/models.py
@@ -5,7 +5,7 @@ Regression tests for initial SQL insertion.
from django.db import models
class Simple(models.Model):
- name = models.CharField(maxlength = 50)
+ name = models.CharField(max_length = 50)
__test__ = {'API_TESTS':""}
diff --git a/tests/regressiontests/invalid_admin_options/models.py b/tests/regressiontests/invalid_admin_options/models.py
index 43bcc533ba..14db463735 100644
--- a/tests/regressiontests/invalid_admin_options/models.py
+++ b/tests/regressiontests/invalid_admin_options/models.py
@@ -12,7 +12,7 @@ model_errors = ""
##This should fail gracefully but is causing a metaclass error
#class BadAdminOption(models.Model):
# "Test nonexistent admin option"
-# name = models.CharField(maxlength=30)
+# name = models.CharField(max_length=30)
#
# class Admin:
# nonexistent = 'option'
@@ -22,7 +22,7 @@ model_errors = ""
class ListDisplayBadOne(models.Model):
"Test list_display, list_display must be a list or tuple"
- first_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
class Admin:
list_display = 'first_name'
@@ -32,7 +32,7 @@ model_errors += """invalid_admin_options.listdisplaybadone: "admin.list_display"
class ListDisplayBadTwo(models.Model):
"Test list_display, list_display items must be attributes, methods or properties."
- first_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
class Admin:
list_display = ['first_name','nonexistent']
@@ -41,7 +41,7 @@ model_errors += """invalid_admin_options.listdisplaybadtwo: "admin.list_display"
"""
class ListDisplayBadThree(models.Model):
"Test list_display, list_display items can not be a ManyToManyField."
- first_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
nick_names = models.ManyToManyField('ListDisplayGood')
class Admin:
@@ -52,7 +52,7 @@ model_errors += """invalid_admin_options.listdisplaybadthree: "admin.list_displa
class ListDisplayGood(models.Model):
"Test list_display, Admin list_display can be a attribute, method or property."
- first_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
def _last_name(self):
return self.first_name
@@ -66,8 +66,8 @@ class ListDisplayGood(models.Model):
class ListDisplayLinksBadOne(models.Model):
"Test list_display_links, item must be included in list_display."
- first_name = models.CharField(maxlength=30)
- last_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
+ last_name = models.CharField(max_length=30)
class Admin:
list_display = ['last_name']
@@ -78,8 +78,8 @@ model_errors += """invalid_admin_options.listdisplaylinksbadone: "admin.list_dis
class ListDisplayLinksBadTwo(models.Model):
"Test list_display_links, must be a list or tuple."
- first_name = models.CharField(maxlength=30)
- last_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
+ last_name = models.CharField(max_length=30)
class Admin:
list_display = ['first_name','last_name']
@@ -92,8 +92,8 @@ model_errors += """invalid_admin_options.listdisplaylinksbadtwo: "admin.list_dis
## This is failing but the validation which should fail is not.
#class ListDisplayLinksBadThree(models.Model):
# "Test list_display_links, must define list_display to use list_display_links."
-# first_name = models.CharField(maxlength=30)
-# last_name = models.CharField(maxlength=30)
+# first_name = models.CharField(max_length=30)
+# last_name = models.CharField(max_length=30)
#
# class Admin:
# list_display_links = ('first_name',)
@@ -103,7 +103,7 @@ model_errors += """invalid_admin_options.listdisplaylinksbadtwo: "admin.list_dis
class ListDisplayLinksGood(models.Model):
"Test list_display_links, Admin list_display_list can be a attribute, method or property."
- first_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
def _last_name(self):
return self.first_name
@@ -118,7 +118,7 @@ class ListDisplayLinksGood(models.Model):
class ListFilterBadOne(models.Model):
"Test list_filter, must be a list or tuple."
- first_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
class Admin:
list_filter = 'first_name'
@@ -128,7 +128,7 @@ model_errors += """invalid_admin_options.listfilterbadone: "admin.list_filter",
class ListFilterBadTwo(models.Model):
"Test list_filter, must be a field not a property or method."
- first_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
def _last_name(self):
return self.first_name
@@ -146,7 +146,7 @@ invalid_admin_options.listfilterbadtwo: "admin.list_filter" refers to 'full_name
class DateHierarchyBadOne(models.Model):
"Test date_hierarchy, must be a date or datetime field."
- first_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
birth_day = models.DateField()
class Admin:
@@ -158,7 +158,7 @@ class DateHierarchyBadOne(models.Model):
class DateHierarchyBadTwo(models.Model):
"Test date_hieracrhy, must be a field."
- first_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
birth_day = models.DateField()
class Admin:
@@ -169,7 +169,7 @@ model_errors += """invalid_admin_options.datehierarchybadtwo: "admin.date_hierar
class DateHierarchyGood(models.Model):
"Test date_hieracrhy, must be a field."
- first_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
birth_day = models.DateField()
class Admin:
@@ -177,7 +177,7 @@ class DateHierarchyGood(models.Model):
class SearchFieldsBadOne(models.Model):
"Test search_fields, must be a list or tuple."
- first_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
class Admin:
search_fields = ('nonexistent')
@@ -188,7 +188,7 @@ class SearchFieldsBadOne(models.Model):
class SearchFieldsBadTwo(models.Model):
"Test search_fields, must be a field."
- first_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
def _last_name(self):
return self.first_name
@@ -203,8 +203,8 @@ class SearchFieldsBadTwo(models.Model):
class SearchFieldsGood(models.Model):
"Test search_fields, must be a list or tuple."
- first_name = models.CharField(maxlength=30)
- last_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
+ last_name = models.CharField(max_length=30)
class Admin:
search_fields = ['first_name','last_name']
@@ -212,7 +212,7 @@ class SearchFieldsGood(models.Model):
class JsBadOne(models.Model):
"Test js, must be a list or tuple"
- name = models.CharField(maxlength=30)
+ name = models.CharField(max_length=30)
class Admin:
js = 'test.js'
@@ -223,7 +223,7 @@ class JsBadOne(models.Model):
class SaveAsBad(models.Model):
"Test save_as, should be True or False"
- name = models.CharField(maxlength=30)
+ name = models.CharField(max_length=30)
class Admin:
save_as = 'not True or False'
@@ -234,7 +234,7 @@ class SaveAsBad(models.Model):
class SaveOnTopBad(models.Model):
"Test save_on_top, should be True or False"
- name = models.CharField(maxlength=30)
+ name = models.CharField(max_length=30)
class Admin:
save_on_top = 'not True or False'
@@ -245,7 +245,7 @@ class SaveOnTopBad(models.Model):
class ListSelectRelatedBad(models.Model):
"Test list_select_related, should be True or False"
- name = models.CharField(maxlength=30)
+ name = models.CharField(max_length=30)
class Admin:
list_select_related = 'not True or False'
@@ -256,7 +256,7 @@ class ListSelectRelatedBad(models.Model):
class ListPerPageBad(models.Model):
"Test list_per_page, should be a positive integer value."
- name = models.CharField(maxlength=30)
+ name = models.CharField(max_length=30)
class Admin:
list_per_page = 89.3
@@ -267,8 +267,8 @@ class ListPerPageBad(models.Model):
class FieldsBadOne(models.Model):
"Test fields, should be a tuple"
- first_name = models.CharField(maxlength=30)
- last_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
+ last_name = models.CharField(max_length=30)
class Admin:
fields = 'not a tuple'
@@ -279,8 +279,8 @@ class FieldsBadOne(models.Model):
class FieldsBadTwo(models.Model):
"""Test fields, 'fields' dict option is required."""
- first_name = models.CharField(maxlength=30)
- last_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
+ last_name = models.CharField(max_length=30)
class Admin:
fields = ('Name', {'description': 'this fieldset needs fields'})
@@ -291,8 +291,8 @@ class FieldsBadTwo(models.Model):
class FieldsBadThree(models.Model):
"""Test fields, 'classes' and 'description' are the only allowable extra dict options."""
- first_name = models.CharField(maxlength=30)
- last_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
+ last_name = models.CharField(max_length=30)
class Admin:
fields = ('Name', {'fields': ('first_name','last_name'),'badoption': 'verybadoption'})
@@ -303,8 +303,8 @@ class FieldsBadThree(models.Model):
class FieldsGood(models.Model):
"Test fields, working example"
- first_name = models.CharField(maxlength=30)
- last_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
+ last_name = models.CharField(max_length=30)
birth_day = models.DateField()
class Admin:
@@ -315,8 +315,8 @@ class FieldsGood(models.Model):
class OrderingBad(models.Model):
"Test ordering, must be a field."
- first_name = models.CharField(maxlength=30)
- last_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
+ last_name = models.CharField(max_length=30)
class Admin:
ordering = 'nonexistent'
@@ -328,7 +328,7 @@ class OrderingBad(models.Model):
## TODO: Add a manager validator, this should fail gracefully.
#class ManagerBad(models.Model):
# "Test manager, must be a manager object."
-# first_name = models.CharField(maxlength=30)
+# first_name = models.CharField(max_length=30)
#
# class Admin:
# manager = 'nonexistent'
diff --git a/tests/regressiontests/many_to_one_regress/models.py b/tests/regressiontests/many_to_one_regress/models.py
index 8ddec98da4..57bbcd8489 100644
--- a/tests/regressiontests/many_to_one_regress/models.py
+++ b/tests/regressiontests/many_to_one_regress/models.py
@@ -12,15 +12,15 @@ class Second(models.Model):
# Protect against repetition of #1839, #2415 and #2536.
class Third(models.Model):
- name = models.CharField(maxlength=20)
+ name = models.CharField(max_length=20)
third = models.ForeignKey('self', null=True, related_name='child_set')
class Parent(models.Model):
- name = models.CharField(maxlength=20)
+ name = models.CharField(max_length=20)
bestchild = models.ForeignKey('Child', null=True, related_name='favored_by')
class Child(models.Model):
- name = models.CharField(maxlength=20)
+ name = models.CharField(max_length=20)
parent = models.ForeignKey(Parent)
diff --git a/tests/regressiontests/maxlength/__init__.py b/tests/regressiontests/maxlength/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/regressiontests/maxlength/__init__.py
diff --git a/tests/regressiontests/maxlength/models.py b/tests/regressiontests/maxlength/models.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/regressiontests/maxlength/models.py
diff --git a/tests/regressiontests/maxlength/tests.py b/tests/regressiontests/maxlength/tests.py
new file mode 100644
index 0000000000..8a5f874c78
--- /dev/null
+++ b/tests/regressiontests/maxlength/tests.py
@@ -0,0 +1,160 @@
+# Test access to max_length while still providing full backwards compatibility
+# with legacy maxlength attribute.
+"""
+
+Don't print out the deprecation warnings during testing.
+>>> from warnings import filterwarnings
+>>> filterwarnings("ignore")
+
+# legacy_maxlength function
+
+>>> from django.utils.maxlength import legacy_maxlength
+
+>>> legacy_maxlength(None, None)
+
+
+>>> legacy_maxlength(10, None)
+10
+
+>>> legacy_maxlength(None, 10)
+10
+
+>>> legacy_maxlength(10, 12)
+Traceback (most recent call last):
+...
+TypeError: field can not take both the max_length argument and the legacy maxlength argument.
+
+>>> legacy_maxlength(0, 10)
+Traceback (most recent call last):
+...
+TypeError: field can not take both the max_length argument and the legacy maxlength argument.
+
+>>> legacy_maxlength(0, None)
+0
+
+>>> legacy_maxlength(None, 0)
+0
+
+#===============================================================================
+# Fields
+#===============================================================================
+
+# Set up fields
+>>> from django.db.models import fields
+>>> new = fields.Field(max_length=15)
+>>> old = fields.Field(maxlength=10)
+
+# Ensure both max_length and legacy maxlength are not able to both be specified
+>>> fields.Field(maxlength=10, max_length=15)
+Traceback (most recent call last):
+ ...
+TypeError: field can not take both the max_length argument and the legacy maxlength argument.
+
+# Test max_length
+>>> new.max_length
+15
+>>> old.max_length
+10
+
+# Test accessing maxlength
+>>> new.maxlength
+15
+>>> old.maxlength
+10
+
+# Test setting maxlength
+>>> new.maxlength += 1
+>>> old.maxlength += 1
+>>> new.max_length
+16
+>>> old.max_length
+11
+
+# SlugField __init__ passes through max_length so test that too
+>>> fields.SlugField('new', max_length=15).max_length
+15
+>>> fields.SlugField('empty').max_length
+50
+>>> fields.SlugField('old', maxlength=10).max_length
+10
+
+#===============================================================================
+# (old)forms
+#===============================================================================
+
+>>> from django import oldforms
+
+# Test max_length attribute
+
+>>> oldforms.TextField('new', max_length=15).render('')
+u'<input type="text" id="id_new" class="vTextField" name="new" size="30" value="" maxlength="15" />'
+
+>>> oldforms.IntegerField('new', max_length=15).render('')
+u'<input type="text" id="id_new" class="vIntegerField" name="new" size="10" value="" maxlength="15" />'
+
+>>> oldforms.SmallIntegerField('new', max_length=15).render('')
+u'<input type="text" id="id_new" class="vSmallIntegerField" name="new" size="5" value="" maxlength="15" />'
+
+>>> oldforms.PositiveIntegerField('new', max_length=15).render('')
+u'<input type="text" id="id_new" class="vPositiveIntegerField" name="new" size="10" value="" maxlength="15" />'
+
+>>> oldforms.PositiveSmallIntegerField('new', max_length=15).render('')
+u'<input type="text" id="id_new" class="vPositiveSmallIntegerField" name="new" size="5" value="" maxlength="15" />'
+
+>>> oldforms.DatetimeField('new', max_length=15).render('')
+u'<input type="text" id="id_new" class="vDatetimeField" name="new" size="30" value="" maxlength="15" />'
+
+>>> oldforms.EmailField('new', max_length=15).render('')
+u'<input type="text" id="id_new" class="vEmailField" name="new" size="50" value="" maxlength="15" />'
+>>> oldforms.EmailField('new').render('')
+u'<input type="text" id="id_new" class="vEmailField" name="new" size="50" value="" maxlength="75" />'
+
+>>> oldforms.URLField('new', max_length=15).render('')
+u'<input type="text" id="id_new" class="vURLField" name="new" size="50" value="" maxlength="15" />'
+>>> oldforms.URLField('new').render('')
+u'<input type="text" id="id_new" class="vURLField" name="new" size="50" value="" maxlength="200" />'
+
+>>> oldforms.IPAddressField('new', max_length=15).render('')
+u'<input type="text" id="id_new" class="vIPAddressField" name="new" size="15" value="" maxlength="15" />'
+>>> oldforms.IPAddressField('new').render('')
+u'<input type="text" id="id_new" class="vIPAddressField" name="new" size="15" value="" maxlength="15" />'
+
+>>> oldforms.CommaSeparatedIntegerField('new', max_length=15).render('')
+u'<input type="text" id="id_new" class="vCommaSeparatedIntegerField" name="new" size="20" value="" maxlength="15" />'
+
+
+# Test legacy maxlength attribute
+
+>>> oldforms.TextField('old', maxlength=10).render('')
+u'<input type="text" id="id_old" class="vTextField" name="old" size="30" value="" maxlength="10" />'
+
+>>> oldforms.IntegerField('old', maxlength=10).render('')
+u'<input type="text" id="id_old" class="vIntegerField" name="old" size="10" value="" maxlength="10" />'
+
+>>> oldforms.SmallIntegerField('old', maxlength=10).render('')
+u'<input type="text" id="id_old" class="vSmallIntegerField" name="old" size="5" value="" maxlength="10" />'
+
+>>> oldforms.PositiveIntegerField('old', maxlength=10).render('')
+u'<input type="text" id="id_old" class="vPositiveIntegerField" name="old" size="10" value="" maxlength="10" />'
+
+>>> oldforms.PositiveSmallIntegerField('old', maxlength=10).render('')
+u'<input type="text" id="id_old" class="vPositiveSmallIntegerField" name="old" size="5" value="" maxlength="10" />'
+
+>>> oldforms.DatetimeField('old', maxlength=10).render('')
+u'<input type="text" id="id_old" class="vDatetimeField" name="old" size="30" value="" maxlength="10" />'
+
+>>> oldforms.EmailField('old', maxlength=10).render('')
+u'<input type="text" id="id_old" class="vEmailField" name="old" size="50" value="" maxlength="10" />'
+
+>>> oldforms.URLField('old', maxlength=10).render('')
+u'<input type="text" id="id_old" class="vURLField" name="old" size="50" value="" maxlength="10" />'
+
+>>> oldforms.IPAddressField('old', maxlength=10).render('')
+u'<input type="text" id="id_old" class="vIPAddressField" name="old" size="15" value="" maxlength="10" />'
+
+>>> oldforms.CommaSeparatedIntegerField('old', maxlength=10).render('')
+u'<input type="text" id="id_old" class="vCommaSeparatedIntegerField" name="old" size="20" value="" maxlength="10" />'
+"""
+if __name__ == "__main__":
+ import doctest
+ doctest.testmod()
diff --git a/tests/regressiontests/model_regress/models.py b/tests/regressiontests/model_regress/models.py
index b4d432d8fa..0fee831212 100644
--- a/tests/regressiontests/model_regress/models.py
+++ b/tests/regressiontests/model_regress/models.py
@@ -7,7 +7,7 @@ CHOICES = (
)
class Article(models.Model):
- headline = models.CharField(maxlength=100, default='Default headline')
+ headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField()
status = models.IntegerField(blank=True, null=True, choices=CHOICES)
diff --git a/tests/regressiontests/null_queries/models.py b/tests/regressiontests/null_queries/models.py
index 2e903876bf..2aa36b2c1a 100644
--- a/tests/regressiontests/null_queries/models.py
+++ b/tests/regressiontests/null_queries/models.py
@@ -1,14 +1,14 @@
from django.db import models
class Poll(models.Model):
- question = models.CharField(maxlength=200)
+ question = models.CharField(max_length=200)
def __unicode__(self):
return u"Q: %s " % self.question
class Choice(models.Model):
poll = models.ForeignKey(Poll)
- choice = models.CharField(maxlength=200)
+ choice = models.CharField(max_length=200)
def __unicode__(self):
return u"Choice: %s in poll %s" % (self.choice, self.poll)
diff --git a/tests/regressiontests/one_to_one_regress/models.py b/tests/regressiontests/one_to_one_regress/models.py
index be48c842ed..c5ffd3fb3c 100644
--- a/tests/regressiontests/one_to_one_regress/models.py
+++ b/tests/regressiontests/one_to_one_regress/models.py
@@ -1,8 +1,8 @@
from django.db import models
class Place(models.Model):
- name = models.CharField(maxlength=50)
- address = models.CharField(maxlength=80)
+ name = models.CharField(max_length=50)
+ address = models.CharField(max_length=80)
def __unicode__(self):
return u"%s the place" % self.name
@@ -16,7 +16,7 @@ class Restaurant(models.Model):
return u"%s the restaurant" % self.place.name
class Favorites(models.Model):
- name = models.CharField(maxlength = 50)
+ name = models.CharField(max_length = 50)
restaurants = models.ManyToManyField(Restaurant)
def __unicode__(self):
diff --git a/tests/regressiontests/serializers_regress/models.py b/tests/regressiontests/serializers_regress/models.py
index f9af1d26ca..e9df508822 100644
--- a/tests/regressiontests/serializers_regress/models.py
+++ b/tests/regressiontests/serializers_regress/models.py
@@ -16,7 +16,7 @@ class BooleanData(models.Model):
data = models.BooleanField(null=True)
class CharData(models.Model):
- data = models.CharField(maxlength=30, null=True)
+ data = models.CharField(max_length=30, null=True)
class DateData(models.Model):
data = models.DateField(null=True)
@@ -90,7 +90,7 @@ class Tag(models.Model):
ordering = ["data"]
class GenericData(models.Model):
- data = models.CharField(maxlength=30)
+ data = models.CharField(max_length=30)
tags = generic.GenericRelation(Tag)
@@ -102,13 +102,13 @@ class Anchor(models.Model):
"""This is a model that can be used as
something for other models to point at"""
- data = models.CharField(maxlength=30)
+ data = models.CharField(max_length=30)
class UniqueAnchor(models.Model):
"""This is a model that can be used as
something for other models to point at"""
- data = models.CharField(unique=True, maxlength=30)
+ data = models.CharField(unique=True, max_length=30)
class FKData(models.Model):
data = models.ForeignKey(Anchor, null=True)
@@ -144,7 +144,7 @@ class BooleanPKData(models.Model):
data = models.BooleanField(primary_key=True)
class CharPKData(models.Model):
- data = models.CharField(maxlength=30, primary_key=True)
+ data = models.CharField(max_length=30, primary_key=True)
# class DatePKData(models.Model):
# data = models.DateField(primary_key=True)
@@ -208,9 +208,9 @@ class USStatePKData(models.Model):
# data = models.XMLField(primary_key=True)
class ComplexModel(models.Model):
- field1 = models.CharField(maxlength=10)
- field2 = models.CharField(maxlength=10)
- field3 = models.CharField(maxlength=10)
+ field1 = models.CharField(max_length=10)
+ field2 = models.CharField(max_length=10)
+ field3 = models.CharField(max_length=10)
# Tests for handling fields with pre_save functions, or
# models with save functions that modify data
diff --git a/tests/regressiontests/string_lookup/models.py b/tests/regressiontests/string_lookup/models.py
index 66651ce680..6a341070a4 100644
--- a/tests/regressiontests/string_lookup/models.py
+++ b/tests/regressiontests/string_lookup/models.py
@@ -2,14 +2,14 @@
from django.db import models
class Foo(models.Model):
- name = models.CharField(maxlength=50)
- friend = models.CharField(maxlength=50, blank=True)
+ name = models.CharField(max_length=50)
+ friend = models.CharField(max_length=50, blank=True)
def __unicode__(self):
return "Foo %s" % self.name
class Bar(models.Model):
- name = models.CharField(maxlength=50)
+ name = models.CharField(max_length=50)
normal = models.ForeignKey(Foo, related_name='normal_foo')
fwd = models.ForeignKey("Whiz")
back = models.ForeignKey("Foo")
@@ -18,20 +18,20 @@ class Bar(models.Model):
return "Bar %s" % self.place.name
class Whiz(models.Model):
- name = models.CharField(maxlength = 50)
+ name = models.CharField(max_length = 50)
def __unicode__(self):
return "Whiz %s" % self.name
class Child(models.Model):
parent = models.OneToOneField('Base')
- name = models.CharField(maxlength = 50)
+ name = models.CharField(max_length = 50)
def __unicode__(self):
return "Child %s" % self.name
class Base(models.Model):
- name = models.CharField(maxlength = 50)
+ name = models.CharField(max_length = 50)
def __unicode__(self):
return "Base %s" % self.name