コード例 #1
0
ファイル: test_register.py プロジェクト: disko/Kotti
    def test_register_submit_groups_and_roles(self, root):
        from kotti.views.login import register
        from pyramid.httpexceptions import HTTPFound

        request = DummyRequest()
        request.POST['title'] = u'Test User'
        request.POST['name'] = u'test'
        request.POST['email'] = u'*****@*****.**'
        request.POST['register'] = u'register',

        with patch('kotti.views.login.UserAddFormView') as form:
            with patch('kotti.views.login.get_principals'):
                with patch('kotti.views.login.get_settings') as get_settings:
                    get_settings.return_value = {
                        'kotti.register.group': 'mygroup',
                        'kotti.register.role': 'myrole',
                        }

                    res = register(root, request)

        form.assert_has_calls([
            call().add_user_success({
                'name': u'test',
                'roles': {u'role:myrole'},
                'title': u'Test User',
                'send_email': True,
                'groups': [u'mygroup'],
                'email': u'*****@*****.**',
                })])
        assert(isinstance(res, HTTPFound))
コード例 #2
0
    def test_register_submit_empty(self, root):
        from kotti.views.login import register

        request = DummyRequest()
        request.POST["register"] = u"register"
        res = register(root, request)
        assert "There was a problem with your submission" in res["form"]
コード例 #3
0
ファイル: test_register.py プロジェクト: disko/Kotti
    def test_register_submit_empty(self, root):
        from kotti.views.login import register

        request = DummyRequest()
        request.POST['register'] = u'register'
        res = register(root, request)
        assert 'There was a problem with your submission' in res['form']
コード例 #4
0
ファイル: test_node_views.py プロジェクト: pombredanne/Kotti
    def test_multi_delete(self):
        from kotti import DBSession
        from kotti.resources import Node
        from kotti.resources import Document
        from kotti.resources import File
        from kotti.views.edit.actions import NodeActions

        root = DBSession.query(Node).get(1)
        root['child1'] = Document(title=u"Child 1")
        root['child2'] = Document(title=u"Child 2")
        root['file1'] = File(title=u"File 1")

        request = DummyRequest()
        request.POST = MultiDict()
        id1 = str(root['child1'].id)
        id2 = str(root['child2'].id)
        id3 = str(root['file1'].id)
        request.POST.add('delete_nodes', u'delete_nodes')
        NodeActions(root, request).delete_nodes()
        assert request.session.pop_flash('info') ==\
            [u'Nothing deleted.']

        request.POST.add('children-to-delete', id1)
        request.POST.add('children-to-delete', id2)
        request.POST.add('children-to-delete', id3)
        NodeActions(root, request).delete_nodes()
        assert request.session.pop_flash('success') ==\
            [u'${title} deleted.', u'${title} deleted.', u'${title} deleted.']
コード例 #5
0
ファイル: test_node_views.py プロジェクト: rkintzi/Kotti
    def test_multi_rename(self):
        from kotti import DBSession
        from kotti.resources import Node
        from kotti.resources import Document
        from kotti.views.edit.actions import NodeActions
        self.setUp()
        root = DBSession.query(Node).get(1)
        root['child1'] = Document(title=u"Child 1")
        root['child2'] = Document(title=u"Child 2")
        request = DummyRequest()
        request.POST = MultiDict()
        id1 = str(root['child1'].id)
        id2 = str(root['child2'].id)
        request.POST.add('children-to-rename', id1)
        request.POST.add('children-to-rename', id2)
        request.POST.add(id1 + '-name', u'')
        request.POST.add(id1 + '-title', u'Unhappy Child')
        request.POST.add(id2 + '-name', u'happy-child')
        request.POST.add(id2 + '-title', u'')
        request.POST.add('rename_nodes', u'rename_nodes')
        NodeActions(root, request).rename_nodes()
        assert request.session.pop_flash('error') ==\
            [u'Name and title are required.']

        request.POST.add(id1 + '-name', u'unhappy-child')
        request.POST.add(id1 + '-title', u'Unhappy Child')
        request.POST.add(id2 + '-name', u'happy-child')
        request.POST.add(id2 + '-title', u'Happy Child')
        request.POST.add('rename_nodes', u'rename_nodes')
        NodeActions(root, request).rename_nodes()
        assert request.session.pop_flash('success') ==\
            [u'Your changes have been saved.']
