def test_reqfactory(db): factory = RequestFactory() request = factory.get('posts/') request.user = User.objects.create_user('username', '*****@*****.**', 'pass') response = PostList.as_view()(request) assert 200 == response.status_code
def create_post(self, user): # 포스트 생성 factory = APIRequestFactory() track_dir = os.path.join( settings.MEDIA_ROOT, 'author_tracks/The_Shortest_Straw_-_Guitar.mp3') with open(track_dir, 'rb') as author_track: data = { 'title': 'test_title', 'author_track': author_track, 'instrument': 'Guitar', 'genre': 'Heavy Metal', } request = factory.post(self.POST_API_VIEW_URL, data) force_authenticate(request, user=user) view = PostList.as_view() response = view(request) return response
"""pygram URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/3.0/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin from django.urls import path from django.conf import settings from django.conf.urls.static import static from posts.views import PostList, PostCreate, PostDetail urlpatterns = [ path('admin/', admin.site.urls), path('', PostList.as_view(), name='List'), path('new/', PostCreate.as_view(), name="new"), path('posts/<pk>/', PostDetail.as_view(), name='detail'), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from django.urls import path from posts.views import CreatePost, DeletePost, PostDetail, UserPost, PostList app_name = 'posts' urlpatterns = [ path('', PostList.as_view(), name='all'), path('new/', CreatePost.as_view(), name='create'), path('by/<username>/', UserPost.as_view(), name='for_user'), path('by/<username>/<int:pk>/', PostDetail.as_view(), name='single'), path('delete/<int:pk>', DeletePost.as_view(), name='delete'), ]
# -*- encoding: utf-8 -*- from posts.views import PostList, PostDetails from django.conf.urls import patterns, include, url urlpatterns = patterns('', url(r'^$', PostList.as_view(), name='postlist'), url(r'^(?P<slug>[a-zA-Z0-9_-]+)/$', PostDetails.as_view(), name='postdetails'), )
from django.conf.urls import include, url from rest_framework.urlpatterns import format_suffix_patterns from posts.views import TagList, TagDetail, PostList, PostDetail urlpatterns = [ url(r'^posts/$', PostList.as_view(), name='post-list'), url(r'^posts/(?P<pk>[0-9]+)/$', PostDetail.as_view(), name='post-detail'), url(r'^tags/$', TagList.as_view(), name='tag-list'), url(r'^tags/(?P<pk>[0-9]+)/$', TagDetail.as_view(), name='tag-detail'), ] urlpatterns = format_suffix_patterns(urlpatterns)
from django.conf.urls import url from posts.views import PostDetail, PostListCategory, PostList from posts.settings import POST_DETAIL_URL, POSTS_CATEGORY_DETAIL_URL, POSTS_LIST_URL urlpatterns = [ url(r'^detail/(?P<post_id>[\w-]+)/(?P<post_slug>[\w-]+)/$', PostDetail.as_view(), name=POST_DETAIL_URL), url(r'^(?P<category_id>[\w-]+)/(?P<category_slug>[\w-]+)/$', PostListCategory.as_view(), name=POSTS_CATEGORY_DETAIL_URL), url(r'^$', PostList.as_view(), name=POSTS_LIST_URL), ]
from drf_yasg import openapi from posts.views import PostList schema_view = get_schema_view( openapi.Info( title="Social_test API", default_version="v1", description="All API endpoints", terms_of_service="https://www.google.com/policies/terms/", contact=openapi.Contact(email=""), license=openapi.License(name=""), ), public=True, permission_classes=(permissions.AllowAny, ), ) urlpatterns = [ path("admin/", admin.site.urls), path("", PostList.as_view(), name="home"), path("accounts/", include("accounts.urls", namespace="accounts")), path("accounts/", include("django.contrib.auth.urls")), path("posts/", include("posts.urls", namespace="posts")), path("api/", include("posts.api.urls")), path( "swagger/", schema_view.with_ui("swagger", cache_timeout=0), name="schema-swagger-ui", ), ]
from django.urls import path from posts.views import PostList urlpatterns = [ path('', PostList.as_view()), ]
from django.contrib.auth.decorators import login_required from django.urls import path from posts.views import PostList, PostCreate, PostDetail, BlogView, UserList, \ UserDetail urlpatterns = [ path('', login_required(PostList.as_view()), name='feed'), path('blog/', login_required(BlogView.as_view()), name='blog'), path('users/', UserList.as_view(), name='users'), path('user/<int:pk>/', UserDetail.as_view(), name='user'), path('create/', PostCreate.as_view(), name='post_create'), path('<slug:slug>/', PostDetail.as_view(), name='post_detail'), ]
from django.conf.urls import url from posts.views import PostDetail, PostList urlpatterns = [ url(r'^(?P<id>[\w-]+)/(?P<slug>[\w-]+)/', PostDetail.as_view(), name='post_detail'), url(r'^', PostList.as_view(), name='posts_list'), ]
from django.conf.urls import url from django.urls import path, include from posts.views import PostCreate, PostLikeToggle, PostDetail, PostList, PostEdit app_name = 'posts' urlpatterns = [ path("", PostList.as_view(), name="list"), path('new/', PostCreate.as_view(), name='new'), path('<pk>/edit/', PostEdit.as_view(), name='edit'), path("<pk>/like/", PostLikeToggle.as_view(), name='like'), path("<pk>/", PostDetail.as_view(), name='detail') ]
from django.conf.urls import url from django.contrib.auth.decorators import login_required from posts.views import BlogList, BlogView, PostView, EditBlog, CreateBlog, CreatePost, PostDetail, EditPost, PostList, PostLikeAjaxView, CommentsView urlpatterns = [ url(r'^blogs/$', BlogList.as_view(), name='showBloglist'), url(r'^blogs/(?P<pk>\d+)/$', BlogView.as_view(), name='showBlog'), url(r'^posts/(?P<pk>\d+)/$', PostDetail.as_view(), name='showComments'), url(r'^posts/(?P<pk>\d+)/comments/$', CommentsView.as_view(), name='onlyComments'), url(r'^posts/(?P<pk>\d+)/like/$', login_required(PostLikeAjaxView.as_view()), name='post_ajax_like'), url(r'^blogs/add/$', login_required(CreateBlog.as_view()), name='createblog'), url(r'^blogs/(?P<pk>\d+)/add/$', login_required(CreatePost.as_view()), name='createpost'), url(r'^blogs/(?P<pk>\d+)/edit/$', EditBlog.as_view(), name='editblog'), url(r'^posts/(?P<pk>\d+)/edit/$', EditPost.as_view(), name='editpost'), url(r'^feed/$', PostList.as_view(), name='showFeed'), ]
from django.urls import path, include from posts.views import PostList urlpatterns = [ path("", PostList.as_view()), ]
from django.conf.urls import url from posts.views import PostList urlpatterns = [ url(r'^$', PostList.as_view(), name='my-post-list'), ]
"""ajax URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.1/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin from django.urls import path, include from posts.views import PostList urlpatterns = [ path('admin/', admin.site.urls), path('posts/', include('posts.urls')), path('', PostList.as_view(), name='home'), path('accounts/', include('accounts.urls')) ]
from django.conf.urls import url from posts.views import PageDetail, PostDetail, PostList urlpatterns = [ url(r'^posts/(?P<year>[0-9]{4})/(?P<pk>[0-9]+)/$', PostDetail.as_view(), name='post'), url(r'^tag/(?P<tag>[-\w]+)/$', PostList.as_view(), name='tag'), url(r'^(?P<slug>[-\w]+)/$', PageDetail.as_view(), name='page'), url(r'^$', PostList.as_view(), name='posts'), ]
def test_reqfactory(db): factory = RequestFactory() request = factory.get('posts/') request.user = factories.UserFactory() response = PostList.as_view()(request) assert 200 == response.status_code
from django.urls import path from posts.views import PostList, PostDetail app_name = 'posts' urlpatterns = [ path('', PostList.as_view(), name='post_list'), path('<int:pk>/', PostDetail.as_view(), name='post_detail'), ]
from django.conf.urls import url from rest_framework.urlpatterns import format_suffix_patterns from django.views.decorators.csrf import csrf_exempt from posts.views import PostList, PostDetail, PostSortingList, get_tags urlpatterns = [ url(r'^posts/$', PostList.as_view()), url(r'^posts/(?P<pk>[0-9]+)/$', PostDetail.as_view()), url(r'^posts/filters/$', get_tags), url(r'^posts/sortings/$', PostSortingList.as_view()), ] urlpatterns = format_suffix_patterns(urlpatterns)