Exemplo n.º 1
0
    def test_post_list_request(self):
        post = Post.objects.create(title="Title", description="Description", user=self.user)
        factory = APIRequestFactory()
        view = ListCreatePost.as_view()
        url = reverse("api_post_list_create")
        request = factory.get(url, {}, format="json")
        response = view(request)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data["count"], 1)
        response_post = response.data["results"][0]
        self.assertEqual(response_post["title"], post.title)
Exemplo n.º 2
0
    def test_post_list_request(self):
        post = Post.objects.create(title='Title', description='Description', user=self.user, location=self.city,
                                   subcategory=self.subcategory)
        factory = APIRequestFactory()
        view = ListCreatePost.as_view()
        url = reverse('api_post_list_create')
        request = factory.get(url, {}, format='json')
        response = view(request)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], 1)
        response_post = response.data['results'][0]
        self.assertEqual(response_post['title'], post.title)
Exemplo n.º 3
0
from django.conf.urls import url
from api.views import DetailUpdatePost, ListCreatePost, ListUser, ListCreateFavorite, ListTop50
from rest_framework.authtoken import views

urlpatterns = [
    url(r'^posts/(?P<pk>\d+)', DetailUpdatePost.as_view(), name='api_post_detail_update'),
    url(r'^posts/', ListCreatePost.as_view(), name='api_post_list_create'),
    url(r'^users/', ListUser.as_view(), name='api_user_list'),
    url(r'^api-token-auth/', views.obtain_auth_token),
    url(r'^favorites/', ListCreateFavorite.as_view(), name='api_favorite_list_create'),
    url(r'^top/', ListTop50.as_view(), name='top_50_list'),
]