コード例 #6
0
    def test_register_submit_groups_and_roles(self, root):
        from kotti.views.login import register
        from pyramid.httpexceptions import HTTPFound

        request = DummyRequest()
        request.POST["title"] = u"Test User"
        request.POST["name"] = u"test"
        request.POST["email"] = u"*****@*****.**"
        request.POST["register"] = (u"register",)

        with patch("kotti.views.login.UserAddFormView") as form:
            with patch("kotti.views.login.get_principals"):
                with patch("kotti.views.login.get_settings") as get_settings:
                    get_settings.return_value = {"kotti.register.group": "mygroup", "kotti.register.role": "myrole"}

                    res = register(root, request)

        form.assert_has_calls(
            [
                call().add_user_success(
                    {
                        "name": u"test",
                        "roles": set([u"role:myrole"]),
                        "title": u"Test User",
                        "send_email": True,
                        "groups": [u"mygroup"],
                        "email": u"*****@*****.**",
                    }
                )
            ]
        )
        assert isinstance(res, HTTPFound)
コード例 #7
0
    def test_register_submit(self, root):
        from kotti.views.login import register
        from pyramid.httpexceptions import HTTPFound

        request = DummyRequest()
        request.POST["title"] = u"Test User"
        request.POST["name"] = u"test"
        request.POST["email"] = u"*****@*****.**"
        request.POST["register"] = (u"register",)

        with patch("kotti.views.login.UserAddFormView") as form:
            with patch("kotti.views.login.get_principals"):
                res = register(root, request)
                form.assert_has_calls(
                    [
                        call().add_user_success(
                            {
                                "name": u"test",
                                "roles": u"",
                                "title": u"Test User",
                                "send_email": True,
                                "groups": u"",
                                "email": u"*****@*****.**",
                            }
                        )
                    ]
                )
        assert isinstance(res, HTTPFound)
コード例 #8
0
ファイル: test_security_views.py プロジェクト: Kotti/Kotti
    def test_search(self, extra_principals, root):
        from kotti.security import get_principals
        from kotti.views.users import UsersManage

        request = DummyRequest()
        P = get_principals()

        request.params["search"] = ""
        request.params["query"] = "Joe"
        entries = UsersManage(root, request)()["entries"]
        assert len(entries) == 0
        assert request.session.pop_flash("info") == ["No users or groups were found."]
        request.params["query"] = "Bob"
        entries = UsersManage(root, request)()["entries"]
        assert entries[0][0] == P["bob"]
        assert entries[0][1] == ([], [])
        assert entries[1][0] == P["group:bobsgroup"]
        assert entries[1][1] == ([], [])

        P["bob"].groups = ["group:bobsgroup"]
        P["group:bobsgroup"].groups = ["role:admin"]
        entries = UsersManage(root, request)()["entries"]
        # assert entries[0][1] == (['group:bobsgroup', 'role:admin'], ['role:admin'])  # noqa
        assert set(entries[0][1][0]) == {"group:bobsgroup", "role:admin"}
        assert entries[0][1][1] == ["role:admin"]
        assert entries[1][1] == (["role:admin"], [])
コード例 #9
0
ファイル: test_node_views.py プロジェクト: Kotti/Kotti
    def test_multi_rename(self, root):
        from kotti.resources import Document
        from kotti.views.edit.actions import NodeActions

        self.setUp()
        root["child1"] = Document(title="Child 1")
        root["child2"] = Document(title="Child 2")
        request = DummyRequest()
        request.POST = MultiDict()
        id1 = str(root["child1"].id)
        id2 = str(root["child2"].id)
        request.POST.add("children-to-rename", id1)
        request.POST.add("children-to-rename", id2)
        request.POST.add(id1 + "-name", "")
        request.POST.add(id1 + "-title", "Unhappy Child")
        request.POST.add(id2 + "-name", "happy-child")
        request.POST.add(id2 + "-title", "")
        request.POST.add("rename_nodes", "rename_nodes")
        NodeActions(root, request).rename_nodes()
        assert request.session.pop_flash("error") == ["Name and title are required."]

        request.POST.add(id1 + "-name", "unhappy-child")
        request.POST.add(id1 + "-title", "Unhappy Child")
        request.POST.add(id2 + "-name", "happy-child")
        request.POST.add(id2 + "-title", "Happy Child")
        request.POST.add("rename_nodes", "rename_nodes")
        NodeActions(root, request).rename_nodes()
        assert request.session.pop_flash("success") == ["Your changes have been saved."]
コード例 #10
0
ファイル: test_node_views.py プロジェクト: Kotti/Kotti
    def test_multi_delete(self, root):
        from kotti.resources import Document
        from kotti.resources import File
        from kotti.views.edit.actions import NodeActions

        root["child1"] = Document(title="Child 1")
        root["child2"] = Document(title="Child 2")
        root["file1"] = File(title="File 1")

        request = DummyRequest()
        request.POST = MultiDict()
        id1 = str(root["child1"].id)
        id2 = str(root["child2"].id)
        id3 = str(root["file1"].id)
        request.POST.add("delete_nodes", "delete_nodes")
        NodeActions(root, request).delete_nodes()
        assert request.session.pop_flash("info") == ["Nothing was deleted."]

        request.POST.add("children-to-delete", id1)
        request.POST.add("children-to-delete", id2)
        request.POST.add("children-to-delete", id3)
        NodeActions(root, request).delete_nodes()
        assert request.session.pop_flash("success") == [
            "${title} was deleted.",
            "${title} was deleted.",
            "${title} was deleted.",
        ]
