test_textfield.py 788 B

12345678910111213141516171819202122232425
  1. from django.db import models
  2. from django.test import TestCase
  3. from .models import Post
  4. class TextFieldTests(TestCase):
  5. def test_max_length_passed_to_formfield(self):
  6. """
  7. TextField passes its max_length attribute to form fields created using
  8. their formfield() method.
  9. """
  10. tf1 = models.TextField()
  11. tf2 = models.TextField(max_length=2345)
  12. self.assertIsNone(tf1.formfield().max_length)
  13. self.assertEqual(2345, tf2.formfield().max_length)
  14. def test_to_python(self):
  15. """TextField.to_python() should return a string."""
  16. f = models.TextField()
  17. self.assertEqual(f.to_python(1), '1')
  18. def test_lookup_integer_in_textfield(self):
  19. self.assertEqual(Post.objects.filter(body=24).count(), 0)