Exemplo n.º 1
0
    def test_association_proxy(self, db_session, events):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, TagsToContents, Content

        root = get_root()
        root[u'content_1'] = Content()
        root[u'content_1'].tags = [u'tag 1', u'tag 2']
        assert root[u'content_1'].tags == [u'tag 1', u'tag 2']
        assert type(root[u'content_1']._tags[0]) == TagsToContents
        assert type(root[u'content_1']._tags[0].tag) == Tag
        assert root[u'content_1']._tags[0].tag.title == u'tag 1'
        assert root[u'content_1']._tags[0].position == 0
        assert root[u'content_1']._tags[1].tag.title == u'tag 2'
        assert root[u'content_1']._tags[1].position == 1
        assert len(root[u'content_1']._tags) == 2

        root[u'content_2'] = Content()
        root[u'content_2'].tags = [u'tag 1', u'tag 3']
        assert len(root[u'content_2']._tags) == 2
        assert root[u'content_2']._tags[0].tag.title == u'tag 1'
        assert root[u'content_2']._tags[0].position == 0
        assert root[u'content_2']._tags[1].tag.title == u'tag 3'
        assert root[u'content_2']._tags[1].position == 1
        assert len(DBSession.query(Tag).all()) == 3
    def test_show_dropdown_menus(self):
        request = NavigationDummyRequest(path='/some-navigation-widget-left')
        root = get_root()
        result = navigation_widget_items(root, request)

        c1 = root[u'content_1'] = Content(title=u'Content_1')
        c1[u'sub_1'] = Content(title=u'Sub_1')
        c1[u'sub_1'][u'sub_sub_1'] = Content(title=u'Sub_Sub_1')
        c2 = root[u'content_2'] = Content(title=u'Content_2')
        c2[u'sub_2'] = Content(title=u'Sub_2')

        html = render_view(
            c1,
            NavigationDummyRequest(path='/some-navigation-widget-left'),
            name='navigation-widget-items-left')

        assert not u'nav-list-careted' in html

        st = get_current_registry().settings
        st['kotti_navigation.navigation_widget.left_display_type'] = u'hor_pills_with_dropdowns'

        html = render_view(
            c1,
            NavigationDummyRequest(path='/some-navigation-widget-left'),
            name='navigation-widget-items-left')

        assert u'nav-list-careted' in html
Exemplo n.º 3
0
    def test_include_content_types(self):
        root = get_root()
        set_nav_setting('left', 'display_type', 'tree')
        set_nav_setting('left', 'options', ['stacked', 'include_root'])

        root[u'content_1'] = Content()
        root[u'content_2'] = Content()
        root[u'content_2'].in_navigation = False

        # If we include the content type the nav item is present.
        set_nav_setting('left', 'include', [Content.type_info.name])
        html = render_view(root, self.request, name='navigation-widget-tree')
        assert u'content_1' in html
        assert u'content_2' not in html

        # With an empty include_content_types, the nav item is not present.
        set_nav_setting('left', 'include', [])
        html = render_view(root, self.request, name='navigation-widget-tree')
        assert u'content_1' in html
        assert u'content_2' not in html

        # Again, with show_hidden True.
        set_nav_setting('left', 'options', ['stacked', 'include_root',
                                            'show_hidden_while_logged_in'])
        with patch('kotti_navigation.util.the_user', return_value='admin'):
            html = render_view(root, self.request,
                               name='navigation-widget-tree')
            assert u'content_1' in html
            assert u'content_2' in html
Exemplo n.º 4
0
def create_contents(root):
    from kotti.resources import Content, File
    doc1 = root['doc1'] = Content(title=u'First Document')
    doc11 = root['doc1']['doc11'] = Content(title=u'Second Document')
    doc12 = root['doc1']['doc12'] = Content(title=u'Third Document')
    file1 = root['doc1']['file1'] = File(title=u'First File',
                                         description=u'this is a file')
    return doc1, doc11, doc12, file1
Exemplo n.º 5
0
    def test_delete_tag_doesnt_touch_content(self, root, db_session):
        from kotti.resources import Tag, Content

        root[u'content_1'] = Content()
        root[u'content_1'].tags = [u'my tag']

        assert Content.query.filter_by(name=u'content_1').count() == 1
        db_session.delete(Tag.query.filter_by(title=u'my tag').one())
        assert Content.query.filter_by(name=u'content_1').count() == 1
Exemplo n.º 6
0
    def test_delete_tag_assignment_delete_tag(self, root, events, db_session):
        from kotti.resources import Tag, TagsToContents, Content

        root[u'content_1'] = Content()
        root[u'content_1'].tags = [u'my tag']

        assert Tag.query.count() == 1
        db_session.delete(TagsToContents.query.one())
        assert Tag.query.count() == 0
Exemplo n.º 7
0
    def test_delete_tag_doesnt_touch_content(self, root, db_session):
        from kotti.resources import Tag, Content

        root['content_1'] = Content()
        root['content_1'].tags = ['my tag']

        assert Content.query.filter_by(name='content_1').count() == 1
        db_session.delete(Tag.query.filter_by(title='my tag').one())
        assert Content.query.filter_by(name='content_1').count() == 1
