10000 Version 2.3.10 · matthiask/django-rest-framework@910de38 · GitHub
[go: up one dir, main page]

Skip to content

Commit 910de38

Browse files
committed
Version 2.3.10
1 parent 85d9eb0 commit 910de38

File tree

5 files changed

+76
-2
lines changed

5 files changed

+76
-2
lines changed

docs/api-guide/status-codes.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ Using bare status codes in your responses isn't recommended. REST framework inc
1717

1818
The full set of HTTP status codes included in the `status` module is listed below.
1919

20+
The module also includes a set of helper functions for testing if a status code is in a given range.
21+
22+
from rest_framework import status
23+
from rest_framework.test import APITestCase
24+
25+
class ExampleTestCase(APITestCase):
26+
def test_url_root(self):
27+
url = reverse('index')
28+
response = self.client.get(url)
29+
self.assertTrue(status.is_success(response.status_code))
30+
31+
2032
For more information on proper usage of HTTP status codes see [RFC 2616][rfc2616]
2133
and [RFC 6585][rfc6585].
2234

@@ -90,6 +102,15 @@ Response status codes beginning with the digit "5" indicate cases in which the s
90102
HTTP_505_HTTP_VERSION_NOT_SUPPORTED
91103
HTTP_511_NETWORK_AUTHENTICATION_REQUIRED
92104

105+
## Helper functions
106+
107+
The following helper functions are available for identifying the category of the response code.
108+
109+
is_informational() # 1xx
110+
is_success() # 2xx
111+
is_redirect() # 3xx
112+
is_client_error() # 4xx
113+
is_server_error() # 5xx
93114

94115
[rfc2324]: http://www.ietf.org/rfc/rfc2324.txt
95116
[rfc2616]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

docs/topics/release-notes.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ You can determine your currently installed version using `pip freeze`:
4040

4141
## 2.3.x series
4242

43-
### Master
43+
### 2.3.10
44+
45+
**Date**: 6th December 2013
4446

4547
* Add in choices information for ChoiceFields in response to `OPTIONS` requests.
4648
* Added `pre_delete()` and `post_delete()` method hooks.
49+
* Added status code category helper functions.
4750
* Bugfix: Partial updates which erronously set a related field to `None` now correctly fail validation instead of raising an exception.
4851
* Bugfix: Responses without any content no longer include an HTTP `'Content-Type'` header.
4952
* Bugfix: Correctly handle validation errors in PUT-as-create case, responding with 400.

rest_framework/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"""
99

1010
__title__ = 'Django REST framework'
11-
__version__ = '2.3.9'
11+
__version__ = '2.3.10'
1212
__author__ = 'Tom Christie'
1313
__license__ = 'BSD 2-Clause'
1414
__copyright__ = 'Copyright 2011-2013 Tom Christie'

rest_framework/status.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@
66
"""
77
from __future__ import unicode_literals
88

9+
10+
def is_informational(code):
11+
return code >= 100 and code <= 199
12+
13+
def is_success(code):
14+
return code >= 200 and code <= 299
15+
16+
def is_redirect(code):
17+
return code >= 300 and code <= 399
18+
19+
def is_client_error(code):
20+
return code >= 400 and code <= 499
21+
22+
def is_server_error(code):
23+
return code >= 500 and code <= 599
24+
25+
926
HTTP_100_CONTINUE = 100
1027
HTTP_101_SWITCHING_PROTOCOLS = 101
1128
HTTP_200_OK = 200

rest_framework/tests/test_status.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from __future__ import unicode_literals
2+
from django.test import TestCase
3+
from rest_framework.status import (
4+
is_informational, is_success, is_redirect, is_client_error, is_server_error
5+
)
6+
7+
8+
class TestStatus(TestCase):
9+
def test_status_categories(self):
10+
self.assertFalse(is_informational(99))
11+
self.assertTrue(is_informational(100))
12+
self.assertTrue(is_informational(199))
13+
self.assertFalse(is_informational(200))
14+
15+
self.assertFalse(is_success(199))
16+
self.assertTrue(is_success(200))
17+
self.assertTrue(is_success(299))
18+
self.assertFalse(is_success(300))
19+
20+
self.assertFalse(is_redirect(299))
21+
self.assertTrue(is_redirect(300))
22+
self.assertTrue(is_redirect(399))
23+
self.assertFalse(is_redirect(400))
24+
25+
self.assertFalse(is_client_error(399))
26+
self.assertTrue(is_client_error(400))
27+
self.assertTrue(is_client_error(499))
28+
self.assertFalse(is_client_error(500))
29+
30+
self.assertFalse(is_server_error(499))
31+
self.assertTrue(is_server_error(500))
32+
self.assertTrue(is_server_error(599))
33+
self.assertFalse(is_server_error(600))

0 commit comments

Comments
 (0)
0