~ubuntu-branches/debian/squeeze/python-django/squeeze

« back to all changes in this revision

Viewing changes to tests/regressiontests/max_lengths/tests.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb, Chris Lamb, David Spreen, Sandro Tosi
  • Date: 2008-11-19 21:31:00 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081119213100-gp0lqhxl1qxa6dgl
Tags: 1.0.2-1
[ Chris Lamb ]
* New upstream bugfix release. Closes: #505783
* Add myself to Uploaders with ACK from Brett.

[ David Spreen ]
* Remove python-pysqlite2 from Recommends because Python 2.5 includes
  sqlite library used by Django. Closes: 497886

[ Sandro Tosi ]
* debian/control
  - switch Vcs-Browser field to viewsvn

Show diffs side-by-side

added added

removed removed

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