def test_get_queryset_owner(self): user = UserModel.objects.get(pk=2) request = APIRequestFactory() request.user = user view = PostViewSet() view.action = 'update' view.request = request response = view.get_queryset() self.assertEqual(response.first().created_by, user) self.assertEqual(response.last().created_by, user)
def test_retrieve(self): template_renderer = TemplateHTMLRenderer template_renderer.format = 'html' request = APIRequestFactory() request.accepted_renderer = template_renderer request.query_params = dict() view = PostViewSet() view.kwargs = {'pk': 1} view.action = 'retrieve' view.request = request view.format_kwarg = '' response = view.retrieve(request) self.assertEqual(response.template_name, 'posts/detail.html')
def test_list(self): template_renderer = TemplateHTMLRenderer template_renderer.format = 'html' request = APIRequestFactory() request.accepted_renderer = template_renderer request.query_params = dict() request.GET = {} view = PostViewSet() view.action = 'list' view.request = request view.format_kwarg = '' response = view.list(request) self.assertEqual(response.template_name, 'posts/list.html')