Exemplo n.º 8
0
    def test_delete_tag_assignment_delete_tag(self, root, events, db_session):
        from kotti.resources import Tag, TagsToContents, Content

        root['content_1'] = Content()
        root['content_1'].tags = ['my tag']

        assert Tag.query.count() == 1
        db_session.delete(TagsToContents.query.one())
        assert Tag.query.count() == 0
Exemplo n.º 9
0
    def test_delete_content_deletes_orphaned_tags(self, root, events):
        from kotti.resources import Tag, Content

        root["content_1"] = Content()
        root["content_2"] = Content()
        root["content_1"].tags = ["tag 1", "tag 2"]
        root["content_2"].tags = ["tag 2"]
        assert Tag.query.count() == 2
        del root["content_1"]
        assert Tag.query.one().title == "tag 2"
Exemplo n.º 10
0
    def test_delete_tag_assignment_doesnt_touch_content(self, root, db_session):
        from kotti.resources import Tag, TagsToContents, Content

        root['content_1'] = Content()
        root['content_1'].tags = ['my tag']

        assert Tag.query.count() == 1
        assert Content.query.filter_by(name='content_1').count() == 1
        db_session.delete(TagsToContents.query.one())
        assert Content.query.filter_by(name='content_1').count() == 1
Exemplo n.º 11
0
    def test_delete_content_deletes_orphaned_tags(self, root, events):
        from kotti.resources import Tag, Content

        root['content_1'] = Content()
        root['content_2'] = Content()
        root['content_1'].tags = ['tag 1', 'tag 2']
        root['content_2'].tags = ['tag 2']
        assert Tag.query.count() == 2
        del root['content_1']
        assert Tag.query.one().title == 'tag 2'
Exemplo n.º 12
0
    def test_delete_tag_assignment_doesnt_touch_content(self, root, db_session):
        from kotti.resources import Tag, TagsToContents, Content

        root[u'content_1'] = Content()
        root[u'content_1'].tags = [u'my tag']

        assert Tag.query.count() == 1
        assert Content.query.filter_by(name=u'content_1').count() == 1
        db_session.delete(TagsToContents.query.one())
        assert Content.query.filter_by(name=u'content_1').count() == 1
Exemplo n.º 13
0
    def test_get_content_items_for_tag_title(self):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, TagsToContents, Content

        ses = DBSession
        root = get_root()
        root[u'folder_1'] = Content()
        root[u'folder_1'].tags = [u'first tag', u'second tag']
        root[u'folder_1'][u'content_1'] = Content()
        root[u'folder_1'][u'content_1'].tags = [
            u'third tag',
        ]
        root[u'folder_1'][u'content_2'] = Content()
        root[u'folder_1'][u'content_2'].tags = [u'first tag', u'third tag']

        result = ses.query(Content).join(TagsToContents).join(Tag).filter(
            Tag.title == u'first tag').all()
        assert [res.name for res in result] == [u'folder_1', u'content_2']
        result = ses.query(Content).join(TagsToContents).join(Tag).filter(
            Tag.title == u'second tag').all()
        assert [res.name for res in result] == [u'folder_1']
        result = ses.query(Content).join(TagsToContents).join(Tag).filter(
            Tag.title == u'third tag').all()
        assert [res.name for res in result] == [u'content_1', u'content_2']
Exemplo n.º 14
0
def _create_contents(root):
    from kotti.resources import Content, File

    doc1 = root["doc1"] = Content(title="First Document",
                                  description="I am the first.")
    doc11 = root["doc1"]["doc11"] = Content(title="Second Document",
                                            description="And I am the second.")
    doc12 = root["doc1"]["doc12"] = Content(title="Third Document")
    file1 = root["doc1"]["file1"] = File(title="First File",
                                         description="this is a file")
    return doc1, doc11, doc12, file1
 def test_render_widget(self):
     request = NavigationDummyRequest(
         path='/some-navigation-widget-beforebodyend')
     root = get_root()
     root[u'content_1'] = Content(title=u'Content_1')
     root[u'content_1'][u'sub_1'] = Content(title=u'Sub_1')
     request.context = root[u'content_1'][u'sub_1']
     html = render_view(root[u'content_1'][u'sub_1'],
                        request,
                        name='navigation-widget-breadcrumbs-beforebodyend')
     assert 'You are here:' in html
Exemplo n.º 16
0
    def test_delete_tag_assignment_delete_tag(self, db_session, events):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, TagsToContents, Content

        root = get_root()
        root[u'content_1'] = Content()
        root[u'content_1'].tags = [u'my tag']

        ses = DBSession
        assert ses.query(Tag).count() == 1
        ses.delete(ses.query(TagsToContents).one())
        assert ses.query(Tag).count() == 0
Exemplo n.º 17
0
    def test_delete_tag_assignment_delete_tag(self):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, TagsToContents, Content

        root = get_root()
        root[u'content_1'] = Content()
        root[u'content_1'].tags = [u'my tag']

        ses = DBSession
        assert ses.query(Tag).count() == 1
        ses.delete(ses.query(TagsToContents).one())
        assert ses.query(Tag).count() == 0