コード例 #11
0
    def test_search(self, extra_principals, root):
        from kotti.security import get_principals
        from kotti.views.users import UsersManage

        request = DummyRequest()
        P = get_principals()

        request.params['search'] = u''
        request.params['query'] = u'Joe'
        entries = UsersManage(root, request)()['entries']
        assert len(entries) == 0
        assert (request.session.pop_flash('info') ==
                [u'No users or groups were found.'])
        request.params['query'] = u'Bob'
        entries = UsersManage(root, request)()['entries']
        assert entries[0][0] == P['bob']
        assert entries[0][1] == ([], [])
        assert entries[1][0] == P['group:bobsgroup']
        assert entries[1][1] == ([], [])

        P[u'bob'].groups = [u'group:bobsgroup']
        P[u'group:bobsgroup'].groups = [u'role:admin']
        entries = UsersManage(root, request)()['entries']
        assert (entries[0][1] ==
                (['group:bobsgroup', 'role:admin'], ['role:admin']))
        assert entries[1][1] == (['role:admin'], [])
コード例 #12
0
ファイル: test_security_views.py プロジェクト: dnouri/Kotti
    def test_search(self):
        from kotti.resources import get_root
        from kotti.security import get_principals
        from kotti.tests.test_node_views import TestNodeShare
        from kotti.views.users import users_manage

        root = get_root()
        request = DummyRequest()
        P = get_principals()
        TestNodeShare.add_some_principals()

        request.params['search'] = u''
        request.params['query'] = u'Joe'
        entries = users_manage(root, request)['entries']
        self.assertEqual(len(entries), 0)
        self.assertEqual(request.session.pop_flash('info'),
                         [u'No users or groups found.'])
        request.params['query'] = u'Bob'
        entries = users_manage(root, request)['entries']
        self.assertEqual(entries[0][0], P['bob'])
        self.assertEqual(entries[0][1], ([], []))
        self.assertEqual(entries[1][0], P['group:bobsgroup'])
        self.assertEqual(entries[1][1], ([], []))

        P[u'bob'].groups = [u'group:bobsgroup']
        P[u'group:bobsgroup'].groups = [u'role:admin']
        entries = users_manage(root, request)['entries']
        self.assertEqual(entries[0][1],
                         (['group:bobsgroup', 'role:admin'], ['role:admin']))
        self.assertEqual(entries[1][1], (['role:admin'], []))
コード例 #13
0
ファイル: test_util.py プロジェクト: dnouri/Kotti
    def setUp(self):
        from kotti.util import request_cache

        registry = Registry('testing')
        request = DummyRequest()
        request.registry = registry
        super(TestRequestCache, self).setUp(registry=registry, request=request)
        self.cache_decorator = request_cache
コード例 #14
0
ファイル: test_events.py プロジェクト: dnouri/Kotti
 def setUp(self):
     # We're jumping through some hoops to allow the event handlers
     # to be able to do 'pyramid.threadlocal.get_current_request'
     # and 'authenticated_userid'.
     registry = Registry('testing')
     request = DummyRequest()
     request.registry = registry
     super(TestEvents, self).setUp(registry=registry, request=request)
     self.config.include('kotti.events')
コード例 #15
0
ファイル: test_rss.py プロジェクト: cullerton/kotti_feed
    def test_rss_icon_at_root(self):
        from kotti_feed.views import rss_icon

        request = DummyRequest()
        request.static_url = lambda url: url
        icon = rss_icon(request.context, request)
        assert 'rss_url' in icon
        assert 'icon_url' in icon
        assert icon['rss_url'] == 'http://example.com/rss_view'
