Skip to content

Commit d139a39

Browse files
committed
Release 0.8.0
- enable auto-replace of csrf_token - focus back on the Response object that is nice to use with pytest - drop django < 2.1 and python < 3.7
1 parent fc5092a commit d139a39

17 files changed

+143
-25
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
sudo: false
22
language: python
33
python:
4-
- '3.6'
4+
- '3.7'
55
env:
66
matrix:
7-
- TOXENV=py27-dj111
8-
- TOXENV=py36-dj111
9-
- TOXENV=py36-dj20
7+
- TOXENV=py37-dj21
108
- TOXENV=qa
119
install:
1210
- pip install -U pip

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ itself and to make it reusable for other apps.
1616

1717
It's pretty much the same as django-dbdiff, except this is for HTTP response.
1818

19+
.. note:: v0.7 supports up to Django < 2.1
20+
1921
Response state assertion
2022
========================
2123

responsediff/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
"""Basic HTTP response diff-ing for test purposes."""
2+
from .response import Response # noqa

responsediff/response.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import inspect
44
import json
55
import os
6+
import re
67
import subprocess
78
import tempfile
89

@@ -79,8 +80,22 @@ def __init__(self, path):
7980
"""
8081
self.path = path
8182

82-
def assertNoDiff(self, response, selector=None): # noqa
83+
def assertNoDiff(self, response, selector=None, replace=None): # noqa
8384
"""Backward compatibility method for pre-assertWebsiteSame versions."""
85+
if not replace:
86+
replace = []
87+
88+
replace += [
89+
('<[^<]*csrfmiddlewaretoken[^>]*>', '{% csrf_token %}'),
90+
]
91+
92+
for pattern in replace:
93+
response.content = re.sub(
94+
pattern[0],
95+
pattern[1],
96+
response.content.decode('utf8')
97+
).encode('utf8')
98+
8499
diffs, created = self.make_diff(response, selector=selector)
85100

86101
if created or diffs:

responsediff/tests/project/settings.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,15 @@
3939
'django.contrib.staticfiles',
4040
)
4141

42-
MIDDLEWARE_CLASSES = (
42+
MIDDLEWARE = [ # django 2
43+
'django.middleware.security.SecurityMiddleware',
4344
'django.contrib.sessions.middleware.SessionMiddleware',
4445
'django.middleware.common.CommonMiddleware',
4546
'django.middleware.csrf.CsrfViewMiddleware',
4647
'django.contrib.auth.middleware.AuthenticationMiddleware',
47-
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
4848
'django.contrib.messages.middleware.MessageMiddleware',
4949
'django.middleware.clickjacking.XFrameOptionsMiddleware',
50-
'django.middleware.security.SecurityMiddleware',
51-
)
50+
]
5251

5352
ROOT_URLCONF = 'responsediff.tests.project.urls'
5453

responsediff/tests/project/urls.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
urlpatterns = []
1+
from django.contrib import admin
2+
from django.urls import path
3+
4+
urlpatterns = [
5+
path('admin/', admin.site.urls),
6+
]
Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,88 @@
1-
<h1>Not Found</h1><p>The requested URL /admin/ was not found on this server.</p>
1+
<!DOCTYPE html>
2+
3+
<html lang="en-us" >
4+
<head>
5+
<title>Log in | Django site admin</title>
6+
<link rel="stylesheet" type="text/css" href="/static/admin/css/base.css">
7+
<link rel="stylesheet" type="text/css" href="/static/admin/css/login.css">
8+
9+
10+
11+
12+
13+
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0">
14+
<link rel="stylesheet" type="text/css" href="/static/admin/css/responsive.css">
15+
16+
17+
<meta name="robots" content="NONE,NOARCHIVE">
18+
</head>
19+
20+
21+
<body class=" login"
22+
data-admin-utc-offset="0">
23+
24+
<!-- Container -->
25+
<div id="container">
26+
27+
28+
<!-- Header -->
29+
<div id="header">
30+
<div id="branding">
31+
32+
<h1 id="site-name"><a href="/admin/">Django administration</a></h1>
33+
34+
</div>
35+
36+
37+
</div>
38+
<!-- END Header -->
39+
40+
41+
42+
43+
44+
45+
46+
<!-- Content -->
47+
<div id="content" class="colM">
48+
49+
50+
51+
52+
53+
54+
55+
<div id="content-main">
56+
57+
58+
59+
<form action="/admin/login/" method="post" id="login-form">{% csrf_token %}
60+
<div class="form-row">
61+
62+
<label class="required" for="id_username">Username:</label> <input type="text" name="username" autofocus required id="id_username">
63+
</div>
64+
<div class="form-row">
65+
66+
<label class="required" for="id_password">Password:</label> <input type="password" name="password" required id="id_password">
67+
<input type="hidden" name="next" value="/admin/">
68+
</div>
69+
70+
71+
<div class="submit-row">
72+
<label>&nbsp;</label><input type="submit" value="Log in">
73+
</div>
74+
</form>
75+
76+
</div>
77+
78+
79+
<br class="clear">
80+
</div>
81+
<!-- END Content -->
82+
83+
<div id="footer"></div>
84+
</div>
85+
<!-- END Container -->
86+
87+
</body>
88+
</html>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"status_code": 404
2+
"status_code": 200
33
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
<h1>Not Found</h1>
2-
---
3-
<p>The requested URL /admin/ was not found on this server.</p>
1+
<h1 id="site-name"><a href="/admin/">Django administration</a></h1>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"status_code": 404
2+
"status_code": 200
33
}

0 commit comments

Comments
 (0)