Exemplo n.º 18
0
    def test_delete_tag_doesnt_touch_content(self):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, Content

        root = get_root()
        root[u'content_1'] = Content()
        root[u'content_1'].tags = [u'my tag']

        ses = DBSession
        assert ses.query(Content).filter_by(name=u'content_1').count() == 1
        ses.delete(ses.query(Tag).filter_by(title=u'my tag').one())
        assert ses.query(Content).filter_by(name=u'content_1').count() == 1
    def test_is_node_open(self):
        request = NavigationDummyRequest(path='/some-navigation-widget-left')
        root = get_root()
        root[u'content_1'] = Content()
        root[u'content_1'][u'sub_1'] = Content()
        root[u'content_2'] = Content()
        root[u'content_2'][u'sub_2'] = Content()

        request.context = root
        html = render_view(root, request, name='navigation-widget-tree-left')
        assert is_node_open(root, request)
        assert is_node_open(root['content_1'], request) == False
        assert is_node_open(root['content_2'], request) == False
Exemplo n.º 20
0
    def test_delete_tag_doesnt_touch_content(self, db_session, events):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, Content

        root = get_root()
        root[u'content_1'] = Content()
        root[u'content_1'].tags = [u'my tag']

        ses = DBSession
        assert ses.query(Content).filter_by(name=u'content_1').count() == 1
        ses.delete(ses.query(Tag).filter_by(title=u'my tag').one())
        assert ses.query(Content).filter_by(name=u'content_1').count() == 1
Exemplo n.º 21
0
    def test_delete_content_deletes_orphaned_tags(self, db_session, events):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, Content

        root = get_root()
        root[u'content_1'] = Content()
        root[u'content_2'] = Content()
        root[u'content_1'].tags = [u'tag 1', u'tag 2']
        root[u'content_2'].tags = [u'tag 2']
        assert DBSession.query(Tag).count() == 2
        del root[u'content_1']
        assert DBSession.query(Tag).one().title == u'tag 2'
    def test_is_tree_open(self):
        request = NavigationDummyRequest(path='/some-navigation-widget-left')
        root = get_root()
        root[u'content_1'] = Content()
        root[u'content_1'][u'sub_1'] = Content()
        root[u'content_2'] = Content()
        root[u'content_2'][u'sub_2'] = Content()

        request.context = root
        html = render_view(root, request, name='navigation-widget-tree-left')
        assert u'content_1' in html
        assert u'sub_1' not in html
        assert u'content_2' in html
        assert u'sub_2' not in html

        request.context = root[u'content_1']
        html = render_view(root[u'content_1'],
                           request,
                           name='navigation-widget-tree-left')
        assert u'content_1' in html
        assert u'sub_1' in html
        assert u'content_2' in html
        assert u'sub_2' not in html

        request.context = root[u'content_2']
        html = render_view(root[u'content_2'],
                           request,
                           name='navigation-widget-tree-left')
        assert u'content_1' in html
        assert u'sub_1' not in html
        assert u'content_2' in html
        assert u'sub_2' in html

        request.context = root[u'content_2'][u'sub_2']
        html = render_view(root[u'content_2'][u'sub_2'],
                           request,
                           name='navigation-widget-tree-left')
        assert u'content_1' in html
        assert u'sub_1' not in html
        assert u'content_2' in html
        assert u'sub_2' in html

        se = get_current_registry().settings
        se['kotti_navigation.navigation_widget.left_display_type'] = u'ver_tabs_stacked_open_all'
        request.context = root
        html = render_view(root, request, name='navigation-widget-tree-left')
        assert u'content_1' in html
        assert u'sub_1' in html
        assert u'content_2' in html
        assert u'sub_2' in html
Exemplo n.º 23
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["content_1"] = Content()
        root["content_1"].owner = "bob"
        assert root["content_1"].owner == "bob"

        request.params["name"] = "bob"
        request.params["delete"] = "delete"
        user_delete(root, request)
        assert root["content_1"].owner is None
Exemplo n.º 24
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["content_1"] = Content()
        root["content_1"].owner = "bob"
        assert root["content_1"].owner == "bob"

        request.params["name"] = "bob"
        request.params["delete"] = "delete"
        user_delete(root, request)
        assert root["content_1"].owner is None
Exemplo n.º 25
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
Exemplo n.º 26
0
    def test_copy_content_copy_tags(self, root, db_session):
        from kotti.resources import Tag, TagsToContents, Content

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

        root[u'content_2'] = root[u'content_1'].copy()
        db_session.flush()
        assert root[u'content_1'].tags == [u'my tag']
        assert root[u'content_2'].tags == [u'my tag']
        assert Tag.query.count() == 1
        assert TagsToContents.query.count() == 2
Exemplo n.º 27
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['content_1'] = Content()
        root['content_1'].owner = 'bob'
        assert root['content_1'].owner == 'bob'

        request.params['name'] = 'bob'
        request.params['delete'] = 'delete'
        user_delete(root, request)
        assert root['content_1'].owner is None