コード例 #16
0
ファイル: test_security.py プロジェクト: Doik/Kotti
    def test_login(self):
        from kotti.views.login import login
        request = DummyRequest()

        # No login attempt:
        result = login(None, request)
        self.assert_(isinstance(result, dict))
        self.assertEqual(request.session.pop_flash('success'), [])
        self.assertEqual(request.session.pop_flash('error'), [])

        # Attempt to log in before Bob exists:
        request.params['submit'] = u'on'
        request.params['login'] = u'bob'
        request.params['password'] = u'secret'
        result = login(None, request)
        self.assert_(isinstance(result, dict))
        self.assertEqual(request.session.pop_flash('success'), [])
        self.assertEqual(request.session.pop_flash('error'),
                         [u'Login failed.'])

        # Make Bob and do it again:
        bob = self.make_bob()
        self.assertEqual(bob.last_login_date, None)
        result = login(None, request)
        self.assertEqual(result.status, '302 Found')
        self.assertEqual(
            [request.session.pop_flash('success')[0].interpolate()],
            [u'Welcome, Bob Dabolina!'])
        last_login_date = bob.last_login_date
        self.assertNotEqual(last_login_date, None)
        self.assertEqual(request.session.pop_flash('error'), [])

        # Log in with email:
        request.params['login'] = u'*****@*****.**'
        result = login(None, request)
        self.assertEqual(result.status, '302 Found')
        self.assertEqual(
            [request.session.pop_flash('success')[0].interpolate()],
            [u'Welcome, Bob Dabolina!'])
        self.assertTrue(last_login_date < bob.last_login_date)

        # Deactive Bob, logging in is no longer possible:
        bob.active = False
        result = login(None, request)
        self.assert_(isinstance(result, dict))
        self.assertEqual(request.session.pop_flash('error'),
                         [u'Login failed.'])

        # If Bob has a 'confirm_token' set, logging in is still possible:
        bob.active = True
        bob.confirm_token = u'token'
        result = login(None, request)
        self.assertEqual(result.status, '302 Found')
        self.assertEqual(
            [request.session.pop_flash('success')[0].interpolate()],
            [u'Welcome, Bob Dabolina!'])
コード例 #17
0
ファイル: test_security.py プロジェクト: appetito/Kotti
    def test_login_with_email_remembers(self, remember):
        from kotti.views.login import login
        request = DummyRequest()

        self.make_bob()
        request.params['submit'] = u'on'
        request.params['login'] = u'*****@*****.**'
        request.params['password'] = u'secret'
        login(None, request)
        remember.assert_called_with(request, u'bob')
コード例 #18
0
ファイル: test_node_views.py プロジェクト: Kotti/Kotti
    def test_rename_to_empty_name(self, root):
        from kotti.resources import Document
        from kotti.views.edit.actions import NodeActions

        child = root["child"] = Document(title="Child")
        request = DummyRequest()
        request.params["rename"] = "on"
        request.params["name"] = ""
        request.params["title"] = "foo"
        NodeActions(child, request).rename_node()
        assert request.session.pop_flash("error") == ["Name and title are required."]
コード例 #19
0
ファイル: test_util.py プロジェクト: IonicaBizauKitchen/Kotti
    def test_link_selected(self):
        from kotti.util import Link
        from kotti.testing import DummyRequest

        req = DummyRequest()
        req.url = "http://example.com/@@manage"

        assert Link('manage').selected(Mock(__name__=None), req)

        req.url = "http://example.com/@@manage_cats"
        assert not Link('manage').selected(Mock(__name__=None), req)
コード例 #20
0
ファイル: test_security.py プロジェクト: castaf/Kotti
    def test_login_with_email_remembers(self, db_session):
        from kotti.views.login import login
        request = DummyRequest()

        self.make_bob()
        request.params['submit'] = 'on'
        request.params['login'] = '******'
        request.params['password'] = '******'
        with patch('kotti.views.login.remember') as remember:
            login(None, request)
            remember.assert_called_with(request, 'bob')
コード例 #21
0
    def test_login(self, db_session):
        from kotti.views.login import login
        request = DummyRequest()

        # No login attempt:
        result = login(None, request)
        assert isinstance(result, dict)
        assert request.session.pop_flash('success') == []
        assert request.session.pop_flash('error') == []

        # Attempt to log in before Bob exists:
        request.params['submit'] = u'on'
        request.params['login'] = u'bob'
        request.params['password'] = u'secret'
        result = login(None, request)
        assert isinstance(result, dict)
        assert request.session.pop_flash('success') == []
        assert (request.session.pop_flash('error') == [u'Login failed.'])

        # Make Bob and do it again:
        bob = self.make_bob()
        assert bob.last_login_date is None
        result = login(None, request)
        assert result.status == '302 Found'
        assert (
            [request.session.pop_flash('success')[0].interpolate()] ==
            [u'Welcome, Bob Dabolina!'])
        last_login_date = bob.last_login_date
        assert last_login_date is not None
        assert request.session.pop_flash('error') == []

        # Log in with email:
        request.params['login'] = u'*****@*****.**'
        result = login(None, request)
        assert result.status == '302 Found'
        assert (
            [request.session.pop_flash('success')[0].interpolate()] ==
            [u'Welcome, Bob Dabolina!'])
        assert last_login_date < bob.last_login_date

        # Deactive Bob, logging in is no longer possible:
        bob.active = False
        result = login(None, request)
        assert isinstance(result, dict)
        assert (request.session.pop_flash('error') == [u'Login failed.'])

        # If Bob has a 'confirm_token' set, logging in is still possible:
        bob.active = True
        bob.confirm_token = u'token'
        result = login(None, request)
        assert result.status == '302 Found'
        assert (
            [request.session.pop_flash('success')[0].interpolate()] ==
            [u'Welcome, Bob Dabolina!'])
