Added tests that I neglected to check in for #8049 in [12159]

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12160 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2010-01-10 17:21:52 +00:00
parent 19b72077f7
commit 1461a76fdd
6 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<django-objects version="1.0">
<object pk="100" model="auth.user">
<field type="CharField" name="username">super</field>
<field type="CharField" name="first_name">Super</field>
<field type="CharField" name="last_name">User</field>
<field type="CharField" name="email">super@example.com</field>
<field type="CharField" name="password">sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158</field>
<field type="BooleanField" name="is_staff">True</field>
<field type="BooleanField" name="is_active">True</field>
<field type="BooleanField" name="is_superuser">True</field>
<field type="DateTimeField" name="last_login">2007-05-30 13:20:10</field>
<field type="DateTimeField" name="date_joined">2007-05-30 13:20:10</field>
<field to="auth.group" name="groups" rel="ManyToManyRel"></field>
<field to="auth.permission" name="user_permissions" rel="ManyToManyRel"></field>
</object>
<object pk="1" model="special_headers.article">
<field type="TextField" name="text">text</field>
</object>
</django-objects>

View File

@ -0,0 +1,4 @@
from django.db import models
class Article(models.Model):
text = models.TextField()

View File

@ -0,0 +1,40 @@
from django.test import TestCase
from django.contrib.auth.models import User
class SpecialHeadersTest(TestCase):
fixtures = ['data.xml']
def test_xheaders(self):
user = User.objects.get(username='super')
response = self.client.get('/special_headers/article/1/')
# import pdb; pdb.set_trace()
self.failUnless('X-Object-Type' not in response)
self.client.login(username='super', password='secret')
response = self.client.get('/special_headers/article/1/')
self.failUnless('X-Object-Type' in response)
user.is_staff = False
user.save()
response = self.client.get('/special_headers/article/1/')
self.failUnless('X-Object-Type' not in response)
user.is_staff = True
user.is_active = False
user.save()
response = self.client.get('/special_headers/article/1/')
self.failUnless('X-Object-Type' not in response)
def test_xview(self):
user = User.objects.get(username='super')
response = self.client.head('/special_headers/xview/')
self.failUnless('X-View' not in response)
self.client.login(username='super', password='secret')
response = self.client.head('/special_headers/xview/')
self.failUnless('X-View' in response)
user.is_staff = False
user.save()
response = self.client.head('/special_headers/xview/')
self.failUnless('X-View' not in response)
user.is_staff = True
user.is_active = False
user.save()
response = self.client.head('/special_headers/xview/')
self.failUnless('X-View' not in response)

View File

@ -0,0 +1,10 @@
# coding: utf-8
from django.conf.urls.defaults import *
from django.views.generic.list_detail import object_detail
from models import Article
import views
urlpatterns = patterns('',
(r'^article/(?P<object_id>\d+)/$', object_detail, {'queryset': Article.objects.all()}),
(r'^xview/$', views.xview),
)

View File

@ -0,0 +1,10 @@
# -*- coding:utf-8 -*-
from django.http import HttpResponse
from django.utils.decorators import decorator_from_middleware
from django.middleware.doc import XViewMiddleware
xview_dec = decorator_from_middleware(XViewMiddleware)
def xview(request):
return HttpResponse()
xview = xview_dec(xview)