def test_post_data(self): create_url = reverse("posts-api:create") request = self.factory.post(create_url, data=self.data) response1 = PostCreateAPIView.as_view()(request) self.assertEqual(response1.status_code, 401) force_authenticate(request, user=self.user) response = PostCreateAPIView.as_view()(request) self.assertEqual(response.status_code, 201)
def test_crud_data(self): obj = Post.objects.create(title='Test API Post', content='New Content', publish=timezone.now().date()) create_url = reverse('posts-api:create') update_url = reverse('posts-api:update', kwargs={'slug': obj.slug}) delete_url = reverse('posts-api:delete', kwargs={'slug': obj.slug}) request_create = self.factory.post(create_url, data=self.data) force_authenticate(request_create, self.user) response_create = PostCreateAPIView.as_view()(request_create, slug=obj.slug) self.assertEqual(response_create.status_code, 201) request_update = self.factory.put(update_url, data=self.data) force_authenticate(request_update, self.user) response_update = PostUpdateAPIView.as_view()(request_update, slug=obj.slug) self.assertEqual(response_update.status_code, 200) request_delete = self.factory.delete(delete_url) force_authenticate(request_delete, self.user) response_delete = PostDeleteAPIView.as_view()(request_delete, slug=obj.slug) self.assertEqual(response_delete.status_code, 204)
from django.conf.urls import url from posts.api.views import ( PostCreateAPIView, PostDeleteAPIView, PostDetailAPIView, PostListAPIView, PostUpdateAPIView, ) urlpatterns = [ url(r'^$', PostListAPIView.as_view(), name='list'), url(r'^create/$', PostCreateAPIView.as_view(), name='create'), url(r'^(?P<slug>[\w-]+)/$', PostDetailAPIView.as_view(), name='detail'), url(r'^(?P<slug>[\w-]+)/edit/$', PostUpdateAPIView.as_view(), name='update'), url(r'^(?P<slug>[\w-]+)/delete/$', PostDeleteAPIView.as_view(), name='delete') ]
from django.conf.urls import url from posts.api.views import PostListAPIView, PostDetailAPIView, PostUpdateAPIView, PostDeleteAPIView, PostCreateAPIView urlpatterns = [ url(r'^$', PostListAPIView.as_view(), name="list"), url(r'^create/$', PostCreateAPIView.as_view(), name="create"), url(r'^(?P<slug>[\w-]+)/$', PostDetailAPIView.as_view(), name="detail"), url(r'^(?P<slug>[\w-]+)/edit/$', PostUpdateAPIView.as_view(), name="update"), url(r'^(?P<slug>[\w-]+)/delete/$', PostDeleteAPIView.as_view(), name="delete"), ]
path('api/sign_up/', SignupView.as_view(), name="sign_up"), path('api/faq/', FoireAuxQuestionsApiView.as_view(), name='faq'), path('api/lexique/', LexiqueApiView.as_view(), name='lexique'), path('api/category/', CategoryListView.as_view(), name='category-list'), path('api/category/<int:pk>/', CategoryDetailView.as_view(), name='category-detail'), path('api/subcategory/', SubCategoryListView.as_view(), name='subcategory-list'), path('api/subcategory/<int:pk>/', SubCategoryDetailView.as_view(), name='subcategory-detail'), path('api/tags/', TagListAPIView.as_view(), name='tag-list'), path('api/posts/', PostListAPIView.as_view(), name='post-list'), path('api/posts/create/', PostCreateAPIView.as_view(), name='post-create'), path('api/posts/<int:pk>/update/', PostUpdateAPIView.as_view(), name='post-update'), path('api/posts/<int:pk>/remove/', PostUpdateAPIView.as_view(), name='post-delete'), path('api/posts/<str:slug>/', PostDetailAPIView.as_view(), name='post-detail'), path('api/genres/', GenresListView.as_view(), name='genre-list'), path('api/classement/', ClassementListView.as_view(), name='classement-list'), path('api/status/', StatusListView.as_view(), name='status-list'), path('api/fanfics/', FanficCreateApiView.as_view(), name='fanfic-list'),
from django.conf.urls import url from django.contrib import admin from posts.api.views import ( PostListAPIView, PostDetailAPIView, PostUpdateAPIView, PostDestroyAPIView, PostCreateAPIView, ) urlpatterns = [ url(r'^$', PostListAPIView.as_view(), name='list'), url(r'^create/$', PostCreateAPIView.as_view()), url(r'^(?P<slug>[\w-]+)/$', PostDetailAPIView.as_view(), name='detail'), url(r'^(?P<slug>[\w-]+)/edit/$', PostUpdateAPIView.as_view(), name='update'), url(r'^(?P<slug>[\w-]+)/delete/$', PostDestroyAPIView.as_view()), #url(r'^posts/$', "<appname>.views.<function_name>"), ]
from django.urls import path from posts.api.views import PostListAPIView, PostDetailAPIView, PostCreateAPIView app_name = 'posts' urlpatterns = [ path('', PostListAPIView.as_view(), name='list'), path('create/', PostCreateAPIView.as_view(), name='create'), path('<slug>/', PostDetailAPIView.as_view(), name='detail'), ]
from django.conf.urls import url from posts.api.views import PostListAPIView, PostDetailAPIView, PostDeleteAPIView, PostUpdateAPIView, PostCreateAPIView urlpatterns = [ url(r"^$", PostListAPIView.as_view(), name='list'), url(r"^create/$", PostCreateAPIView.as_view(), name='create'), url(r"^(?P<slug>[\w-]+)/$", PostDetailAPIView.as_view(), name='detail'), url(r"^(?P<slug>[\w-]+)/edit/$", PostUpdateAPIView.as_view(), name='update'), url(r"^(?P<slug>[\w-]+)/delete/$", PostDeleteAPIView.as_view(), name='delete'), #url(r"^(?P<pk>\d+)/$", PostDetailAPIView.as_view(), name='detail'), ]
from django.conf.urls import url from django.contrib import admin from posts.api.views import ( PostListAPIView, PostDeleteAPIView, PostDetailAPIView, PostUpdateAPIView, PostCreateAPIView, ) urlpatterns = [ url(r'^$', PostListAPIView.as_view(), name='list'), url(r'^create/$', PostCreateAPIView.as_view(), name='create'), url(r'^(?P<slug>[\w-]+)/$', PostDetailAPIView.as_view(), name='detail'), url(r'^(?P<slug>[\w-]+)/edit/$', PostUpdateAPIView.as_view(), name='update'), url(r'^(?P<slug>[\w-]+)/delete/$', PostDeleteAPIView.as_view(),name='delete'), # url(r'^(?P<pk>[\w-]+)/$', PostDetailAPIView.as_view(), name='pk-detail'), # url(r'^create/$', post_create), # url(r'^(?P<slug>[\w-]+)/$', post_detail, name='detail'), # url(r'^posts/$', "<appname>.views.<function_name>"), ]
from django.conf.urls import url from django.contrib import admin from posts.api.views import (PostListAPIView, PostDetailAPIView, PostUpdateAPIView, PostDeleteAPIView, PostCreateAPIView) urlpatterns = [ url(r'^$', PostListAPIView.as_view(), name="list"), #blank makes it default home page url(r'^create/$', PostCreateAPIView.as_view(), name="create"), url(r'^(?P<slug>[\w-]+)/$', PostDetailAPIView.as_view(), name="detail"), url(r'^(?P<slug>[\w-]+)/edit/$', PostUpdateAPIView.as_view(), name='update'), url(r'^(?P<slug>[\w-]+)/delete/$', PostDeleteAPIView.as_view(), name='delete'), # url(r'^create/$', post_create), ]