This repository was archived by the owner on Aug 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtests.py
52 lines (42 loc) · 1.88 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from django.test import TestCase
from django.test.client import Client
from documentation.views import documentation
from django.core.urlresolvers import reverse
from django.conf import settings
from django.contrib.auth.models import User
from documentation import app_settings
class DocumentationTest(TestCase):
def setUp(self):
self.client = Client()
app_settings.DOCUMENTATION_ACCESS_FUNCTION = lambda x: x.is_staff
app_settings.DOCUMENTATION_XSENDFILE = False
self.login_url = settings.LOGIN_URL
User.objects.create_user('testuser', '[email protected]', 'testpw')
v = User.objects.create_user('teststaff', '[email protected]', 'testpw')
v.is_staff = True
v.save()
def test_no_anonymous(self):
c = self.client
response = c.get(reverse(documentation, args=['index.html']))
self.assertEqual(response.status_code, 404)
def test_no_regular(self):
c = self.client
c.login(username='testuser', password='testpw')
response = c.get(reverse(documentation, args=['index.html']))
self.assertEqual(response.status_code, 404)
def test_staff(self):
c = self.client
c.login(username='teststaff', password='testpw')
response = c.get(reverse(documentation, args=['index.html']))
self.assertEqual(response.status_code, 200)
self.assertTemplateNotUsed(response, 'admin/login.html')
self.assertNotEqual('', response.content)
class XSendfileDocumentationTest(DocumentationTest):
def setUp(self):
super(XSendfileDocumentationTest, self).setUp()
app_settings.DOCUMENTATION_XSENDFILE = True
def test_staff(self):
c = self.client
c.login(username='teststaff', password='testpw')
response = c.get(reverse(documentation, args=['index.html']))
self.assertEqual(response['X-Sendfile'][-10:], 'index.html')