Skip to content

Commit

Permalink
Merge pull request #42 from DZPM/master
Browse files Browse the repository at this point in the history
Add check for status code 400 (Bad Request)
  • Loading branch information
frankwiles committed Jun 25, 2016
2 parents 312e3df + 1dc823f commit e06b983
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/methods.rst
Expand Up @@ -123,6 +123,7 @@ django-test-plus provides the following response method checks for you::
- response_200()
- response_201()
- response_302()
- response_400()
- response_401()
- response_403()
- response_404()
Expand Down
5 changes: 5 additions & 0 deletions test_plus/test.py
Expand Up @@ -159,6 +159,11 @@ def response_302(self, response=None):
response = self._which_response(response)
self.assertEqual(response.status_code, 302)

def response_400(self, response=None):
""" Given response has status_code 400 """
response = self._which_response(response)
self.assertEqual(response.status_code, 400)

def response_401(self, response=None):
""" Given response has status_code 401 """
response = self._which_response(response)
Expand Down
7 changes: 7 additions & 0 deletions test_project/test_app/tests.py
Expand Up @@ -106,6 +106,13 @@ def test_response_302(self):
# Test without response option
self.response_302()

def test_response_400(self):
res = self.get('view-400')
self.response_400(res)

# Test without response option
self.response_400()

def test_response_401(self):
res = self.get('view-401')
self.response_401(res)
Expand Down
5 changes: 3 additions & 2 deletions test_project/test_app/urls.py
Expand Up @@ -5,8 +5,8 @@

from .views import (
data_1, data_5, needs_login, view_200, view_201, view_302,
view_401, view_403, view_404, view_405, view_410, view_context_with,
view_context_without, view_is_ajax, view_redirect
view_400, view_401, view_403, view_404, view_405, view_410,
view_context_with, view_context_without, view_is_ajax, view_redirect,
)

urlpatterns = patterns(
Expand All @@ -15,6 +15,7 @@
url(r'^view/200/$', view_200, name='view-200'),
url(r'^view/201/$', view_201, name='view-201'),
url(r'^view/302/$', view_302, name='view-302'),
url(r'^view/400/$', view_400, name='view-400'),
url(r'^view/401/$', view_401, name='view-401'),
url(r'^view/403/$', view_403, name='view-403'),
url(r'^view/404/$', view_404, name='view-404'),
Expand Down
4 changes: 4 additions & 0 deletions test_project/test_app/views.py
Expand Up @@ -20,6 +20,10 @@ def view_302(request):
return HttpResponse('', status=302)


def view_400(request):
return HttpResponse('', status=400)


def view_401(request):
return HttpResponse('', status=401)

Expand Down

0 comments on commit e06b983

Please sign in to comment.