コード例 #22
0
ファイル: test_node_views.py プロジェクト: adamchainz/Kotti
    def test_rename_to_empty_name(self, root):
        from kotti.resources import Document
        from kotti.views.edit.actions import NodeActions

        child = root['child'] = Document(title=u"Child")
        request = DummyRequest()
        request.params['rename'] = u'on'
        request.params['name'] = u''
        request.params['title'] = u'foo'
        NodeActions(child, request).rename_node()
        assert (request.session.pop_flash('error') ==
                [u'Name and title are required.'])
コード例 #23
0
ファイル: test_security.py プロジェクト: Doik/Kotti
    def test_reset_password_inactive_user(self, email_set_password):
        from kotti.views.login import login

        request = DummyRequest()
        self.make_bob().active = False
        request.params['reset-password'] = u'on'
        request.params['login'] = u'bob'
        request.params['password'] = u'secret'
        login(None, request)
        self.assertEqual(request.session.pop_flash('error'),
                         [u"That username or email is not known to us."])
        assert email_set_password.call_count == 0
コード例 #24
0
ファイル: test_util_views.py プロジェクト: disko/Kotti
    def test_slot_request_has_parameters(self, config, db_session):
        from kotti.views.slots import assign_slot

        def foo(context, request):
            bar = request.POST['bar']
            return Response(u"{0} world!".format(bar))
        config.add_view(foo, name='foo')
        assign_slot('foo', 'left', params=dict(greeting=u"Y\u0153"))

        request = DummyRequest()
        request.params['bar'] = u'Hello'
        api = self.make(request=request)
        assert api.slots.left == [u"Hello world!"]
コード例 #25
0
ファイル: test_security.py プロジェクト: Doik/Kotti
    def test_reset_password(self, email_set_password):
        from kotti.views.login import login

        request = DummyRequest()
        self.make_bob()
        request.params['reset-password'] = u'on'
        request.params['login'] = u'bob'
        request.params['password'] = u'secret'
        login(None, request)
        self.assertEqual(request.session.pop_flash('success'), [
            u"You should receive an email with a link to reset your "
            u"password momentarily."])
        assert email_set_password.call_count == 1
コード例 #26
0
ファイル: test_register.py プロジェクト: disko/Kotti
    def test_register_event(self, root):
        from kotti.views.login import register
        request = DummyRequest()
        request.POST['title'] = u'Test User'
        request.POST['name'] = u'test'
        request.POST['email'] = u'*****@*****.**'
        request.POST['register'] = u'register',

        with patch('kotti.views.login.UserAddFormView'):
            with patch('kotti.views.login.get_principals'):
                with patch('kotti.views.login.notify') as notify:
                    register(root, request)
        assert(notify.call_count == 1)
コード例 #27
0
    def test_reset_password_inactive_user(self, db_session):
        from kotti.views.login import login

        request = DummyRequest()
        self.make_bob().active = False
        request.params['reset-password'] = u'on'
        request.params['login'] = u'bob'
        request.params['password'] = u'secret'
        with patch(
                'kotti.views.login.email_set_password') as email_set_password:
            login(None, request)
        assert (request.session.pop_flash('error') ==
                [u"That username or email is not known by this system."])
        assert email_set_password.call_count == 0
コード例 #28
0
    def test_register_event(self, root):
        from kotti.views.login import register

        request = DummyRequest()
        request.POST["title"] = u"Test User"
        request.POST["name"] = u"test"
        request.POST["email"] = u"*****@*****.**"
        request.POST["register"] = (u"register",)

        with patch("kotti.views.login.UserAddFormView"):
            with patch("kotti.views.login.get_principals"):
                with patch("kotti.views.login.notify") as notify:
                    register(root, request)
        assert notify.call_count == 1
コード例 #29
0
ファイル: test_util.py プロジェクト: IonicaBizauKitchen/Kotti
    def test_link_selected_no_view_markers(self):
        from kotti.util import Link
        from kotti.testing import DummyRequest
        from mock import Mock

        req = DummyRequest()
        root = Mock(__name__=None)
        manage = Mock(__name__='manage',
                      __parent__=Mock(__name__=None))

        req.url = "http://example.com/manage"
        assert Link('manage').selected(root, req)

        req.url = "http://example.com/manage/"
        assert not Link('manage').selected(root, req)

        req.url = "http://example.com/"
        assert Link('').selected(root, req)

        req.url = "http://example.com/manage/"
        link = Link('')
        assert link.selected(manage, req)

        req.url = "http://example.com/manage"
        assert not link.selected(manage, req)

        req.url = "http://example.com/"
        assert link.selected(root, req)

        req.url = "http://example.com"
        assert link.selected(root, req)
