def test_redirects_to_form_returned_object_if_form_valid( self, mock_redirect, mockNewListForm): mock_form = mockNewListForm.return_value new_list_view = NewListView() new_list_view.request = self.request response = new_list_view.form_valid(mock_form) self.assertEqual(response, mock_redirect.return_value) mock_redirect.assert_called_once_with(mock_form.save.return_value)
def test_passes_POST_data_to_NewListForm(self, mockNewListForm): view = NewListView.as_view() view(self.request) mockNewListForm.assert_called_once_with(data=self.request.POST, files={}, initial={}, instance=None, prefix=None)
def test_redirects_to_form_returned_object_if_form_valid( self, mock_redirect, mockNewListForm): mock_form = mockNewListForm.return_value mock_form.is_valid.return_value = True view = NewListView.as_view() response = view(self.request) self.assertEqual(response, mock_redirect.return_value) mock_redirect.assert_called_once_with(mock_form.save.return_value)
def test_renders_home_template_with_form_if_form_invalid( self, mock_render, mockNewListForm): mock_form = mockNewListForm.return_value mock_form.is_valid.return_value = False view = NewListView.as_view() response = view(self.request) self.assertEqual(response, mock_render.return_value) mock_render.assert_called_once_with(self.request, 'home.html', {'form': mock_form})
from django.conf.urls import patterns, include, url from django.contrib import admin from lists.views import NewListView, ViewAndAddToListView admin.autodiscover() urlpatterns = patterns('', url(r'^(?P<pk>\d+)/$', ViewAndAddToListView.as_view(), name='view_list'), url(r'^new$', NewListView.as_view(), name='new_list'), # url(r'^admin/', include(admin.site.urls)), )
"""superlists URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.8/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. Add an import: from blog import urls as blog_urls 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) """ from django.conf.urls import url from lists import views from lists.views import NewListView, ViewAndAddToList urlpatterns = [ url(r'^new$', NewListView.as_view(), name="new_list"), url(r'^(?P<pk>\d+)/$', ViewAndAddToList.as_view(), name="view_list"), url(r'^users/(.+)/$', views.my_lists, name="my_lists"), url(r'^(\d+)/share$', views.share_list, name="share_list"), ]
def test_does_not_save_if_form_invalid(self, mockNewListForm): mock_form = mockNewListForm.return_value mock_form.is_valid.return_value = False view = NewListView.as_view() view(self.request) self.assertFalse(mock_form.save.called)
def test_saves_form_with_owner_if_form_valid(self, mockNewListForm): mock_form = mockNewListForm.return_value mock_form.is_valid.return_value = True view = NewListView.as_view() view(self.request) mock_form.save.assert_called_once_with(owner=self.request.user)
def test_saves_form_with_owner_if_form_valid(self, mockNewListForm): mock_form = mockNewListForm.return_value new_list_view = NewListView() new_list_view.request = self.request new_list_view.form_valid(mock_form) mock_form.save.assert_called_once_with(owner=self.request.user)
from django.conf.urls import url from lists.views import my_lists, share_list, new_list, view_list, NewListView, ViewAndAddToList urlpatterns = [ # url(r'^lists/the-only-list-in-the-world/$', 'lists.views.view_list', # name='view_list' # ), # url(r'^lists/(.+)/$', 'lists.views.view_list', name='view_list'), # url(r'^(\d+)/add_item$', views.add_item, name='add_item'), # url(r'^(\d+)/$', view_list, name='view_list'), url(r"^(?P<pk>\d+)/$", ViewAndAddToList.as_view(), name="view_list"), # url(r'^new$', new_list, name='new_list'), # url(r'^new$', new_list2, name='new_list'), url(r"^new$", NewListView.as_view(), name="new_list"), url(r"^users/(.+)/$", my_lists, name="my_lists"), url(r"^(\d+)/share$", share_list, name="share_list"), ]
# -*- coding: utf-8 -*- """ Lists app URL Configuration """ from django.urls import path from lists.views import NewListView, my_lists, share_list, view_list app_name = 'lists' urlpatterns = [ path('new', NewListView.as_view(), name='new_list'), path('<int:list_id>/', view_list, name='view_list'), path('users/<user_email>', my_lists, name='my_lists'), path('share-list/<int:list_id>', share_list, name='share_list'), ]