aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework
diff options
context:
space:
mode:
authorEdmond Wong2013-09-03 12:30:18 -0700
committerEdmond Wong2013-09-03 12:30:18 -0700
commit6e7e4fc01c5ddaf668f17f1d1f201a14a26f72f3 (patch)
tree8de07353f3f081117cc3627399a825862f1d472d /rest_framework
parent3063a50fc20f0bfb7308e668cf083c5ae0876dac (diff)
downloaddjango-rest-framework-6e7e4fc01c5ddaf668f17f1d1f201a14a26f72f3.tar.bz2
Added test for OPTIONS before object creation from a PUT
Diffstat (limited to 'rest_framework')
-rw-r--r--rest_framework/generics.py4
-rw-r--r--rest_framework/tests/test_generics.py42
2 files changed, 45 insertions, 1 deletions
diff --git a/rest_framework/generics.py b/rest_framework/generics.py
index 4d909ef1..7d1bf794 100644
--- a/rest_framework/generics.py
+++ b/rest_framework/generics.py
@@ -360,7 +360,9 @@ class GenericAPIView(views.APIView):
self.get_object()
except Http404:
# Http404 should be acceptable and the serializer
- # metadata should be populated.
+ # metadata should be populated. Except this so the
+ # outer "else" clause of the try-except-else block
+ # will be executed.
pass
except (exceptions.APIException, PermissionDenied):
pass
diff --git a/rest_framework/tests/test_generics.py b/rest_framework/tests/test_generics.py
index 7a87d389..79cd99ac 100644
--- a/rest_framework/tests/test_generics.py
+++ b/rest_framework/tests/test_generics.py
@@ -272,6 +272,48 @@ class TestInstanceView(TestCase):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, expected)
+ def test_options_before_instance_create(self):
+ """
+ OPTIONS requests to RetrieveUpdateDestroyAPIView should return metadata
+ before the instance has been created
+ """
+ request = factory.options('/999')
+ with self.assertNumQueries(1):
+ response = self.view(request, pk=999).render()
+ expected = {
+ 'parses': [
+ 'application/json',
+ 'application/x-www-form-urlencoded',
+ 'multipart/form-data'
+ ],
+ 'renders': [
+ 'application/json',
+ 'text/html'
+ ],
+ 'name': 'Instance',
+ 'description': 'Example description for OPTIONS.',
+ 'actions': {
+ 'PUT': {
+ 'text': {
+ 'max_length': 100,
+ 'read_only': False,
+ 'required': True,
+ 'type': 'string',
+ 'label': 'Text comes here',
+ 'help_text': 'Text description.'
+ },
+ 'id': {
+ 'read_only': True,
+ 'required': False,
+ 'type': 'integer',
+ 'label': 'ID',
+ },
+ }
+ }
+ }
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ self.assertEqual(response.data, expected)
+
def test_get_instance_view_incorrect_arg(self):
"""
GET requests with an incorrect pk type, should raise 404, not 500.