コード例 #30
0
    def test_reset_owner_to_none(self, events, extra_principals, root):
        from kotti.resources import Content
        from kotti.views.users import user_delete

        request = DummyRequest()

        root[u'content_1'] = Content()
        root[u'content_1'].owner = u'bob'
        assert root[u'content_1'].owner == u'bob'

        request.params['name'] = u'bob'
        request.params['delete'] = u'delete'
        user_delete(root, request)
        assert root[u'content_1'].owner is None
コード例 #31
0
ファイル: test_node_views.py プロジェクト: rkintzi/Kotti
    def test_view_permitted_yes(self, config, db_session):
        from kotti import DBSession
        from kotti.resources import Node
        from kotti.resources import Document

        config.testing_securitypolicy(permissive=True)
        config.include('kotti.views.edit.content')
        root = DBSession.query(Node).get(1)
        request = DummyRequest()
        assert Document.type_info.addable(root, request) is True
コード例 #32
0
    def test_roles(self):
        from kotti.resources import get_root
        from kotti.security import USER_MANAGEMENT_ROLES
        from kotti.views.users import users_manage

        root = get_root()
        request = DummyRequest()
        self.assertEqual(
            [r.name for r in users_manage(root, request)['available_roles']],
            USER_MANAGEMENT_ROLES)
コード例 #33
0
ファイル: test_rss.py プロジェクト: movermeyer/kotti_feed
    def test_document_or_image_type_items(self):
        from kotti_feed.views import rss_items

        request = DummyRequest()
        settings()['kotti_feed.content_types'] = 'document image'
        items = rss_items(request.context, request)
        assert len(items) == 1
        assert items[0].link == 'http://example.com/'
        assert items[0].description == \
            u'Congratulations! You have successfully installed Kotti.'
コード例 #34
0
    def test_get_non_existing_paste_item(self):
        from kotti import DBSession
        from kotti.resources import Node
        from kotti.views.edit import get_paste_item

        root = DBSession().query(Node).get(1)
        request = DummyRequest()
        request.session['kotti.paste'] = (1701, 'copy')
        item = get_paste_item(root, request)
        self.assertEqual(item, None)
コード例 #35
0
ファイル: test_node_views.py プロジェクト: rkintzi/Kotti
    def test_get_non_existing_paste_item(self):
        from kotti import DBSession
        from kotti.resources import Node
        from kotti.views.edit import get_paste_items

        root = DBSession.query(Node).get(1)
        request = DummyRequest()
        request.session['kotti.paste'] = ([1701], 'copy')
        item = get_paste_items(root, request)
        assert item == []
コード例 #36
0
    def test_it(self):
        from kotti.views.util import nodes_tree

        a, aa, ab, ac, aca, acb = create_contents()
        aa.in_navigation = False # nodes_tree doesn't care
        tree = nodes_tree(DummyRequest())
        assert tree.id == a.__parent__.id
        assert [ch.name for ch in tree.children] == [a.name]
        assert [ch.id for ch in tree.children[0].children] == [
            aa.id, ab.id, ac.id]
コード例 #37
0
    def test_add_renderer_globals_event_has_no_renderer_name(self, db_session):
        from kotti.views.util import add_renderer_globals

        request = DummyRequest()
        event = {
            'request': request,
            'context': object(),
            }
        add_renderer_globals(event)
        assert 'api' in event
コード例 #38
0
def test_search_file_description(root):
    from kotti.views.util import search_content

    request = DummyRequest()
    doc1, doc11, doc12, file1 = _create_contents(root)
    results = search_content("this is a file", request)
    assert len(results) == 1
    assert results[0]["name"] == "file1"
    assert results[0]["title"] == "First File"
    assert results[0]["path"] == "/doc1/file1/"
コード例 #39
0
    def test_ordering(self):
        from kotti.views.util import nodes_tree

        a, aa, ab, ac, aca, acb = create_contents()
        a.children.insert(1, a.children.pop(0))
        tree = nodes_tree(DummyRequest())
        assert [ch.position for ch in tree.children[0].children] == [
            0, 1, 2]
        assert [ch.id for ch in tree.children[0].children] == [
            ab.id, aa.id, ac.id]
コード例 #40
0
    def test_deleted_group_removed_in_usergroups(self):
        from kotti.resources import get_root
        from kotti.security import get_principals
        from kotti.tests.test_node_views import TestNodeShare
        from kotti.views.users import user_delete

        root = get_root()
        request = DummyRequest()
        TestNodeShare.add_some_principals()
        bob = get_principals()[u'bob']
        bob.groups = [u'group:bobsgroup']
        assert bob.groups == [u'group:bobsgroup']

        request.params['name'] = u'group:bobsgroup'
        request.params['delete'] = u'delete'
        user_delete(root, request)
        with pytest.raises(KeyError):
            get_principals()[u'group:bobsgroup']
        assert bob.groups == []
