From 1461a76fdd3540e37122131f15a58520dce438ca Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sun, 10 Jan 2010 17:21:52 +0000 Subject: [PATCH] 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 --- .../special_headers/fixtures/data.xml | 20 ++++++++++ .../regressiontests/special_headers/models.py | 4 ++ .../special_headers/article_detail.html | 1 + .../regressiontests/special_headers/tests.py | 40 +++++++++++++++++++ tests/regressiontests/special_headers/urls.py | 10 +++++ .../regressiontests/special_headers/views.py | 10 +++++ 6 files changed, 85 insertions(+) create mode 100644 tests/regressiontests/special_headers/fixtures/data.xml create mode 100644 tests/regressiontests/special_headers/models.py create mode 100644 tests/regressiontests/special_headers/templates/special_headers/article_detail.html create mode 100644 tests/regressiontests/special_headers/tests.py create mode 100644 tests/regressiontests/special_headers/urls.py create mode 100644 tests/regressiontests/special_headers/views.py diff --git a/tests/regressiontests/special_headers/fixtures/data.xml b/tests/regressiontests/special_headers/fixtures/data.xml new file mode 100644 index 0000000000..7e60d45199 --- /dev/null +++ b/tests/regressiontests/special_headers/fixtures/data.xml @@ -0,0 +1,20 @@ + + + + super + Super + User + super@example.com + sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158 + True + True + True + 2007-05-30 13:20:10 + 2007-05-30 13:20:10 + + + + + text + + diff --git a/tests/regressiontests/special_headers/models.py b/tests/regressiontests/special_headers/models.py new file mode 100644 index 0000000000..0c126757cc --- /dev/null +++ b/tests/regressiontests/special_headers/models.py @@ -0,0 +1,4 @@ +from django.db import models + +class Article(models.Model): + text = models.TextField() diff --git a/tests/regressiontests/special_headers/templates/special_headers/article_detail.html b/tests/regressiontests/special_headers/templates/special_headers/article_detail.html new file mode 100644 index 0000000000..3cbd38cb7e --- /dev/null +++ b/tests/regressiontests/special_headers/templates/special_headers/article_detail.html @@ -0,0 +1 @@ +{{ object }} diff --git a/tests/regressiontests/special_headers/tests.py b/tests/regressiontests/special_headers/tests.py new file mode 100644 index 0000000000..f304bfa932 --- /dev/null +++ b/tests/regressiontests/special_headers/tests.py @@ -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) diff --git a/tests/regressiontests/special_headers/urls.py b/tests/regressiontests/special_headers/urls.py new file mode 100644 index 0000000000..721f60ad94 --- /dev/null +++ b/tests/regressiontests/special_headers/urls.py @@ -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\d+)/$', object_detail, {'queryset': Article.objects.all()}), + (r'^xview/$', views.xview), +) diff --git a/tests/regressiontests/special_headers/views.py b/tests/regressiontests/special_headers/views.py new file mode 100644 index 0000000000..7a012038a1 --- /dev/null +++ b/tests/regressiontests/special_headers/views.py @@ -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)