Exemple #1
0
    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)
Exemple #2
0
    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})
Exemple #3
0
 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)
Exemple #4
0
 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)
Exemple #5
0
 def test_passes_POST_data_to_NewListForm(self, mock_redirect,
                                          mockNewListForm):
     newListView(self.request)
     mockNewListForm.assert_called_once_with(data=self.request.POST)