コード例 #41
0
    def test_paste_non_existing_node(self, root):
        from kotti.views.edit.actions import NodeActions

        request = DummyRequest()

        for index, action in enumerate(['copy', 'cut']):
            request.session['kotti.paste'] = ([1701], 'copy')
            response = NodeActions(root, request).paste_nodes()
            assert response.status == '302 Found'
            assert len(request.session['_f_error']) == index + 1
コード例 #42
0
ファイル: test_node_views.py プロジェクト: dnouri/Kotti
    def test_paste_without_edit_permission(self):
        from kotti import DBSession
        from kotti.resources import Node
        from kotti.views.edit import paste_node

        root = DBSession().query(Node).get(1)
        request = DummyRequest()
        request.params['paste'] = u'on'
        self.config.testing_securitypolicy(permissive=False)

        # We need to have the 'edit' permission on the original object
        # to be able to cut and paste:
        request.session['kotti.paste'] = (1, 'cut')
        self.assertRaises(Forbidden, paste_node, root, request)

        # We don't need 'edit' permission if we're just copying:
        request.session['kotti.paste'] = (1, 'copy')
        response = paste_node(root, request)
        self.assertEqual(response.status, '302 Found')
コード例 #43
0
ファイル: test_node_views.py プロジェクト: dnouri/Kotti
    def test_view_permitted_yes(self):
        from kotti import DBSession
        from kotti.resources import Node
        from kotti.resources import Document

        self.config.testing_securitypolicy(permissive=True)
        self.config.include('kotti.views.edit')
        root = DBSession().query(Node).get(1)
        request = DummyRequest()
        self.assertEquals(Document.type_info.addable(root, request), True)
コード例 #44
0
    def test_email_set_password_add_query(self, db_session):
        from kotti.message import email_set_password

        user = Dummy(name=u'joe', email='*****@*****.**', title=u'Joe')
        email_set_password(
            user, DummyRequest(), add_query={'another': 'param'})

        assert self.mailer.send.called
        message = self.mailer.send.call_args[0][0]
        assert 'another=param' in message.body
コード例 #45
0
    def test_email_set_password_other_template(self, db_session):
        from kotti.message import email_set_password

        user = Dummy(name=u'joe', email='*****@*****.**', title=u'Joe')
        email_set_password(
            user, DummyRequest(),
            template_name='kotti:templates/email-reset-password.pt')

        assert self.mailer.send.called
        message = self.mailer.send.call_args[0][0]
        assert message.subject.startswith('Reset your password')
コード例 #46
0
ファイル: test_node_views.py プロジェクト: rkintzi/Kotti
    def test_roles(self, db_session):
        from kotti.views.users import share_node
        from kotti.resources import get_root
        from kotti.security import SHARING_ROLES

        # The 'share_node' view will return a list of available roles
        # as defined in 'kotti.security.SHARING_ROLES'
        root = get_root()
        request = DummyRequest()
        assert ([r.name for r in share_node(root, request)['available_roles']
                 ] == SHARING_ROLES)
コード例 #47
0
ファイル: test_util_views.py プロジェクト: eugeneai/Kotti
    def test_add_renderer_globals(self):
        from kotti.views.util import add_renderer_globals

        request = DummyRequest()
        event = {
            'request': request,
            'context': object(),
            'renderer_name': 'foo',
        }
        add_renderer_globals(event)
        self.assertTrue('api' in event)
コード例 #48
0
    def test_warning_for_non_registered_views(self, root):

        with warnings.catch_warnings(record=True) as w:

            DefaultViewSelection(root, DummyRequest()).default_view_selector()

            assert len(w) == 1
            assert issubclass(w[-1].category, UserWarning)
            assert str(
                w[-1].message
            ) == "No view called 'folder_view' is registered for <Document 1 at />."
コード例 #49
0
    def test_email_set_password_add_query(self, db_session):
        from kotti.message import email_set_password

        user = Dummy(name="joe", email="*****@*****.**", title="Joe")
        email_set_password(user,
                           DummyRequest(),
                           add_query={"another": "param"})

        assert self.mailer.send.called
        message = self.mailer.send.call_args[0][0]
        assert "another=param" in message.body
コード例 #50
0
ファイル: test_security.py プロジェクト: timgates42/Kotti
    def test_with_exception(self):
        from kotti.security import authz_context

        context, context2, request = object(), object(), DummyRequest()
        request.environ["authz_context"] = context2
        try:
            with authz_context(context, request):
                assert request.environ["authz_context"] == context
                raise ValueError
        except ValueError:
            assert request.environ["authz_context"] == context2
コード例 #51
0
ファイル: test_util_views.py プロジェクト: Doik/Kotti
    def make(self, context=None, request=None, id=1, **kwargs):
        from kotti import DBSession
        from kotti.resources import Node
        from kotti.views.util import TemplateAPI

        if context is None:
            session = DBSession()
            context = session.query(Node).get(id)
        if request is None:
            request = DummyRequest()
        return TemplateAPI(context, request, **kwargs)
