1 | from django.test.client import RequestFactory
|
---|
2 | from django.test import TestCase
|
---|
3 |
|
---|
4 | class TestViews(TestCase):
|
---|
5 | def setUp(self):
|
---|
6 | self.factory = RequestFactory()
|
---|
7 |
|
---|
8 | def test_request(self):
|
---|
9 | request = self.factory.get('/')
|
---|
10 | self.assertFalse(hasattr(request, 'user')) # OK
|
---|
11 |
|
---|
12 | def test_request_after_client(self):
|
---|
13 | self.client.get('/')
|
---|
14 |
|
---|
15 | request = self.factory.get('/')
|
---|
16 | request.session = {}
|
---|
17 | self.assertFalse(hasattr(request, 'user')) # FAIL
|
---|
18 |
|
---|
19 | def test_request_after_client_2(self):
|
---|
20 | # This test is executed after the previous one thus also fails
|
---|
21 | request = self.factory.get('/')
|
---|
22 | request.session = {}
|
---|
23 | self.assertFalse(hasattr(request, 'user')) # FAIL
|
---|
24 |
|
---|