Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 1461a76fdd3540e37122131f15a58520dce438ca 1 parent 19b7207
Adrian Holovaty authored
20  tests/regressiontests/special_headers/fixtures/data.xml
... ...
@@ -0,0 +1,20 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<django-objects version="1.0">
  3
+    <object pk="100" model="auth.user">
  4
+        <field type="CharField" name="username">super</field>
  5
+        <field type="CharField" name="first_name">Super</field>
  6
+        <field type="CharField" name="last_name">User</field>
  7
+        <field type="CharField" name="email">super@example.com</field>
  8
+        <field type="CharField" name="password">sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158</field>
  9
+        <field type="BooleanField" name="is_staff">True</field>
  10
+        <field type="BooleanField" name="is_active">True</field>
  11
+        <field type="BooleanField" name="is_superuser">True</field>
  12
+        <field type="DateTimeField" name="last_login">2007-05-30 13:20:10</field>
  13
+        <field type="DateTimeField" name="date_joined">2007-05-30 13:20:10</field>
  14
+        <field to="auth.group" name="groups" rel="ManyToManyRel"></field>
  15
+        <field to="auth.permission" name="user_permissions" rel="ManyToManyRel"></field>
  16
+    </object>
  17
+    <object pk="1" model="special_headers.article">
  18
+        <field type="TextField" name="text">text</field>
  19
+    </object>
  20
+</django-objects>
4  tests/regressiontests/special_headers/models.py
... ...
@@ -0,0 +1,4 @@
  1
+from django.db import models
  2
+
  3
+class Article(models.Model):
  4
+    text = models.TextField()
1  tests/regressiontests/special_headers/templates/special_headers/article_detail.html
... ...
@@ -0,0 +1 @@
  1
+{{ object }}
40  tests/regressiontests/special_headers/tests.py
... ...
@@ -0,0 +1,40 @@
  1
+from django.test import TestCase
  2
+from django.contrib.auth.models import User
  3
+
  4
+class SpecialHeadersTest(TestCase):
  5
+    fixtures = ['data.xml']
  6
+
  7
+    def test_xheaders(self):
  8
+        user = User.objects.get(username='super')
  9
+        response = self.client.get('/special_headers/article/1/')
  10
+        # import pdb; pdb.set_trace()
  11
+        self.failUnless('X-Object-Type' not in response)
  12
+        self.client.login(username='super', password='secret')
  13
+        response = self.client.get('/special_headers/article/1/')
  14
+        self.failUnless('X-Object-Type' in response)
  15
+        user.is_staff = False
  16
+        user.save()
  17
+        response = self.client.get('/special_headers/article/1/')
  18
+        self.failUnless('X-Object-Type' not in response)
  19
+        user.is_staff = True
  20
+        user.is_active = False
  21
+        user.save()
  22
+        response = self.client.get('/special_headers/article/1/')
  23
+        self.failUnless('X-Object-Type' not in response)
  24
+
  25
+    def test_xview(self):
  26
+        user = User.objects.get(username='super')
  27
+        response = self.client.head('/special_headers/xview/')
  28
+        self.failUnless('X-View' not in response)
  29
+        self.client.login(username='super', password='secret')
  30
+        response = self.client.head('/special_headers/xview/')
  31
+        self.failUnless('X-View' in response)
  32
+        user.is_staff = False
  33
+        user.save()
  34
+        response = self.client.head('/special_headers/xview/')
  35
+        self.failUnless('X-View' not in response)
  36
+        user.is_staff = True
  37
+        user.is_active = False
  38
+        user.save()
  39
+        response = self.client.head('/special_headers/xview/')
  40
+        self.failUnless('X-View' not in response)
10  tests/regressiontests/special_headers/urls.py
... ...
@@ -0,0 +1,10 @@
  1
+# coding: utf-8
  2
+from django.conf.urls.defaults import *
  3
+from django.views.generic.list_detail import object_detail
  4
+from models import Article
  5
+import views
  6
+
  7
+urlpatterns = patterns('',
  8
+    (r'^article/(?P<object_id>\d+)/$', object_detail, {'queryset': Article.objects.all()}),
  9
+    (r'^xview/$', views.xview),
  10
+)
10  tests/regressiontests/special_headers/views.py
... ...
@@ -0,0 +1,10 @@
  1
+# -*- coding:utf-8 -*-
  2
+from django.http import HttpResponse
  3
+from django.utils.decorators import decorator_from_middleware
  4
+from django.middleware.doc import XViewMiddleware
  5
+
  6
+xview_dec = decorator_from_middleware(XViewMiddleware)
  7
+
  8
+def xview(request):
  9
+    return HttpResponse()
  10
+xview = xview_dec(xview)

0 notes on commit 1461a76

Please sign in to comment.
Something went wrong with that request. Please try again.