コード例 #52
0
    def test_deleted_group_removed_from_localgroups(self):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.security import set_groups
        from kotti.resources import LocalGroup
        from kotti.views.users import user_delete
        from kotti.tests.test_node_views import TestNodeShare

        root = get_root()
        request = DummyRequest()
        TestNodeShare.add_some_principals()
        set_groups(u'group:bobsgroup', root, ['role:admin'])
        local_group = DBSession.query(LocalGroup).first()
        assert local_group.principal_name == u'group:bobsgroup'
        assert local_group.node == root

        request.params['name'] = u'group:bobsgroup'
        request.params['delete'] = u'delete'
        user_delete(root, request)
        assert DBSession.query(LocalGroup).first() == None
コード例 #53
0
ファイル: test_rss.py プロジェクト: movermeyer/kotti_feed
    def test_special_chars_in_feed(self):
        from kotti_feed.views import rss_view
        from kotti.resources import Document, get_root

        root = get_root()
        request = DummyRequest()
        settings()['kotti_feed.content_types'] = 'document image'
        root['doc1'] = Document(title=u'L\xc3\xb6vely Document')
        feed = rss_view(request.context, request)
        assert u'L\xc3\xb6vely Document' in feed.text
        assert u'encoding="utf-8"' in feed.text
コード例 #54
0
    def test_add_renderer_globals(self, db_session):
        from kotti.views.util import add_renderer_globals

        request = DummyRequest()
        event = {
            "request": request,
            "context": object(),
            "renderer_name": "foo"
        }
        add_renderer_globals(event)
        assert "api" in event
コード例 #55
0
    def test_redirect(self, filedepot):
        f = self._create_file()
        f.data._thaw()
        f.data['_public_url'] = 'http://example.com'
        f.data._freeze()

        with pytest.raises(HTTPMovedPermanently) as e:
            UploadedFileResponse(f.data, DummyRequest())

        response = e.value
        assert response.headers['Location'] == 'http://example.com'
コード例 #56
0
    def test_email_set_password_basic(self, db_session):
        from kotti.message import email_set_password

        user = Dummy(name='joe', email='*****@*****.**', title='Joe')
        email_set_password(user, DummyRequest())

        assert hasattr(user, 'confirm_token')
        assert self.mailer.send.called
        message = self.mailer.send.call_args[0][0]
        assert 'Your registration' in message.subject
        assert 'Joe' in message.body
        assert 'Awesome site' in message.body
コード例 #57
0
ファイル: test_security.py プロジェクト: timgates42/Kotti
    def test_list_groups_callback_with_groups(self, db_session):
        from kotti.security import list_groups_callback
        from kotti.security import get_principals

        # Although group definitions are also in the user database,
        # we're not allowed to authenticate with a group id:
        get_principals()["bob"] = dict(name="bob")
        get_principals()["group:bobsgroup"] = dict(name="group:bobsgroup")

        request = DummyRequest()
        assert list_groups_callback("bob", request) == []
        assert list_groups_callback("group:bobsgroup", request) is None
コード例 #58
0
    def test_cut_and_paste_content_copy_tags(self):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, TagsToContents, Content
        from kotti.views.edit import paste_node

        ses = DBSession
        root = get_root()
        root[u'folder_1'] = Content()
        root[u'content_1'] = Content()
        root[u'content_1'].tags = [u'my tag']
        assert ses.query(Tag).count() == 1
        assert ses.query(TagsToContents).count() == 1

        request = DummyRequest()
        request.params['paste'] = u'on'
        request.session['kotti.paste'] = (root[u'content_1'].id, 'cut')
        paste_node(root[u'folder_1'], request)
        assert root[u'folder_1'][u'content_1'].tags == [u'my tag']
        assert ses.query(Tag).count() == 1
        assert ses.query(TagsToContents).count() == 1
コード例 #59
0
    def test_email_set_password_basic(self, db_session):
        from kotti.message import email_set_password

        user = Dummy(name="joe", email="*****@*****.**", title="Joe")
        email_set_password(user, DummyRequest())

        assert hasattr(user, "confirm_token")
        assert self.mailer.send.called
        message = self.mailer.send.call_args[0][0]
        assert "Your registration" in message.subject
        assert "Joe" in message.body
        assert "Awesome site" in message.body
コード例 #60
0
ファイル: test_file.py プロジェクト: Python3pkg/Kotti
    def test_redirect(self, filedepot):
        class PublicFile(object):
            public_url = 'http://example.com'

        class PublicData(object):
            file = PublicFile()

        with pytest.raises(HTTPMovedPermanently) as e:
            UploadedFileResponse(PublicData(), DummyRequest())

        response = e.value
        assert response.headers['Location'] == 'http://example.com'