def test_no_todos_in_context(self): request = self.factory.get('/') request.user = UserFactory(password=random_string_generator()) response = TodoList.as_view()(request) self.assertEqual( list(response.context_data['latest']), [], )
def test_todos_in_context(self): request = self.factory.get('/') todo = TodoFactory() request.user = todo.user response = TodoList.as_view()(request) self.assertEqual( list(response.context_data['latest']), [todo], )
def test_post_todo_with_invalid_data(self): post_data = { 'improper_property': 'todo1', } request = self.request_factory.post(reverse('todos:todo-list'), post_data, format='json') force_authenticate(request, user=self.user) view = TodoList.as_view() response = view(request) response.render() self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_post_todo(self): post_data = { 'name': 'todo1', } request = self.request_factory.post(reverse('todos:todo-list'), post_data, format='json') force_authenticate(request, user=self.user) view = TodoList.as_view() response = view(request) response.render() self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(Todo.objects.all().count(), 1)
def test_get_all_todos(self): todo1 = Todo(name='todo1', user=self.user) todo1.save() todo2 = Todo(name='todo2', user=self.user) todo2.save() request = self.request_factory.get(reverse('todos:todo-list'), format='json') force_authenticate(request, user=self.user) view = TodoList.as_view() response = view(request) response.render() todos = Todo.objects.all() serializer = TodoSerializer(todos, many=True, context={'request': request}) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data, serializer.data)
from django.urls import path from todos.views import TodoList, DeleteItems, UploadImage from django.conf import settings from django.conf.urls.static import static urlpatterns = [ path('', TodoList.as_view(), name='todo-list'), path('delete/<itemId>', DeleteItems.as_view(), name='todo-delete'), path('uploads/', UploadImage.as_view(), name='upload-image'), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
"""jwtAuth URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.11/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf.urls import url from django.contrib import admin from rest_framework_jwt.views import obtain_jwt_token, refresh_jwt_token from todos.views import TodoList from authentication.views import AuthRegister, CustomObtainJSONWebToken urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^login/', CustomObtainJSONWebToken.as_view()), url(r'^get-todo-list/', TodoList.as_view()), url(r'^token-refresh/', refresh_jwt_token), url(r'^register/$', AuthRegister.as_view()), ]
from django.urls import path from rest_framework.urlpatterns import format_suffix_patterns from todolist.urls import ROUTER from todos.views import TodoCreate, TodoDetail, TodoList, TodoViewSet app_name = 'todos' ROUTER.register(r'todos', TodoViewSet, base_name='todo') urlpatterns = [ path(r'', TodoList.as_view(), name='list'), path(r'<int:pk>', TodoDetail.as_view(), name='detail'), path(r'create/', TodoCreate.as_view(), name='create'), ] urlpatterns = format_suffix_patterns(urlpatterns) # TODO: Implement 2FA & update corresponding Cover letter # TODO: Implement TBA using django-allauth & update corresponding Cover letter
from django.urls import path from todos.views import TodoList, UserList urlpatterns = [ path('users/', UserList.as_view(), name='users'), path('todos/', TodoList.as_view(), name='todos') ]
"""todolist URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.2/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 todos.views import TodoLV, TodoList, TodoDetail from rest_framework import routers routers = routers urlpatterns = [ path('admin/', admin.site.urls), path('todos/', TodoLV.as_view()), path('api/todos/', TodoList.as_view()), path('api/todos/<int:todo_id>/', TodoDetail.as_view()), ]