Example #1
0
    def test_passes_post_data_list_and_sharer_to_ShareListForm(
            self, post_request, mock_ShareListForm, mock_redirect):
        share_list(post_request, 1)

        mock_ShareListForm.assert_called_with(data=post_request.POST,
                                              list_id=1,
                                              sharer=post_request.user)
Example #2
0
    def test_share_a_list_with_another_user(self):
        user1 = User.objects.create(email="*****@*****.**")
        user2 = User.objects.create(email="*****@*****.**")

        list_ = List.objects.create(owner=user1)

        request = HttpRequest()
        request.POST["email"] = user2.email
        share_list(request, list_.id)

        self.assertEqual(list_.shared_with.count(), 1)
        self.assertIn(
            user2,
            list_.shared_with.all()
        )
Example #3
0
    def test_redirects_to_view_list_if_form_valid(self, post_request,
                                                  mock_form, mock_redirect):
        mock_form.is_valid.return_value = True
        response = share_list(post_request, 1)

        mock_redirect.assert_called_once_with(mock_form.save.return_value)
        assert response == mock_redirect.return_value
Example #4
0
    def test_renders_list_template_with_ShareListForm_empty_ItemForm_and_list_if_form_invalid(
            self, post_request, mock_form, mock_render, list_template,
            mock_ItemForm):
        mock_form.is_valid.return_value = False
        response = share_list(post_request, 1)

        mock_ItemForm.assert_called_once_with()
        mock_render.assert_called_once_with(
            post_request,
            list_template,
            {
                "form": mock_ItemForm.return_value,
                "share_form": mock_form,
                "list": mock_form.list
            },
        )
        assert response == mock_render.return_value
Example #5
0
    def test_form_not_saved_if_form_invalid(self, post_request, mock_form,
                                            mock_render):
        mock_form.is_valid.return_value = False
        share_list(post_request, 1)

        mock_form.save.assert_not_called()
Example #6
0
    def test_saves_form_if_form_valid(self, post_request, mock_form,
                                      mock_redirect):
        mock_form.is_valid.return_value = True
        share_list(post_request, 1)

        mock_form.save.assert_called_once()
Example #7
0
 def test_post_redirects_to_lists_page(self):
     response = share_list(self.request)
     self.assertContains(response, 'share_list')
Example #8
0
    def test_redirects_with_wrong_id(self):
        response = share_list(self.request, 'wawa')

        self.assertIsInstance(response, HttpResponse)
        # assert redirects
        self.assertEqual(response.status_code, 302)
Example #9
0
    def test_returns_response(self):
        response = share_list(self.request, str(self.user_list.id))

        self.assertIsInstance(response, HttpResponse)
        # assert redirects
        self.assertEqual(response.status_code, 302)
Example #10
0
    def test_calls_appropriate_methods(self, try_get_mock, share_with_mock):
        try_get_mock.return_value = self.user_list

        share_list(self.request, list_id=str(self.user_list.id))
        try_get_mock.assert_called_once_with(pk=str(self.user_list.id))
        share_with_mock.assert_called_once_with('*****@*****.**')