2013-07-29 17:19:04 +00:00
|
|
|
from __future__ import unicode_literals
|
2011-10-13 21:34:56 +00:00
|
|
|
|
2013-07-01 12:22:27 +00:00
|
|
|
import unittest
|
2011-07-13 09:35:51 +00:00
|
|
|
|
2011-10-13 21:34:56 +00:00
|
|
|
from .models import PersonWithDefaultMaxLengths, PersonWithCustomMaxLengths
|
|
|
|
|
2007-09-19 23:33:57 +00:00
|
|
|
|
2010-10-11 12:55:17 +00:00
|
|
|
class MaxLengthArgumentsTests(unittest.TestCase):
|
|
|
|
|
2013-10-26 19:15:03 +00:00
|
|
|
def verify_max_length(self, model, field, length):
|
|
|
|
self.assertEqual(model._meta.get_field(field).max_length, length)
|
2010-10-11 12:55:17 +00:00
|
|
|
|
2007-09-19 23:33:57 +00: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 04:56:11 +00:00
|
|
|
def test_custom_max_lengths(self):
|
2009-05-07 18:06:22 +00: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-19 23:33:57 +00:00
|
|
|
|
2010-10-11 12:55:17 +00:00
|
|
|
class MaxLengthORMTests(unittest.TestCase):
|
2007-09-19 23:33:57 +00: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)
|
2013-07-01 12:22:27 +00:00
|
|
|
self.assertEqual(getattr(p, field), ("X" * 250))
|