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 response = newListView(self.request) self.assertEqual(response, mock_redirect.return_value) mock_redirect.assert_called_once_with(mock_form.save.return_value)
def test_redirects_home_if_form_invalid(self, mock_render, mockNewListForm): mock_form = mockNewListForm.return_value mock_form.is_valid.return_value = False response = newListView(self.request) self.assertEqual(response, mock_render.return_value) mock_render.assert_called_once_with(self.request, 'lists/index.html', {'form': mock_form})
def test_saves_owner_if_form_valid(self, mock_redirect, mockNewListForm): mock_form = mockNewListForm.return_value mock_form.is_valid.return_value = True newListView(self.request) mock_form.save.assert_called_once_with(owner=self.request.user)
def test_doesnt_save_owner_if_form_invalid(self, mockNewListForm): mock_form = mockNewListForm.return_value mock_form.is_valid.return_value = False newListView(self.request) self.assertFalse(mock_form.save.called)
def test_passes_POST_data_to_NewListForm(self, mock_redirect, mockNewListForm): newListView(self.request) mockNewListForm.assert_called_once_with(data=self.request.POST)