2013-07-29 19:19:04 +02:00
|
|
|
from __future__ import unicode_literals
|
2011-10-13 23:34:56 +02:00
|
|
|
|
2013-07-01 14:22:27 +02:00
|
|
|
import unittest
|
2011-07-13 11:35:51 +02:00
|
|
|
|
2011-10-13 23:34:56 +02:00
|
|
|
from .models import PersonWithDefaultMaxLengths, PersonWithCustomMaxLengths
|
|
|
|
|
2007-09-20 01:33:57 +02:00
|
|
|
|
2010-10-11 14:55:17 +02:00
|
|
|
class MaxLengthArgumentsTests(unittest.TestCase):
|
|
|
|
|
2013-10-26 21:15:03 +02:00
|
|
|
def verify_max_length(self, model, field, length):
|
|
|
|
self.assertEqual(model._meta.get_field(field).max_length, length)
|
2010-10-11 14:55:17 +02:00
|
|
|
|
2007-09-20 01:33:57 +02: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 06:56:11 +02:00
|
|
|
def test_custom_max_lengths(self):
|
2009-05-07 20:06:22 +02: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 01:33:57 +02:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2010-10-11 14:55:17 +02:00
|
|
|
class MaxLengthORMTests(unittest.TestCase):
|
2007-09-20 01:33:57 +02: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 22:02:56 +01:00
|
|
|
new_args[field] = "X" * 250 # a value longer than any of the default fields could hold.
|
2007-09-20 01:33:57 +02:00
|
|
|
p = PersonWithCustomMaxLengths.objects.create(**new_args)
|
2013-07-01 14:22:27 +02:00
|
|
|
self.assertEqual(getattr(p, field), ("X" * 250))
|