Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-pipeline
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
django-pipeline
Commits
5d0ecfa6
Commit
5d0ecfa6
authored
Nov 20, 2014
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve middleware tests
parent
48f502b0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
45 deletions
+32
-45
tests/settings.py
+5
-1
tests/tests/test_middleware.py
+27
-44
No files found.
tests/settings.py
View file @
5d0ecfa6
...
...
@@ -18,10 +18,14 @@ INSTALLED_APPS = [
'django.contrib.auth'
,
'django.contrib.admin'
,
'pipeline'
,
'tests'
,
'tests.tests'
]
MIDDLEWARE_CLASSES
=
(
'django.contrib.sessions.middleware.SessionMiddleware'
,
'django.contrib.auth.middleware.AuthenticationMiddleware'
)
ROOT_URLCONF
=
'tests.urls'
MEDIA_URL
=
'/media/'
...
...
tests/tests/test_middleware.py
View file @
5d0ecfa6
...
...
@@ -2,52 +2,35 @@
from
__future__
import
unicode_literals
from
django.test
import
TestCase
from
django.conf
import
settings
from
django.core.urlresolvers
import
reverse
from
django.http
import
HttpRequest
,
HttpResponse
from
tests.utils
import
pipeline_settings
from
pipeline.middleware
import
MinifyHTMLMiddleware
class
MiddlewareTest
(
TestCase
):
def
test_middleware_off
(
self
):
response
=
self
.
client
.
get
(
reverse
(
'admin:index'
))
whitespace
=
b
' '
def
setUp
(
self
):
self
.
req
=
HttpRequest
()
self
.
req
.
META
=
{
'SERVER_NAME'
:
'testserver'
,
'SERVER_PORT'
:
80
,
}
self
.
req
.
path
=
self
.
req
.
path_info
=
"/"
self
.
resp
=
HttpResponse
()
self
.
resp
.
status_code
=
200
self
.
resp
.
content
=
self
.
whitespace
def
test_middleware_html
(
self
):
self
.
resp
[
'Content-Type'
]
=
'text/html; charset=UTF-8'
response
=
MinifyHTMLMiddleware
()
.
process_response
(
self
.
req
,
self
.
resp
)
self
.
assertIn
(
'text/html'
,
response
[
'Content-Type'
])
# Should not come if not compressed
self
.
assertNotIn
(
'Content-Length'
,
response
)
def
test_middleware_on
(
self
):
CUSTOM_MIDDLEWARE
=
(
'django.middleware.gzip.GZipMiddleware'
,
'pipeline.middleware.MinifyHTMLMiddleware'
,
)
+
settings
.
MIDDLEWARE_CLASSES
with
self
.
settings
(
MIDDLEWARE_CLASSES
=
CUSTOM_MIDDLEWARE
):
response
=
self
.
client
.
get
(
reverse
(
'admin:index'
))
self
.
assertIn
(
'text/html'
,
response
[
'Content-Type'
])
length
=
str
(
len
(
response
.
content
))
self
.
assertEqual
(
length
,
response
[
'Content-Length'
])
def
test_middleware_pipeline_enabled
(
self
):
CUSTOM_MIDDLEWARE
=
(
'django.middleware.gzip.GZipMiddleware'
,
'pipeline.middleware.MinifyHTMLMiddleware'
,
)
+
settings
.
MIDDLEWARE_CLASSES
with
self
.
settings
(
MIDDLEWARE_CLASSES
=
CUSTOM_MIDDLEWARE
):
with
pipeline_settings
(
PIPELINE_ENABLED
=
True
):
response
=
self
.
client
.
get
(
reverse
(
'admin:index'
))
self
.
assertNotIn
(
b
' '
,
response
.
content
)
def
test_middleware_pipeline_disabled
(
self
):
CUSTOM_MIDDLEWARE
=
(
'django.middleware.gzip.GZipMiddleware'
,
'pipeline.middleware.MinifyHTMLMiddleware'
,
)
+
settings
.
MIDDLEWARE_CLASSES
with
self
.
settings
(
MIDDLEWARE_CLASSES
=
CUSTOM_MIDDLEWARE
):
with
pipeline_settings
(
PIPELINE_ENABLED
=
False
):
response
=
self
.
client
.
get
(
reverse
(
'admin:index'
))
self
.
assertIn
(
b
' '
,
response
.
content
)
self
.
assertNotIn
(
self
.
whitespace
,
response
.
content
)
def
test_middleware_text
(
self
):
self
.
resp
[
'Content-Type'
]
=
'text/plain; charset=UTF-8'
response
=
MinifyHTMLMiddleware
()
.
process_response
(
self
.
req
,
self
.
resp
)
self
.
assertIn
(
'text/plain'
,
response
[
'Content-Type'
])
self
.
assertIn
(
self
.
whitespace
,
response
.
content
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment