Skip to content

Commit

Permalink
Merge 56229d0 into 4c14c8f
Browse files Browse the repository at this point in the history
  • Loading branch information
goodtune committed Nov 15, 2016
2 parents 4c14c8f + 56229d0 commit eb91c89
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/methods.rst
Expand Up @@ -153,6 +153,7 @@ django-test-plus provides the following response method checks for you::

- response_200()
- response_201()
- response_301()
- response_302()
- response_400()
- response_401()
Expand Down
6 changes: 6 additions & 0 deletions test_plus/test.py
Expand Up @@ -17,6 +17,7 @@
class NoPreviousResponse(Exception):
pass


# Build a real context in versions of Django greater than 1.6
# On versions below 1.6, create a context that simply warns that
# the query number assertion is not happening
Expand Down Expand Up @@ -198,6 +199,11 @@ def response_201(self, response=None):
response = self._which_response(response)
self.assertEqual(response.status_code, 201)

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

def response_302(self, response=None):
""" Given response has status_code 302 """
response = self._which_response(response)
Expand Down
1 change: 1 addition & 0 deletions test_project/runtests.py
Expand Up @@ -20,5 +20,6 @@ def runtests(*test_args):
failures = test_runner.run_tests(['test_app'])
sys.exit(failures)


if __name__ == '__main__':
runtests()
7 changes: 7 additions & 0 deletions test_project/test_app/tests.py
Expand Up @@ -224,6 +224,13 @@ def test_response_201(self):
# Test without response option
self.response_201()

def test_response_301(self):
res = self.get('view-301')
self.response_301(res)

# Test without response option
self.response_301()

def test_response_302(self):
res = self.get('view-302')
self.response_302(res)
Expand Down
3 changes: 2 additions & 1 deletion test_project/test_app/urls.py
Expand Up @@ -4,7 +4,7 @@
from django.conf.urls.defaults import url, include

from .views import (
data_1, data_5, needs_login, view_200, view_201, view_302,
data_1, data_5, needs_login, view_200, view_201, view_301, view_302,
view_400, view_401, view_403, view_404, view_405, view_410,
view_contains, view_context_with, view_context_without,
view_is_ajax, view_redirect, FormErrors
Expand All @@ -14,6 +14,7 @@
url(r'^accounts/', include('django.contrib.auth.urls')),
url(r'^view/200/$', view_200, name='view-200'),
url(r'^view/201/$', view_201, name='view-201'),
url(r'^view/301/$', view_301, name='view-301'),
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'),
Expand Down
4 changes: 4 additions & 0 deletions test_project/test_app/views.py
Expand Up @@ -17,6 +17,10 @@ def view_201(request):
return HttpResponse('', status=201)


def view_301(request):
return HttpResponse('', status=301)


def view_302(request):
return HttpResponse('', status=302)

Expand Down

0 comments on commit eb91c89

Please sign in to comment.