예제 #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
예제 #2
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
예제 #3
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']
예제 #4
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"
예제 #5
0
    def test_delete_content_deletes_orphaned_tags(self, root, events):
        from kotti.resources import Tag, Content

        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 Tag.query.count() == 2
        del root[u'content_1']
        assert Tag.query.one().title == u'tag 2'
예제 #6
0
파일: test_tags.py 프로젝트: castaf/Kotti
    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'
예제 #7
0
파일: test_tags.py 프로젝트: Kotti/Kotti
    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"
예제 #8
0
파일: test_tags.py 프로젝트: Kotti/Kotti
    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"]
        )
예제 #9
0
    def test_delete_content_deletes_orphaned_tags(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_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'
예제 #10
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'
예제 #11
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']
예제 #12
0
파일: test_tags.py 프로젝트: Kotti/Kotti
    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"]
예제 #13
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']
예제 #14
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"]
예제 #15
0
파일: test_tags.py 프로젝트: castaf/Kotti
    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']
예제 #16
0
파일: test_tags.py 프로젝트: castaf/Kotti
    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
예제 #17
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
예제 #18
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
예제 #19
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
예제 #20
0
파일: test_tags.py 프로젝트: Kotti/Kotti
    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
예제 #21
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[u'folder_1'] = Content()
        root[u'folder_1'].tags = [u'first tag']
        root[u'folder_1'][u'content_1'] = Content()
        root[u'folder_1'][u'content_1'].tags = [u'second tag']
        root[u'folder_1'][u'content_2'] = Content()
        root[u'folder_1'][u'content_2'].tags = [u'third tag']
        assert Tag.query.count() == 3
        assert TagsToContents.query.count() == 3

        request = DummyRequest()
        request.POST['delete'] = 'delete'
        NodeActions(root[u'folder_1'], request).delete_node()
        assert Tag.query.count() == 0
        assert TagsToContents.query.count() == 0
예제 #22
0
파일: test_tags.py 프로젝트: castaf/Kotti
    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
예제 #23
0
파일: test_tags.py 프로젝트: castaf/Kotti
    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
예제 #24
0
    def test_get_content_items_for_tag_title(self, db_session, events):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, TagsToContents, Content
        from kotti.views.util import content_with_tags

        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']

        # 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([u'first tag'])
        assert [res.name for res in result] == [u'folder_1', u'content_2']
        result = content_with_tags([u'second tag'])
        assert [res.name for res in result] == [u'folder_1']
        result = content_with_tags([u'third tag'])
        assert [res.name for res in result] == [u'content_1', u'content_2']
예제 #25
0
파일: test_tags.py 프로젝트: disko/Kotti
    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
예제 #26
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"])
예제 #27
0
파일: test_tags.py 프로젝트: fschulze/Kotti
    def test_get_content_items_from_tag(self):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, 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']
        first_tag = ses.query(Tag).filter(Tag.title == u'first tag').one()
        assert [rel.name for rel in first_tag.items] == [u'folder_1', u'content_2']
        second_tag = ses.query(Tag).filter(Tag.title == u'second tag').one()
        assert [rel.name for rel in second_tag.items] == [u'folder_1']
        third_tag = ses.query(Tag).filter(Tag.title == u'third tag').one()
        assert [rel.name for rel in third_tag.items] == [u'content_1', u'content_2']
예제 #28
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
예제 #29
0
    def test_get_content_items_from_tag(self, db_session, events):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, 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']
        first_tag = ses.query(Tag).filter(Tag.title == u'first tag').one()
        assert [rel.name for rel in first_tag.items] == [
            u'folder_1', u'content_2']
        second_tag = ses.query(Tag).filter(Tag.title == u'second tag').one()
        assert [rel.name for rel in second_tag.items] == [u'folder_1']
        third_tag = ses.query(Tag).filter(Tag.title == u'third tag').one()
        assert [rel.name for rel in third_tag.items] == [
            u'content_1', u'content_2']
예제 #30
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
예제 #31
0
파일: test_tags.py 프로젝트: Kotti/Kotti
    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
예제 #32
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
예제 #33
0
    def test_delete_content_delete_tags_and_assignments(self):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Tag, TagsToContents, Content
        from kotti.views.edit import delete_node

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

        request = DummyRequest()
        request.POST['delete'] = 'on'
        delete_node(root[u'folder_1'], request)
        assert ses.query(Tag).count() == 0
        assert ses.query(TagsToContents).count() == 0
예제 #34
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
예제 #35
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
예제 #36
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
예제 #37
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
예제 #38
0
    def test_delete_content_delete_tags_and_assignments(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'folder_1'].tags = [u'first tag']
        root[u'folder_1'][u'content_1'] = Content()
        root[u'folder_1'][u'content_1'].tags = [u'second tag']
        root[u'folder_1'][u'content_2'] = Content()
        root[u'folder_1'][u'content_2'].tags = [u'third tag']
        assert ses.query(Tag).count() == 3
        assert ses.query(TagsToContents).count() == 3

        request = DummyRequest()
        request.POST['delete'] = 'on'
        NodeActions(root[u'folder_1'], request).delete_node()
        assert ses.query(Tag).count() == 0
        assert ses.query(TagsToContents).count() == 0
예제 #39
0
파일: test_tags.py 프로젝트: fschulze/Kotti
    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']
예제 #40
0
파일: test_tags.py 프로젝트: castaf/Kotti
    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
예제 #41
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
예제 #42
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
예제 #43
0
파일: test_tags.py 프로젝트: Kotti/Kotti
    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
예제 #44
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
예제 #45
0
파일: test_tags.py 프로젝트: castaf/Kotti
    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
예제 #46
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
예제 #47
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
예제 #48
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
예제 #49
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
예제 #50
0
    def test_copy_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], 'copy')
        NodeActions(root[u'folder_1'], request).paste_nodes()
        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
예제 #51
0
파일: test_tags.py 프로젝트: fschulze/Kotti
    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