2007-09-20 07:33:57 +08:00
|
|
|
from django.db import DatabaseError
|
2010-10-11 20:55:17 +08:00
|
|
|
from django.utils import unittest
|
2007-09-20 07:33:57 +08:00
|
|
|
from regressiontests.max_lengths.models import PersonWithDefaultMaxLengths, PersonWithCustomMaxLengths
|
|
|
|
|
2010-10-11 20:55:17 +08:00
|
|
|
class MaxLengthArgumentsTests(unittest.TestCase):
|
|
|
|
|
2007-09-20 07:33:57 +08:00
|
|
|
def verify_max_length(self, model,field,length):
|
2011-03-03 23:04:39 +08:00
|
|
|
self.assertEqual(model._meta.get_field(field).max_length,length)
|
2010-10-11 20:55:17 +08:00
|
|
|
|
2007-09-20 07:33:57 +08:00
|
|
|
def test_default_max_lengths(self):
|
|
|
|
self.verify_max_length(PersonWithDefaultMaxLengths, 'email', 75)
|
|
|
|
self.verify_max_length(PersonWithDefaultMaxLengths, 'vcard', 100)
|
|
|
|
self.verify_max_length(PersonWithDefaultMaxLengths, 'homepage', 200)
|
|
|
|
self.verify_max_length(PersonWithDefaultMaxLengths, 'avatar', 100)
|
|
|
|
|
2008-08-02 12:56:11 +08:00
|
|
|
def test_custom_max_lengths(self):
|
2009-05-08 02:06:22 +08:00
|
|
|
self.verify_max_length(PersonWithCustomMaxLengths, 'email', 250)
|
|
|
|
self.verify_max_length(PersonWithCustomMaxLengths, 'vcard', 250)
|
|
|
|
self.verify_max_length(PersonWithCustomMaxLengths, 'homepage', 250)
|
|
|
|
self.verify_max_length(PersonWithCustomMaxLengths, 'avatar', 250)
|
2007-09-20 07:33:57 +08:00
|
|
|
|
2010-10-11 20:55:17 +08:00
|
|
|
class MaxLengthORMTests(unittest.TestCase):
|
2007-09-20 07:33:57 +08:00
|
|
|
|
|
|
|
def test_custom_max_lengths(self):
|
|
|
|
args = {
|
|
|
|
"email": "someone@example.com",
|
|
|
|
"vcard": "vcard",
|
|
|
|
"homepage": "http://example.com/",
|
|
|
|
"avatar": "me.jpg"
|
|
|
|
}
|
|
|
|
|
|
|
|
for field in ("email", "vcard", "homepage", "avatar"):
|
|
|
|
new_args = args.copy()
|
|
|
|
new_args[field] = "X" * 250 # a value longer than any of the default fields could hold.
|
|
|
|
p = PersonWithCustomMaxLengths.objects.create(**new_args)
|
|
|
|
self.assertEqual(getattr(p, field), ("X" * 250))
|