mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Merge 6dbcbcc9a8
into 5ee472718a
This commit is contained in:
commit
d15a2fc21a
|
@ -1,9 +1,10 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from django.conf.urls import patterns
|
from django.conf.urls import patterns
|
||||||
|
|
||||||
from .views import MockView
|
from .views import MockView, CreateOnlyView
|
||||||
|
|
||||||
urlpatterns = patterns(
|
urlpatterns = patterns(
|
||||||
'',
|
'',
|
||||||
(r'^$', MockView.as_view()),
|
(r'^$', MockView.as_view()),
|
||||||
|
(r'^create/$', CreateOnlyView.as_view()),
|
||||||
)
|
)
|
||||||
|
|
|
@ -63,3 +63,11 @@ class NoDropdownWithoutAuthTests(TestCase):
|
||||||
def test_dropdown_not_shown_when_logged_out(self):
|
def test_dropdown_not_shown_when_logged_out(self):
|
||||||
response = self.client.get('/')
|
response = self.client.get('/')
|
||||||
self.assertNotContains(response, '<li class="dropdown">')
|
self.assertNotContains(response, '<li class="dropdown">')
|
||||||
|
|
||||||
|
|
||||||
|
class CreatOnlyModelTests(TestCase):
|
||||||
|
urls = 'tests.browsable_api.no_auth_urls'
|
||||||
|
|
||||||
|
def test_create_only_model(self):
|
||||||
|
with self.assertRaises(AssertionError):
|
||||||
|
self.client.post('/create/', {'text': 'creating'})
|
||||||
|
|
|
@ -3,8 +3,12 @@ from __future__ import unicode_literals
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework import authentication
|
from rest_framework import authentication
|
||||||
from rest_framework import renderers
|
from rest_framework import renderers
|
||||||
|
from rest_framework import generics
|
||||||
|
from rest_framework import serializers
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
from tests.models import BasicModel
|
||||||
|
|
||||||
|
|
||||||
class MockView(APIView):
|
class MockView(APIView):
|
||||||
|
|
||||||
|
@ -13,3 +17,19 @@ class MockView(APIView):
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
return Response({'a': 1, 'b': 2, 'c': 3})
|
return Response({'a': 1, 'b': 2, 'c': 3})
|
||||||
|
|
||||||
|
|
||||||
|
class CreateOnlySerializer(serializers.ModelSerializer):
|
||||||
|
def restore_object(self, attrs, instance=None):
|
||||||
|
assert instance is None, 'Cannot update models with this serializer'
|
||||||
|
return super(CreateOnlySerializer, self).restore_object(attrs, instance=instance)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = BasicModel
|
||||||
|
|
||||||
|
|
||||||
|
class CreateOnlyView(generics.ListCreateAPIView):
|
||||||
|
authentication_classes = (authentication.SessionAuthentication,)
|
||||||
|
renderer_classes = (renderers.BrowsableAPIRenderer,)
|
||||||
|
serializer_class = CreateOnlySerializer
|
||||||
|
model = BasicModel
|
||||||
|
|
Loading…
Reference in New Issue
Block a user