~statik/+junk/django-nfa

« back to all changes in this revision

Viewing changes to tests/regressiontests/test_client_regress/models.py

  • Committer: brosner
  • Date: 2008-06-07 17:10:16 UTC
  • Revision ID: svn-v3-trunk1:bcc190cf-cafb-0310-a4f2-bffc1f526a37:django%2Fbranches%2Fnewforms-admin:7584
newforms-admin: Merged from trunk up to [7583].

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
"""
5
5
from django.test import Client, TestCase
6
6
from django.core.urlresolvers import reverse
 
7
from django.core.exceptions import SuspiciousOperation
7
8
import os
8
9
 
9
10
class AssertContainsTests(TestCase):
11
12
        "Responses can be inspected for content, including counting repeated substrings"
12
13
        response = self.client.get('/test_client_regress/no_template_view/')
13
14
 
 
15
        self.assertNotContains(response, 'never')
14
16
        self.assertContains(response, 'never', 0)
15
17
        self.assertContains(response, 'once')
16
18
        self.assertContains(response, 'once', 1)
18
20
        self.assertContains(response, 'twice', 2)
19
21
 
20
22
        try:
 
23
            self.assertNotContains(response, 'once')
 
24
        except AssertionError, e:
 
25
            self.assertEquals(str(e), "Response should not contain 'once'")
 
26
            
 
27
        try:
21
28
            self.assertContains(response, 'never', 1)
22
29
        except AssertionError, e:
23
30
            self.assertEquals(str(e), "Found 0 instances of 'never' in response (expected 1)")
288
295
        self.assertEqual(response.status_code, 200)
289
296
        self.assertEqual(response.content, 'Hi, Arthur')
290
297
 
291
 
 
 
298
class ExceptionTests(TestCase):
 
299
    fixtures = ['testdata.json']
 
300
    
 
301
    def test_exception_cleared(self):
 
302
        "#5836 - A stale user exception isn't re-raised by the test client."
 
303
 
 
304
        login = self.client.login(username='testclient',password='password')
 
305
        self.failUnless(login, 'Could not log in')
 
306
        try:
 
307
            response = self.client.get("/test_client_regress/staff_only/")
 
308
            self.fail("General users should not be able to visit this page")
 
309
        except SuspiciousOperation:
 
310
            pass
 
311
 
 
312
        # At this point, an exception has been raised, and should be cleared.
 
313
        
 
314
        # This next operation should be successful; if it isn't we have a problem.
 
315
        login = self.client.login(username='staff', password='password')
 
316
        self.failUnless(login, 'Could not log in')
 
317
        try:
 
318
            self.client.get("/test_client_regress/staff_only/")
 
319
        except SuspiciousOperation:
 
320
            self.fail("Staff should be able to visit this page")