1 | # Embed a dummy URLconf to make the test self-contained
|
---|
2 | from django.conf.urls.defaults import patterns, include, url
|
---|
3 | from django.http import HttpResponse
|
---|
4 | urlpatterns = patterns('',
|
---|
5 | url(r'', lambda request: HttpResponse('')),
|
---|
6 | )
|
---|
7 |
|
---|
8 |
|
---|
9 | from django.test import TestCase
|
---|
10 | from django.test.client import RequestFactory
|
---|
11 |
|
---|
12 |
|
---|
13 | class TestViews(TestCase):
|
---|
14 |
|
---|
15 | urls = __name__
|
---|
16 |
|
---|
17 | def setUp(self):
|
---|
18 | self.factory = RequestFactory()
|
---|
19 |
|
---|
20 | def common_test_that_should_always_pass(self):
|
---|
21 | request = self.factory.get('/')
|
---|
22 | request.session = {}
|
---|
23 | self.assertFalse(hasattr(request, 'user'))
|
---|
24 |
|
---|
25 | def test_request(self):
|
---|
26 | self.common_test_that_should_always_pass() # OK
|
---|
27 |
|
---|
28 | def test_request_after_client(self):
|
---|
29 | # apart from the next line the three tests are identical
|
---|
30 | self.client.get('/')
|
---|
31 | self.common_test_that_should_always_pass() # FAIL
|
---|
32 |
|
---|
33 | def test_request_after_client_2(self):
|
---|
34 | # This test is executed after the previous one thus also fails
|
---|
35 | self.common_test_that_should_always_pass() # FAIL
|
---|
36 |
|
---|