| 1 | """ |
| 2 | >>> from django.contrib.auth.models import User |
| 3 | >>> from django.test import Client |
| 4 | |
| 5 | Created a regular user and an admin user. |
| 6 | |
| 7 | >>> adminuser = User.objects.create_user('staff', 'staff@mysite', 'staffpassword') |
| 8 | >>> normaluser = User.objects.create_user('user', 'user@mysite', 'userpassword') |
| 9 | >>> adminuser.is_staff = True |
| 10 | >>> adminuser.save() |
| 11 | |
| 12 | Login as a staff user and access a protected view. |
| 13 | |
| 14 | >>> c = Client() |
| 15 | >>> c.login(username='staff', password='staffpassword') |
| 16 | True |
| 17 | >>> response = c.get('/admin/staff_members_only/', {'param':1}) |
| 18 | >>> response.status_code |
| 19 | 200 |
| 20 | >>> response.content |
| 21 | 'param:1' |
| 22 | |
| 23 | Login as a normal user and access a protected view. |
| 24 | |
| 25 | >>> c = Client() |
| 26 | >>> c.login(username='user', password='userpassword') |
| 27 | True |
| 28 | >>> response = c.get('/admin/staff_members_only/', {'param':1}) |
| 29 | >>> response.status_code |
| 30 | 200 |
| 31 | >>> response.content.find('action="/admin/staff_members_only/?param=1"') > 0 |
| 32 | True |
| 33 | |
| 34 | """ |
| 35 | |
| 36 | from django.contrib.admin.views.decorators import staff_member_required |
| 37 | from django.http import HttpResponse |
| 38 | |
| 39 | def test_staff_member_required( req ): |
| 40 | return HttpResponse( '\n'.join( u'%s:%s' % (item,req.GET[item]) for item in req.GET) ) |
| 41 | test_staff_member_required = staff_member_required( test_staff_member_required ) |