Esempio n. 1
0
    def test_clone_link_method_for_list_display_renders_object_clone_url(self):
        model_admin = ClonableModelAdmin(Post, default_admin_site)
        expected_link = '<a href="{0}">{1}</a>'.format(
            reverse('admin:posts_post_clone', args=(self.post.id, )),
            model_admin.clone_verbose_name)

        assert model_admin.clone_link(self.post) == expected_link
Esempio n. 2
0
    def test_clone_link_method_for_list_display_renders_object_clone_url(self):
        model_admin = ClonableModelAdmin(Post, default_admin_site)
        expected_link = '<a href="{0}">{1}</a>'.format(
            reverse('admin:posts_post_clone', args=(self.post.id,)),
            model_admin.clone_verbose_name)

        assert model_admin.clone_link(self.post) == expected_link
Esempio n. 3
0
    def test_clone_view_is_wrapped_as_admin_view(self):
        model = mock.Mock()
        admin_site = mock.Mock()
        admin_site.admin_view.return_value = '<wrapped clone view>'

        model_admin = ClonableModelAdmin(model, admin_site)
        clone_view_urlpattern = model_admin.get_urls()[0]

        assert '<wrapped clone view>' == clone_view_urlpattern.callback
Esempio n. 4
0
    def test_clone_should_raise_permission_denied(self):
        model_admin = ClonableModelAdmin(Post, default_admin_site)
        model_admin.has_add_permission = mock.Mock(return_value=False)

        request = object()
        object_id = object()

        with pytest.raises(PermissionDenied):
            model_admin.clone_view(request, object_id)

        model_admin.has_add_permission.assert_called_once_with(request)
    def test_clone_view_is_wrapped_as_admin_view(self):
        model = mock.Mock()
        admin_site = mock.Mock()
        # Fake ClonableModelAdmin.clone_view
        the_view = lambda a, b, c: HttpResponse()
        admin_site.admin_view.return_value = the_view

        model_admin = ClonableModelAdmin(model, admin_site)
        clone_view_urlpattern = model_admin.get_urls()[0]

        assert the_view == clone_view_urlpattern.callback
Esempio n. 6
0
    def test_clone_should_raise_permission_denied(self):
        model_admin = ClonableModelAdmin(Post, default_admin_site)
        model_admin.has_add_permission = mock.Mock(return_value=False)

        request = object()
        object_id = object()

        with pytest.raises(PermissionDenied):
            model_admin.clone_view(request, object_id)

        model_admin.has_add_permission.assert_called_once_with(request)
Esempio n. 7
0
    def test_clone_view_is_wrapped_as_admin_view(self):
        model = mock.Mock()
        admin_site = mock.Mock()
        # Fake ClonableModelAdmin.clone_view
        the_view = lambda a, b, c: HttpResponse()
        admin_site.admin_view.return_value = the_view

        model_admin = ClonableModelAdmin(model, admin_site)
        clone_view_urlpattern = model_admin.get_urls()[0]

        assert the_view == clone_view_urlpattern.callback
Esempio n. 8
0
    def test_clone_view_is_wrapped_as_admin_view(self):
        model = mock.Mock()
        admin_site = mock.Mock()
        admin_site.admin_view.return_value = '<wrapped clone view>'

        model_admin = ClonableModelAdmin(model, admin_site)
        clone_view_urlpattern = model_admin.get_urls()[0]

        if django.VERSION >= (1, 8):
            assert '<wrapped clone view>' == clone_view_urlpattern._callback_str
        else:
            assert '<wrapped clone view>' == clone_view_urlpattern.callback
Esempio n. 9
0
    def test_clone_view_is_wrapped_as_admin_view(self):
        model = mock.Mock()
        admin_site = mock.Mock()
        admin_site.admin_view.return_value = "<wrapped clone view>"

        model_admin = ClonableModelAdmin(model, admin_site)
        clone_view_urlpattern = model_admin.get_urls()[0]

        if django.VERSION >= (1, 8):
            assert "<wrapped clone view>" == clone_view_urlpattern._callback_str
        else:
            assert "<wrapped clone view>" == clone_view_urlpattern.callback