/tests/regressiontests/max_lengths/tests.py

https://code.google.com/p/mango-py/ · Python · 36 lines · 29 code · 7 blank · 0 comment · 1 complexity · f9f9e438d7bbd84de25655973d7d13a4 MD5 · raw file

  1. from django.db import DatabaseError
  2. from django.utils import unittest
  3. from regressiontests.max_lengths.models import PersonWithDefaultMaxLengths, PersonWithCustomMaxLengths
  4. class MaxLengthArgumentsTests(unittest.TestCase):
  5. def verify_max_length(self, model,field,length):
  6. self.assertEqual(model._meta.get_field(field).max_length,length)
  7. def test_default_max_lengths(self):
  8. self.verify_max_length(PersonWithDefaultMaxLengths, 'email', 75)
  9. self.verify_max_length(PersonWithDefaultMaxLengths, 'vcard', 100)
  10. self.verify_max_length(PersonWithDefaultMaxLengths, 'homepage', 200)
  11. self.verify_max_length(PersonWithDefaultMaxLengths, 'avatar', 100)
  12. def test_custom_max_lengths(self):
  13. self.verify_max_length(PersonWithCustomMaxLengths, 'email', 250)
  14. self.verify_max_length(PersonWithCustomMaxLengths, 'vcard', 250)
  15. self.verify_max_length(PersonWithCustomMaxLengths, 'homepage', 250)
  16. self.verify_max_length(PersonWithCustomMaxLengths, 'avatar', 250)
  17. class MaxLengthORMTests(unittest.TestCase):
  18. def test_custom_max_lengths(self):
  19. args = {
  20. "email": "someone@example.com",
  21. "vcard": "vcard",
  22. "homepage": "http://example.com/",
  23. "avatar": "me.jpg"
  24. }
  25. for field in ("email", "vcard", "homepage", "avatar"):
  26. new_args = args.copy()
  27. new_args[field] = "X" * 250 # a value longer than any of the default fields could hold.
  28. p = PersonWithCustomMaxLengths.objects.create(**new_args)
  29. self.assertEqual(getattr(p, field), ("X" * 250))