Exemplo n.º 28
0
    def test_copy_content_copy_tags(self, root, db_session):
        from kotti.resources import Tag, TagsToContents, Content

        root['content_1'] = Content()
        root['content_1'].tags = ['my tag']
        assert Tag.query.count() == 1
        assert TagsToContents.query.count() == 1

        root['content_2'] = root['content_1'].copy()
        db_session.flush()
        assert root['content_1'].tags == ['my tag']
        assert root['content_2'].tags == ['my tag']
        assert Tag.query.count() == 1
        assert TagsToContents.query.count() == 2
    def test_label(self):
        request = NavigationDummyRequest(path='/some-navigation-widget-left')
        root = get_root()

        root[u'content_1'] = Content(title=u'Content_1')
        root[u'content_1'][u'sub_1'] = Content(title=u'Sub_1')
        root[u'content_2'] = Content(title=u'Content_2')
        root[u'content_2'][u'sub_2'] = Content(title=u'Sub_2')

        result = navigation_widget_items(root, request)

        se = get_current_registry().settings
        se['kotti_navigation.navigation_widget.left_label'] =\
            u'Items in [context] are:'
        result = navigation_widget_items(root[u'content_1'], request)
        assert result['label'] == 'Items in [Content_1] are:'
Exemplo n.º 30
0
    def test_cut_and_paste_content_copy_tags(self, root):
        from kotti.resources import Tag, TagsToContents, Content
        from kotti.views.edit.actions import NodeActions

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

        request = DummyRequest()
        request.params['paste'] = 'on'
        request.session['kotti.paste'] = ([root['content_1'].id], 'cut')
        NodeActions(root['folder_1'], request).paste_nodes()
        assert root['folder_1']['content_1'].tags == ['my tag']
        assert Tag.query.count() == 1
        assert TagsToContents.query.count() == 1
Exemplo n.º 31
0
    def test_cut_and_paste_content_copy_tags(self, root):
        from kotti.resources import Tag, TagsToContents, Content
        from kotti.views.edit.actions import NodeActions

        root["folder_1"] = Content()
        root["content_1"] = Content()
        root["content_1"].tags = ["my tag"]
        assert Tag.query.count() == 1
        assert TagsToContents.query.count() == 1

        request = DummyRequest()
        request.params["paste"] = "on"
        request.session["kotti.paste"] = ([root["content_1"].id], "cut")
        NodeActions(root["folder_1"], request).paste_nodes()
        assert root["folder_1"]["content_1"].tags == ["my tag"]
        assert Tag.query.count() == 1
        assert TagsToContents.query.count() == 1
Exemplo n.º 32
0
    def test_cut_and_paste_content_copy_tags(self, root):
        from kotti.resources import Tag, TagsToContents, Content
        from kotti.views.edit.actions import NodeActions

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

        request = DummyRequest()
        request.params['paste'] = u'on'
        request.session['kotti.paste'] = ([root[u'content_1'].id], 'cut')
        NodeActions(root[u'folder_1'], request).paste_nodes()
        assert root[u'folder_1'][u'content_1'].tags == [u'my tag']
        assert Tag.query.count() == 1
        assert TagsToContents.query.count() == 1
Exemplo n.º 33
0
    def test_show_hidden(self):
        root = get_root()
        request = DummyRequest()
        root[u'content_1'] = Content()
        root[u'content_2'] = Content()
        root[u'content_2'].in_navigation = False

        # with standard settings the hidden nav points are hidden
        html = render_view(root, request, name='navigation-widget')
        assert u'content_1' in html
        assert u'content_2' not in html

        # if we change the setting, the nav points still hidden
        get_current_registry().settings['kotti_navigation.navigation_widget.show_hidden_while_logged_in'] = u'true'
        html = render_view(root, request, name='navigation-widget')
        assert u'content_1' in html
        assert u'content_2' not in html
Exemplo n.º 34
0
    def test_cut_and_paste_content_copy_tags(self, root):
        from kotti.resources import Tag, TagsToContents, Content
        from kotti.views.edit.actions import NodeActions

        root["folder_1"] = Content()
        root["content_1"] = Content()
        root["content_1"].tags = ["my tag"]
        assert Tag.query.count() == 1
        assert TagsToContents.query.count() == 1

        request = DummyRequest()
        request.params["paste"] = "on"
        request.session["kotti.paste"] = ([root["content_1"].id], "cut")
        NodeActions(root["folder_1"], request).paste_nodes()
        assert root["folder_1"]["content_1"].tags == ["my tag"]
        assert Tag.query.count() == 1
        assert TagsToContents.query.count() == 1
 def test_render_widget(self):
     request = NavigationDummyRequest(path='/some-navigation-widget-right')
     root = get_root()
     root[u'content_1'] = Content(title=u'Content_1')
     request.context = root[u'content_1']
     html = render_view(root[u'content_1'],
                        request,
                        name='navigation-widget-tree-right')
     assert '<ul class="nav nav-tabs nav-stacked">' in html
Exemplo n.º 36
0
    def test_reset_owner_to_none(self):
        from kotti.resources import get_root
        from kotti.resources import Content
        from kotti.views.users import user_delete
        from kotti.tests.test_node_views import TestNodeShare

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

        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 == None
