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
|
|
|
|
2015-01-28 12:35:27 +00:00
|
|
|
from .models import PersonWithCustomMaxLengths, PersonWithDefaultMaxLengths
|
2011-10-13 21:34:56 +00:00
|
|
|
|
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):
|
2014-06-30 18:34:45 +00:00
|
|
|
self.verify_max_length(PersonWithDefaultMaxLengths, 'email', 254)
|
2007-09-19 23:33:57 +00:00
|
|
|
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
|
|
|
|
2013-11-03 04:36:09 +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()
|
2013-11-02 21:02:56 +00:00
|
|
|
new_args[field] = "X" * 250 # a value longer than any of the default fields could hold.
|
2007-09-19 23:33:57 +00:00
|
|
|
p = PersonWithCustomMaxLengths.objects.create(**new_args)
|
2013-07-01 12:22:27 +00:00
|
|
|
self.assertEqual(getattr(p, field), ("X" * 250))
|