~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
from django.contrib.admin import widgets
4
4
from unittest import TestCase
5
5
from django.test import TestCase as DjangoTestCase
 
6
from django.db.models import DateField
6
7
import models
7
8
 
8
9
class AdminFormfieldForDBFieldTests(TestCase):
89
90
 
90
91
    def testFormfieldOverrides(self):
91
92
        self.assertFormfield(models.Event, 'start_date', forms.TextInput,
92
 
                             formfield_overrides={'widget': forms.TextInput})
 
93
                             formfield_overrides={DateField: {'widget': forms.TextInput}})
93
94
 
94
95
    def testFieldWithChoices(self):
95
96
        self.assertFormfield(models.Member, 'gender', forms.Select)
127
128
        response = self.client.get('%s/admin_widgets/car/' % self.admin_root)
128
129
        self.failUnless('%s/auth/user/add/' % self.admin_root in response.content)
129
130
 
130
 
class OldAdminForeignKeyWidgetChangeList(AdminForeignKeyWidgetChangeList):
131
 
    urls = 'regressiontests.admin_widgets.urls2'
132
 
    admin_root = '/deep/down/admin'
 
131
class AdminForeignKeyRawIdWidget(DjangoTestCase):
 
132
    fixtures = ["admin-widgets-users.xml"]
 
133
    admin_root = '/widget_admin'
 
134
 
 
135
    def setUp(self):
 
136
        self.client.login(username="super", password="secret")
 
137
 
 
138
    def tearDown(self):
 
139
        self.client.logout()
 
140
 
 
141
    def test_nonexistent_target_id(self):
 
142
        band = models.Band.objects.create(name='Bogey Blues')
 
143
        pk = band.pk
 
144
        band.delete()
 
145
        post_data = {
 
146
            "band": u'%s' % pk,
 
147
        }
 
148
        # Try posting with a non-existent pk in a raw id field: this
 
149
        # should result in an error message, not a server exception.
 
150
        response = self.client.post('%s/admin_widgets/event/add/' % self.admin_root,
 
151
            post_data)
 
152
        self.assertContains(response,
 
153
            'Select a valid choice. That choice is not one of the available choices.')