Exemplo n.º 37
0
    def test_copy_content_copy_tags(self):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, TagsToContents, Content

        ses = DBSession
        root = get_root()
        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

        root[u'content_2'] = root[u'content_1'].copy()
        DBSession.flush()
        assert root[u'content_1'].tags == [u'my tag']
        assert root[u'content_2'].tags == [u'my tag']
        assert ses.query(Tag).count() == 1
        assert ses.query(TagsToContents).count() == 2
Exemplo n.º 38
0
    def test_reset_owner_to_none(self):
        from kotti.resources import get_root
        from kotti.resources import Content
        from kotti.views.users import user_delete
        from kotti.tests.test_node_views import TestNodeShare

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

        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 == None
Exemplo n.º 39
0
    def test_copy_content_copy_tags(self, db_session, events):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, TagsToContents, Content

        ses = DBSession
        root = get_root()
        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

        root[u'content_2'] = root[u'content_1'].copy()
        DBSession.flush()
        assert root[u'content_1'].tags == [u'my tag']
        assert root[u'content_2'].tags == [u'my tag']
        assert ses.query(Tag).count() == 1
        assert ses.query(TagsToContents).count() == 2
Exemplo n.º 40
0
    def test_search_results_for_tag_title(self, root):
        from kotti.resources import Tag, TagsToContents, Content
        from substancek_cms_theme.views.search import search_results_for_tag

        root[u'folder_1'] = Content()
        root[u'folder_1'].tags = [u'first tag', u'second tag']
        root[u'folder_1'][u'content_1'] = Content()
        root[u'folder_1'][u'content_1'].tags = [u'third tag']
        root[u'folder_1'][u'content_2'] = Content()
        root[u'folder_1'][u'content_2'].tags = [u'first tag', u'third tag']

        result = Content.query.join(TagsToContents).join(Tag).filter(
            Tag.title == u'first tag').all()
        assert [res.name for res in result] == [u'folder_1', u'content_2']
        result = Content.query.join(TagsToContents).join(Tag).filter(
            Tag.title == u'second tag').all()
        assert [res.name for res in result] == [u'folder_1']
        result = Content.query.join(TagsToContents).join(Tag).filter(
            Tag.title == u'third tag').all()
        assert [res.name for res in result] == [u'content_1', u'content_2']

        # The same tests again, using content_with_tags():
        #
        #     About expected sort order:
        #
        #         In the first set of tests below, where we search by single
        #         tags, the query in the content_with_tags() function returns
        #         results in hierarchical order, from root.
        #
        # content_with_tags() is written to take a list of tags, but in the
        # default Kotti, presently, after some consideration about specialized
        # add-ons for searching, we do not support multiple tags searching, in
        # part to avoid establishing a specification.
        #
        import mock
        from kotti.testing import DummyRequest
        dummy_request = DummyRequest()
        with mock.patch('substancek_cms_theme.views.util.has_permission') \
                as has_permission:
            has_permission.return_value = True
            dummy_request.GET['tag'] = u'first tag'
            result = search_results_for_tag(None, dummy_request)['results']
            assert [res['name'] for res in result] == [u'folder_1', u'content_2']
            dummy_request.GET['tag'] = u'second tag'
            result = search_results_for_tag(None, dummy_request)['results']
            assert [res['name'] for res in result] == [u'folder_1']
            dummy_request.GET['tag'] = u'third tag'
            result = search_results_for_tag(None, dummy_request)['results']
            assert [res['name'] for res in result] == [u'content_1', u'content_2']
    def test_show_hidden(self):
        root = get_root()
        request = NavigationDummyRequest(path='/some-navigation-widget-left')
        root[u'content_1'] = Content()
        root[u'content_2'] = Content()
        root[u'content_2'].in_navigation = False

        # with standard settings the hidden nav items are hidden
        html = render_view(root, request, name='navigation-widget-tree-left')
        assert u'content_1' in html
        assert u'content_2' not in html

        # if we change the setting, the nav items still hidden
        se = get_current_registry().settings
        se['kotti_navigation.navigation_widget.left_show_hidden_while_logged_in'] =\
            u'true'
        html = render_view(root, request, name='navigation-widget-tree-left')
        assert u'content_1' in html
        assert u'content_2' not in html
    def test_include_content_types(self):
        root = get_root()
        request = NavigationDummyRequest(path='/some-navigation-widget-left')
        root[u'content_1'] = Content()
        root[u'content_2'] = Content()
        root[u'content_2'].in_navigation = False

        # If we include the content type the nav item is present.
        se = get_current_registry().settings
        se['kotti_navigation.navigation_widget.left_include_content_types'] =\
            u'kotti.resources.Content'
        html = render_view(root, request, name='navigation-widget-tree-left')
        assert u'content_1' in html

        # With an empty include_content_types, the nav item is not present.
        se['kotti_navigation.navigation_widget.left_include_content_types'] =\
            u''
        html = render_view(root, request, name='navigation-widget-tree-left')
        assert u'content_1' in html
Exemplo n.º 43
0
    def test_owner(self, root, db_session, events, dummy_request):
        from kotti.resources import Content
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.util import clear_cache

        child = root[u'child'] = Content()
        db_session.flush()
        assert child.owner == u'bob'
        assert list_groups(u'bob', child) == [u'role:owner']

        clear_cache()

        # The event listener does not set the role again for subitems:
        grandchild = child[u'grandchild'] = Content()
        db_session.flush()
        assert grandchild.owner == u'bob'
        assert list_groups(u'bob', grandchild) == [u'role:owner']
        assert len(list_groups_raw(u'bob', grandchild)) == 0
Exemplo n.º 44
0
    def test_include_content_types(self):
        root = get_root()
        request = NavigationDummyRequest(path='/some-navigation-widget-left')
        root[u'content_1'] = Content()
        root[u'content_2'] = Content()
        root[u'content_2'].in_navigation = False

        # If we include the content type the nav item is present.
        se = get_current_registry().settings
        se['kotti_navigation.navigation_widget.left_include_content_types'] =\
            u'kotti.resources.Content'
        html = render_view(root, request, name='navigation-widget-tree-left')
        assert u'content_1' in html

        # With an empty include_content_types, the nav item is not present.
        se['kotti_navigation.navigation_widget.left_include_content_types'] =\
            u''
        html = render_view(root, request, name='navigation-widget-tree-left')
        assert u'content_1' in html
Exemplo n.º 45
0
    def test_show_hidden(self):
        root = get_root()
        request = NavigationDummyRequest(path='/some-navigation-widget-left')
        root[u'content_1'] = Content()
        root[u'content_2'] = Content()
        root[u'content_2'].in_navigation = False

        # with standard settings the hidden nav items are hidden
        html = render_view(root, request, name='navigation-widget-tree-left')
        assert u'content_1' in html
        assert u'content_2' not in html

        # if we change the setting, the nav items still hidden
        se = get_current_registry().settings
        se['kotti_navigation.navigation_widget.left_show_hidden_while_logged_in'] =\
            u'true'
        html = render_view(root, request, name='navigation-widget-tree-left')
        assert u'content_1' in html
        assert u'content_2' not in html
Exemplo n.º 46
0
    def test_sqlalchemy_events(self, root, db_session, events):
        from kotti import events
        from kotti.resources import Content

        insert_events = []

        def insert(event):
            insert_events.append(event)

        update_events = []

        def update(event):
            update_events.append(event)

        delete_events = []

        def delete(event):
            delete_events.append(event)

        after_delete_events = []

        def after_delete(event):
            after_delete_events.append(event)

        def lengths():
            return (
                len(insert_events),
                len(update_events),
                len(delete_events),
                len(after_delete_events),
            )

        lis = events.objectevent_listeners
        lis[(events.ObjectInsert, None)].append(insert)
        lis[(events.ObjectUpdate, None)].append(update)
        lis[(events.ObjectDelete, None)].append(delete)
        with warnings.catch_warnings(record=True):
            lis[(events.ObjectAfterDelete, None)].append(after_delete)

        child = root["child"] = Content()
        db_session.flush()
        assert lengths() == (1, 0, 0, 0)
        assert insert_events[0].object == child

        child.title = "Bar"
        db_session.flush()
        assert lengths() == (1, 1, 0, 0)
        assert update_events[0].object == child

        db_session.delete(child)
        db_session.flush()
        assert lengths() == (1, 1, 1, 1)
        assert delete_events[0].object == child
        assert after_delete_events[0].object == child
Exemplo n.º 47
0
    def test_get_content_items_from_tag(self, root):
        from kotti.resources import Tag, Content

        root[u'folder_1'] = Content()
        root[u'folder_1'].tags = [u'first tag', u'second tag']
        root[u'folder_1'][u'content_1'] = Content()
        root[u'folder_1'][u'content_1'].tags = [u'third tag']
        root[u'folder_1'][u'content_2'] = Content()
        root[u'folder_1'][u'content_2'].tags = [u'first tag', u'third tag']
        first_tag = Tag.query.filter(Tag.title == u'first tag').one()
        assert [rel.name
                for rel in first_tag.items] == [u'folder_1', u'content_2']
        second_tag = Tag.query.filter(Tag.title == u'second tag').one()
        assert [rel.name for rel in second_tag.items] == [u'folder_1']
        third_tag = Tag.query.filter(Tag.title == u'third tag').one()
        assert [rel.name
                for rel in third_tag.items] == [u'content_1', u'content_2']
Exemplo n.º 48
0
    def test_get_content_items_from_tag(self, root):
        from kotti.resources import Tag, Content

        root["folder_1"] = Content()
        root["folder_1"].tags = ["first tag", "second tag"]
        root["folder_1"]["content_1"] = Content()
        root["folder_1"]["content_1"].tags = ["third tag"]
        root["folder_1"]["content_2"] = Content()
        root["folder_1"]["content_2"].tags = ["first tag", "third tag"]
        first_tag = Tag.query.filter(Tag.title == "first tag").one()
        assert [rel.name
                for rel in first_tag.items] == ["folder_1", "content_2"]
        second_tag = Tag.query.filter(Tag.title == "second tag").one()
        assert [rel.name for rel in second_tag.items] == ["folder_1"]
        third_tag = Tag.query.filter(Tag.title == "third tag").one()
        assert [rel.name
                for rel in third_tag.items] == ["content_1", "content_2"]
Exemplo n.º 49
0
    def test_cut_and_paste_content_copy_tags(self, db_session, events):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, TagsToContents, Content
        from kotti.views.edit.actions import NodeActions

        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')
        NodeActions(root[u'folder_1'], request).paste_nodes()
        assert root[u'folder_1'][u'content_1'].tags == [u'my tag']
        assert ses.query(Tag).count() == 1
        assert ses.query(TagsToContents).count() == 1
Exemplo n.º 50
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
Exemplo n.º 51
0
    def test_association_proxy(self):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, TagsToContents, Content

        root = get_root()
        root[u'content_1'] = Content()
        root[u'content_1'].tags = [
            u'tag 1',
            u'tag 2',
        ]
        assert root[u'content_1'].tags == [
            u'tag 1',
            u'tag 2',
        ]
        assert type(root[u'content_1']._tags[0]) == TagsToContents
        assert type(root[u'content_1']._tags[0].tag) == Tag
        assert root[u'content_1']._tags[0].tag.title == u'tag 1'
        assert root[u'content_1']._tags[0].position == 0
        assert root[u'content_1']._tags[1].tag.title == u'tag 2'
        assert root[u'content_1']._tags[1].position == 1
        assert len(root[u'content_1']._tags) == 2

        root[u'content_2'] = Content()
        root[u'content_2'].tags = [u'tag 1', u'tag 3']
        assert len(root[u'content_2']._tags) == 2
        assert root[u'content_2']._tags[0].tag.title == u'tag 1'
        assert root[u'content_2']._tags[0].position == 0
        assert root[u'content_2']._tags[1].tag.title == u'tag 3'
        assert root[u'content_2']._tags[1].position == 1
        assert len(DBSession.query(Tag).all()) == 3
Exemplo n.º 52
0
    def test_show_hidden(self):
        root = get_root()
        set_nav_setting('left', 'display_type', 'tree')
        set_nav_setting('left', 'options', ['stacked', 'include_root'])

        root[u'content_1'] = Content()
        root[u'content_2'] = Content()
        root[u'content_2'].in_navigation = False

        # with standard settings the hidden nav items are hidden
        html = render_view(root, self.request, name='navigation-widget-tree')
        assert u'content_1' in html
        assert u'content_2' not in html

        # if we change the setting, the nav items still hidden
        set_nav_setting('left', 'options', ['tabs', 'stacked', 'include_root',
                                            'show_hidden_while_logged_in'])
        with patch('kotti_navigation.util.the_user', return_value='admin'):
            html = render_view(root, self.request,
                               name='navigation-widget-tree')
            assert u'content_1' in html
            assert u'content_2' in html
Exemplo n.º 53
0
    def test_association_proxy(self, root):
        from kotti.resources import Tag, TagsToContents, Content

        root["content_1"] = Content()
        root["content_1"].tags = ["tag 1", "tag 2"]
        assert root["content_1"].tags == ["tag 1", "tag 2"]
        assert type(root["content_1"]._tags[0]) == TagsToContents
        assert type(root["content_1"]._tags[0].tag) == Tag
        assert root["content_1"]._tags[0].tag.title == "tag 1"
        assert root["content_1"]._tags[0].position == 0
        assert root["content_1"]._tags[1].tag.title == "tag 2"
        assert root["content_1"]._tags[1].position == 1
        assert len(root["content_1"]._tags) == 2

        root["content_2"] = Content()
        root["content_2"].tags = ["tag 1", "tag 3"]
        assert len(root["content_2"]._tags) == 2
        assert root["content_2"]._tags[0].tag.title == "tag 1"
        assert root["content_2"]._tags[0].position == 0
        assert root["content_2"]._tags[1].tag.title == "tag 3"
        assert root["content_2"]._tags[1].position == 1
        assert len(Tag.query.all()) == 3
Exemplo n.º 54
0
    def test_association_proxy(self, root):
        from kotti.resources import Tag, TagsToContents, Content

        root['content_1'] = Content()
        root['content_1'].tags = ['tag 1', 'tag 2']
        assert root['content_1'].tags == ['tag 1', 'tag 2']
        assert type(root['content_1']._tags[0]) == TagsToContents
        assert type(root['content_1']._tags[0].tag) == Tag
        assert root['content_1']._tags[0].tag.title == 'tag 1'
        assert root['content_1']._tags[0].position == 0
        assert root['content_1']._tags[1].tag.title == 'tag 2'
        assert root['content_1']._tags[1].position == 1
        assert len(root['content_1']._tags) == 2

        root['content_2'] = Content()
        root['content_2'].tags = ['tag 1', 'tag 3']
        assert len(root['content_2']._tags) == 2
        assert root['content_2']._tags[0].tag.title == 'tag 1'
        assert root['content_2']._tags[0].position == 0
        assert root['content_2']._tags[1].tag.title == 'tag 3'
        assert root['content_2']._tags[1].position == 1
        assert len(Tag.query.all()) == 3
Exemplo n.º 55
0
    def test_copy_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, 'copy')
        paste_node(root[u'folder_1'], request)
        assert root[u'content_1'].tags == [u'my tag']
        assert root[u'folder_1'][u'content_1'].tags == [u'my tag']
        assert ses.query(Tag).count() == 1
        assert ses.query(TagsToContents).count() == 2
Exemplo n.º 56
0
    def test_get_content_items_for_tag_title(self, root):
        from kotti.resources import Tag, TagsToContents, Content
        from kotti.views.util import content_with_tags

        root["folder_1"] = Content()
        root["folder_1"].tags = ["first tag", "second tag"]
        root["folder_1"]["content_1"] = Content()
        root["folder_1"]["content_1"].tags = ["third tag"]
        root["folder_1"]["content_2"] = Content()
        root["folder_1"]["content_2"].tags = ["first tag", "third tag"]

        result = (
            Content.query.join(TagsToContents)
            .join(Tag)
            .filter(Tag.title == "first tag")
            .all()
        )
        assert [res.name for res in result] == ["folder_1", "content_2"]
        result = (
            Content.query.join(TagsToContents)
            .join(Tag)
            .filter(Tag.title == "second tag")
            .all()
        )
        assert [res.name for res in result] == ["folder_1"]
        result = (
            Content.query.join(TagsToContents)
            .join(Tag)
            .filter(Tag.title == "third tag")
            .all()
        )
        assert sorted(res.name for res in result) == sorted(["content_1", "content_2"])

        # The same tests again, using content_with_tags():
        #
        #     About expected sort order:
        #
        #         In the first set of tests below, where we search by single
        #         tags, the query in the content_with_tags() function returns
        #         results in hierarchical order, from root.
        #
        # content_with_tags() is written to take a list of tags, but in the
        # default Kotti, presently, after some consideration about specialized
        # add-ons for searching, we do not support multiple tags searching, in
        # part to avoid establishing a specification.
        #
        result = content_with_tags(["first tag"])
        assert sorted([res.name for res in result]) == sorted(["folder_1", "content_2"])
        result = content_with_tags(["second tag"])
        assert sorted([res.name for res in result]) == sorted(["folder_1"])
        result = content_with_tags(["third tag"])
        assert sorted([res.name for res in result]) == sorted(
            ["content_1", "content_2"]
        )
Exemplo n.º 57
0
    def test_get_content_items_from_tag(self, root):
        from kotti.resources import Tag, Content

        root["folder_1"] = Content()
        root["folder_1"].tags = ["first tag", "second tag"]
        root["folder_1"]["content_1"] = Content()
        root["folder_1"]["content_1"].tags = ["third tag"]
        root["folder_1"]["content_2"] = Content()
        root["folder_1"]["content_2"].tags = ["first tag", "third tag"]
        first_tag = Tag.query.filter(Tag.title == "first tag").one()
        assert [rel.name for rel in first_tag.items] == ["folder_1", "content_2"]
        second_tag = Tag.query.filter(Tag.title == "second tag").one()
        assert [rel.name for rel in second_tag.items] == ["folder_1"]
        third_tag = Tag.query.filter(Tag.title == "third tag").one()
        assert [rel.name for rel in third_tag.items] == ["content_1", "content_2"]
Exemplo n.º 58
0
    def test_get_content_items_from_tag(self, root):
        from kotti.resources import Tag, Content

        root['folder_1'] = Content()
        root['folder_1'].tags = ['first tag', 'second tag']
        root['folder_1']['content_1'] = Content()
        root['folder_1']['content_1'].tags = ['third tag']
        root['folder_1']['content_2'] = Content()
        root['folder_1']['content_2'].tags = ['first tag', 'third tag']
        first_tag = Tag.query.filter(Tag.title == 'first tag').one()
        assert [rel.name for rel in first_tag.items] == [
            'folder_1', 'content_2']
        second_tag = Tag.query.filter(Tag.title == 'second tag').one()
        assert [rel.name for rel in second_tag.items] == ['folder_1']
        third_tag = Tag.query.filter(Tag.title == 'third tag').one()
        assert [rel.name for rel in third_tag.items] == [
            'content_1', 'content_2']
Exemplo n.º 59
0
    def test_delete_content_delete_tags_and_assignments(self, root, events):
        from kotti.resources import Tag, TagsToContents, Content
        from kotti.views.edit.actions import NodeActions

        root['folder_1'] = Content()
        root['folder_1'].tags = ['first tag']
        root['folder_1']['content_1'] = Content()
        root['folder_1']['content_1'].tags = ['second tag']
        root['folder_1']['content_2'] = Content()
        root['folder_1']['content_2'].tags = ['third tag']
        assert Tag.query.count() == 3
        assert TagsToContents.query.count() == 3

        request = DummyRequest()
        request.POST['delete'] = 'delete'
        NodeActions(root['folder_1'], request).delete_node()
        assert Tag.query.count() == 0
        assert TagsToContents.query.count() == 0