Beispiel #1
0
    def test_dict(self):
        become_trusted()
        somedict = {u"One": u"1",
                    u"Two": u"2"}
        update_item(u'TestDict', {SOMEDICT: somedict}, "This is a dict item.")

        return u"TestDict"
Beispiel #2
0
 def test_serialize_backend(self):
     become_trusted()
     testparams = [
         (u'foo3', 0, dict(m1=u"m1r0foo3"), 'bar1'),
         (u'foo4', 0, dict(m1=u"m1r0foo4"), 'bar2'),
         (u'foo4', 1, dict(m1=u"m1r1foo4"), 'baz2'),
     ]
     for params in testparams:
         update_item(*params)
     xmlfile = StringIO()
     serialize(flaskg.storage, xmlfile)
     xml = xmlfile.getvalue()
     assert xml.startswith(XML_DECL + '<backend>')
     assert xml.endswith('</backend>\n')
     # this is not very precise testing:
     assert '<item name="foo3"><meta></meta>' in xml
     assert '<revision revno="0"><meta>' in xml
     assert '<entry key="mimetype"><str>application/octet-stream</str>\n</entry>' in xml
     assert '<entry key="m1"><str>m1r0foo3</str>\n</entry>' in xml
     assert '<entry key="name"><str>foo3</str>\n</entry>' in xml
     assert '<data coding="base64"><chunk>YmFyMQ==</chunk>\n</data>' in xml
     assert '<item name="foo4"><meta></meta>' in xml
     assert '<entry key="m1"><str>m1r0foo4</str>\n</entry>' in xml
     assert '<entry key="name"><str>foo4</str>\n</entry>' in xml
     assert '<data coding="base64"><chunk>YmFyMg==</chunk>\n</data>' in xml
     assert '<revision revno="1"><meta>' in xml
     assert '<entry key="m1"><str>m1r1foo4</str>\n</entry>' in xml
     assert '<entry key="name"><str>foo4</str>\n</entry>' in xml
     assert '<data coding="base64"><chunk>YmF6Mg==</chunk>\n</data>' in xml
Beispiel #3
0
 def custom_setup(self):
     become_trusted(username=u"WikiAdmin")
     for item_name, item_acl, item_content in self.items:
         if item_acl is not None:
             update_item(item_name, {ACL: item_acl}, item_content)
         else:
             update_item(item_name, {}, item_content)
Beispiel #4
0
 def custom_setup(self):
     become_trusted(username=u"WikiAdmin")
     for item_names, item_acl, item_content in self.items:
         meta = {NAME: item_names}
         if item_acl is not None:
             meta.update({ACL: item_acl})
         update_item(item_names[0], meta, item_content)
Beispiel #5
0
    def test_rename_acts_only_in_active_name_in_case_there_are_several_names(self):
        content = u"This is page content"

        update_item(u'Page',
                    {NAME: [u'First',
                            u'Second',
                            u'Third',
                            ],
                     CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, content)

        item = Item.create(u'Second')
        item.rename(u'New name', comment=u'renamed')

        item1 = Item.create(u'First')
        assert item1.name == u'First'
        assert item1.meta[CONTENTTYPE] == 'text/x.moin.wiki;charset=utf-8'
        assert item1.content.data == content

        item2 = Item.create(u'New name')
        assert item2.name == u'New name'
        assert item2.meta[CONTENTTYPE] == 'text/x.moin.wiki;charset=utf-8'
        assert item2.content.data == content

        item3 = Item.create(u'Third')
        assert item3.name == u'Third'
        assert item3.meta[CONTENTTYPE] == 'text/x.moin.wiki;charset=utf-8'
        assert item3.content.data == content

        assert item1.rev.revid == item2.rev.revid == item3.rev.revid

        item4 = Item.create(u'Second')
        assert item4.meta[CONTENTTYPE] == CONTENTTYPE_NONEXISTENT
 def setup_method(self, method):
     become_trusted(username=u'WikiAdmin')
     for item_name, item_acl, item_content in self.items:
         if item_acl is not None:
             update_item(item_name, {ACL: item_acl}, item_content)
         else:
             update_item(item_name, {}, item_content)
Beispiel #7
0
 def setup_method(self, method):
     become_trusted(username=u'WikiAdmin')
     for item_name, item_acl, item_content in self.items:
         if item_acl is not None:
             update_item(item_name, 0, {ACL: item_acl}, item_content)
         else:
             update_item(item_name, 0, {}, item_content)
 def setup_method(self, method):
     become_trusted(username=u'WikiAdmin')
     for item_names, item_acl, item_content in self.items:
         meta = {NAME: item_names}
         if item_acl is not None:
             meta.update({ACL: item_acl})
         update_item(item_names[0], meta, item_content)
 def custom_setup(self):
     become_trusted(username=u'WikiAdmin')
     for item_names, item_acl, item_content in self.items:
         meta = {NAME: item_names}
         if item_acl is not None:
             meta.update({ACL: item_acl})
         update_item(item_names[0], meta, item_content)
 def custom_setup(self):
     become_trusted(username=u'WikiAdmin')
     for item_name, item_acl, item_content in self.items:
         if item_acl is not None:
             update_item(item_name, {ACL: item_acl}, item_content)
         else:
             update_item(item_name, {}, item_content)
Beispiel #11
0
 def setup_method(self, method):
     # temporary hack till we apply test cleanup mechanism on tests.
     self.app, self.ctx = init_test_app(wikiconfig.Config)
     become_trusted()
     somedict = {u"One": u"1",
                 u"Two": u"2"}
     update_item(u'TestDict', {SOMEDICT: somedict}, DATA)
Beispiel #12
0
 def test_Include_Read_Permission_Denied(self):
     # attempt to include an item that user cannot read
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8', ACL: u'All:write,create,admin,destroy'}, u'no one can read')
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'some text{{page1}}more text')
     page2 = Item.create(u'page2')
     rendered = page2.content._render_data()
     # an error message will follow p tag, similar to: Access Denied, transcluded content suppressed.
     assert '<div class="warning"><p>' in rendered
Beispiel #13
0
 def test_InlineIncludeCreole(self):
     # transclude single paragraph as inline using creole parser
     update_item(u'creole',
                 {CONTENTTYPE: u'text/x.moin.creole;charset=utf-8'},
                 u'creole item')
     update_item(u'page1',
                 {CONTENTTYPE: u'text/x.moin.creole;charset=utf-8'},
                 u'before {{creole}} after')
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>before <span class="moin-transclusion" data-href="/creole">creole item</span> after</p>' in rendered
Beispiel #14
0
    def setup_method(self, method):
        become_trusted()

        somedict = {u"First": u"first item",
                    u"text with spaces": u"second item",
                    u'Empty string': u'',
                    u"Last": u"last item"}
        update_item(u'SomeTestDict', {SOMEDICT: somedict}, DATA)

        somedict = {u"One": u"1",
                    u"Two": u"2"}
        update_item(u'SomeOtherTestDict', {SOMEDICT: somedict}, DATA)
    def test_rename_group_item(self):
        """
        Tests renaming of a group item.
        """
        become_trusted()
        item = update_item(u'SomeGroup', {USERGROUP: ["ExampleUser"]}, DATA)
        assert u'ExampleUser' in flaskg.groups[u'SomeGroup']
        pytest.raises(GroupDoesNotExistError, lambda: flaskg.groups[u'AnotherGroup'])

        item = update_item(u'SomeGroup', {NAME: [u'AnotherGroup', ], USERGROUP: ["ExampleUser"]}, DATA)
        assert u'ExampleUser' in flaskg.groups[u'AnotherGroup']
        pytest.raises(GroupDoesNotExistError, lambda: flaskg.groups[u'SomeGroup'])
    def setup_method(self, method):
        become_trusted()

        somedict = {u"First": u"first item",
                    u"text with spaces": u"second item",
                    u'Empty string': u'',
                    u"Last": u"last item"}
        update_item(u'SomeTestDict', 0, {SOMEDICT: somedict}, DATA)

        somedict = {u"One": u"1",
                    u"Two": u"2"}
        update_item(u'SomeOtherTestDict', 0, {SOMEDICT: somedict}, DATA)
    def test_appending_group_item(self):
        """
        Test scalability by appending a name to a large list of group members.
        """
        become_trusted()
        # long list of users
        members = create_random_string_list(length=15, count=1234)
        test_user = create_random_string_list(length=15, count=1)[0]
        update_item(u'UserGroup', {USERGROUP: members}, DATA)
        update_item(u'UserGroup', {USERGROUP: members + [test_user]}, '')
        result = test_user in flaskg.groups['UserGroup']

        assert result
Beispiel #18
0
    def test_appending_group_item(self):
        """
        Test scalability by appending a name to a large list of group members.
        """
        become_trusted()
        # long list of users
        members = create_random_string_list(length=15, count=1234)
        test_user = create_random_string_list(length=15, count=1)[0]
        update_item(u'UserGroup', {USERGROUP: members}, DATA)
        update_item(u'UserGroup', {USERGROUP: members + [test_user]}, '')
        result = test_user in flaskg.groups['UserGroup']

        assert result
Beispiel #19
0
 def test_Include_Read_Permission_Denied(self):
     # attempt to include an item that user cannot read
     update_item(
         u'page1', {
             CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8',
             ACL: u'All:write,create,admin,destroy'
         }, u'no one can read')
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u'some text{{page1}}more text')
     page2 = Item.create(u'page2')
     rendered = page2.content._render_data()
     # an error message will follow p tag, similar to: Access Denied, transcluded content suppressed.
     assert '<div class="warning"><p>' in rendered
 def test_IncludeHandlesCircularRecursion(self):
     # detect circular recursion and create error message
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'{{page2}}')
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'{{page3}}')
     update_item(u'page3', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'{{page4}}')
     update_item(u'page4', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'{{page2}}')
     page1 = Item.create(u'page1')
     rendered = page1.content._render_data()
     # an error message will follow strong tag
     assert '<strong class="moin-error">' in rendered
Beispiel #21
0
    def test_global_atom_with_an_item(self, app):
        basename = u'Foo'
        update_item(basename, {COMMENT: u"foo data for feed item"}, '')
        with app.test_client() as c:
            rv = c.get(url_for('feed.atom'))
            assert rv.status == '200 OK'
            assert rv.headers['Content-Type'] == 'application/atom+xml'
            assert rv.data.startswith('<?xml')
            assert "foo data for feed item" in rv.data

        # tests the cache invalidation
        update_item(basename, {COMMENT: u"checking if the cache invalidation works"}, '')
        with app.test_client() as c:
            rv = c.get(url_for('feed.atom'))
            assert rv.status == '200 OK'
            assert rv.headers['Content-Type'] == 'application/atom+xml'
            assert rv.data.startswith('<?xml')
            assert "checking if the cache invalidation works" in rv.data
Beispiel #22
0
    def test_global_atom_with_an_item(self, app):
        basename = u'Foo'
        update_item(basename, {COMMENT: u"foo data for feed item"}, '')
        with app.test_client() as c:
            rv = c.get(url_for('feed.atom'))
            assert rv.status == '200 OK'
            assert rv.headers['Content-Type'] == 'application/atom+xml'
            assert rv.data.startswith('<?xml')
            assert "foo data for feed item" in rv.data

        # tests the cache invalidation
        update_item(basename,
                    {COMMENT: u"checking if the cache invalidation works"}, '')
        with app.test_client() as c:
            rv = c.get(url_for('feed.atom'))
            assert rv.status == '200 OK'
            assert rv.headers['Content-Type'] == 'application/atom+xml'
            assert rv.data.startswith('<?xml')
            assert "checking if the cache invalidation works" in rv.data
Beispiel #23
0
    def test_IncludeHandlesCircularRecursion(self):
        # issue #80
        # we use MoinWiki items to make tests simple
        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page2}}')
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page3}}')
        update_item(u'page3', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page4}}')
        update_item(u'page4', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page2}}')

        page1 = MoinWiki.create(u'page1')
        rendered = page1._render_data()
        # an error message will follow strong tag
        assert '<strong class="moin-error">' in rendered
Beispiel #24
0
    def test_rename_group_item(self):
        """
        Tests renaming of a group item.
        """
        become_trusted()
        update_item(u'SomeGroup', {USERGROUP: ["ExampleUser"]}, DATA)
        assert u'ExampleUser' in flaskg.groups[u'SomeGroup']
        pytest.raises(GroupDoesNotExistError,
                      lambda: flaskg.groups[u'AnotherGroup'])

        update_item(u'SomeGroup', {
            NAME: [
                u'AnotherGroup',
            ],
            USERGROUP: ["ExampleUser"]
        }, DATA)
        assert u'ExampleUser' in flaskg.groups[u'AnotherGroup']
        pytest.raises(GroupDoesNotExistError,
                      lambda: flaskg.groups[u'SomeGroup'])
Beispiel #25
0
    def test_item_can_have_several_names(self):
        content = u"This is page content"

        update_item(u'Page',
                    {NAME: [u'Page',
                            u'Another name',
                            ],
                     CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, content)

        item1 = Item.create(u'Page')
        assert item1.name == u'Page'
        assert item1.meta[CONTENTTYPE] == 'text/x.moin.wiki;charset=utf-8'
        assert item1.content.data == content

        item2 = Item.create(u'Another name')
        assert item2.name == u'Another name'
        assert item2.meta[CONTENTTYPE] == 'text/x.moin.wiki;charset=utf-8'
        assert item2.content.data == content

        assert item1.rev.revid == item2.rev.revid
    def test_rename_group_item(self):
        """
        Tests renaming of a group item.
        """
        become_trusted()
        item = update_item(u'SomeGroup', 0, {USERGROUP: ["ExampleUser"]}, DATA)
        item.rename(u'AnotherGroup')

        result = u'ExampleUser' in flaskg.groups[u'AnotherGroup']
        assert result

        py.test.raises(GroupDoesNotExistError, lambda: flaskg.groups[u'SomeGroup'])
    def test_wiki_backend_item_acl_usergroupmember_item(self):
        """
        Test if the wiki group backend works with acl code.
        First check acl rights of a user that is not a member of group
        then add user member to an item group and check acl rights
        """
        become_trusted()
        update_item(u'NewGroup', {USERGROUP: ["ExampleUser"]}, DATA)

        acl_rights = ["NewGroup:read,write"]
        acl = AccessControlList(acl_rights, valid=app.cfg.acl_rights_contents)

        has_rights_before = acl.may(u"AnotherUser", "read")

        # update item - add AnotherUser to a item group NewGroup
        update_item(u'NewGroup', {USERGROUP: ["AnotherUser"]}, '')

        has_rights_after = acl.may(u"AnotherUser", "read")

        assert not has_rights_before, 'AnotherUser has no read rights because in the beginning he is not a member of a group item NewGroup'
        assert has_rights_after, 'AnotherUser must have read rights because after appenditem he is member of NewGroup'
Beispiel #28
0
    def test_wiki_backend_item_acl_usergroupmember_item(self):
        """
        Test if the wiki group backend works with acl code.
        First check acl rights of a user that is not a member of group
        then add user member to an item group and check acl rights
        """
        become_trusted()
        update_item(u'NewGroup', {USERGROUP: ["ExampleUser"]}, DATA)

        acl_rights = ["NewGroup:read,write"]
        acl = AccessControlList(acl_rights, valid=app.cfg.acl_rights_contents)

        has_rights_before = acl.may(u"AnotherUser", "read")

        # update item - add AnotherUser to a item group NewGroup
        update_item(u'NewGroup', {USERGROUP: ["AnotherUser"]}, '')

        has_rights_after = acl.may(u"AnotherUser", "read")

        assert not has_rights_before, 'AnotherUser has no read rights because in the beginning he is not a member of a group item NewGroup'
        assert has_rights_after, 'AnotherUser must have read rights because after appenditem he is member of NewGroup'
Beispiel #29
0
 def test_ExternalInclude(self):
     # external include
     update_item(u"page1", {CONTENTTYPE: u"text/x.moin.wiki;charset=utf-8"}, u"{{http://moinmo.in}}")
     rendered = Item.create(u"page1").content._render_data()
     assert (
         '<object class="moin-http moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object>'
         in rendered
     )
     # external include embedded within text (object is an inline tag)
     update_item(u"page1", {CONTENTTYPE: u"text/x.moin.wiki;charset=utf-8"}, u"before {{http://moinmo.in}} after")
     rendered = Item.create(u"page1").content._render_data()
     assert (
         '<p>before <object class="moin-http moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object> after</p>'
         in rendered
     )
     # external include embedded within text italic and bold markup (object is an inline tag)
     update_item(
         u"page1",
         {CONTENTTYPE: u"text/x.moin.wiki;charset=utf-8"},
         u"before ''italic '''bold {{http://moinmo.in}} bold''' italic'' normal",
     )
     rendered = Item.create(u"page1").content._render_data()
     assert (
         '<p>before <em>italic <strong>bold <object class="moin-http moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object> bold</strong> italic</em> normal</p>'
         in rendered
     )
Beispiel #30
0
 def test__render_data_diff(self):
     item_name = u'Html_Item'
     empty_html = u'<span></span>'
     html = u'<span>\ud55c</span>'
     meta = {CONTENTTYPE: u'text/html;charset=utf-8'}
     item = Item.create(item_name)
     item._save(meta, empty_html)
     item = Item.create(item_name)
     # Unicode test, html escaping
     rev1 = update_item(item_name, meta, html)
     rev2 = update_item(item_name, {}, u'     ')
     result = Text._render_data_diff(item.content, rev1, rev2)
     assert escape(html) in result
     # Unicode test, whitespace
     rev1 = update_item(item_name, {}, u'\n\n')
     rev2 = update_item(item_name, {}, u'\n     \n')
     result = Text._render_data_diff(item.content, rev1, rev2)
     assert '<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>' in result
     # If fairly similar diffs are correctly spanned or not, also check indent
     rev1 = update_item(item_name, {}, u'One Two Three Four\nSix\n\ud55c')
     rev2 = update_item(item_name, {}, u'Two Three Seven Four\nSix\n\ud55c')
     result = Text._render_data_diff(item.content, rev1, rev2)
     assert '<span>One </span>Two Three Four' in result
     assert 'Two Three <span>Seven </span>Four' in result
     # Check for diff_html.diff return types
     assert reduce(lambda x, y: x and y, [isinstance(i[1], unicode) and isinstance(i[3], unicode) for i in diff_html.diff(u'One Two Three Four\nSix\n', u'Two Three Seven Four\nSix Seven\n')], True)
Beispiel #31
0
 def test_IncludeHandlesCircularRecursion(self):
     # detect circular recursion and create error message
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u'{{page2}}')
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u'{{page3}}')
     update_item(u'page3', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u'{{page4}}')
     update_item(u'page4', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u'{{page2}}')
     page1 = Item.create(u'page1')
     rendered = page1.content._render_data()
     # an error message will follow strong tag
     assert '<strong class="moin-error">' in rendered
Beispiel #32
0
 def test__render_data_diff(self):
     item_name = u'Html_Item'
     empty_html = u'<span></span>'
     html = u'<span>\ud55c</span>'
     meta = {CONTENTTYPE: u'text/html;charset=utf-8'}
     item = Item.create(item_name)
     item._save(meta, empty_html)
     item = Item.create(item_name)
     # Unicode test, html escaping
     rev1 = update_item(item_name, meta, html)
     rev2 = update_item(item_name, {}, u'     ')
     result = Text._render_data_diff(item.content, rev1, rev2)
     assert escape(html) in result
     # Unicode test, whitespace
     rev1 = update_item(item_name, {}, u'\n\n')
     rev2 = update_item(item_name, {}, u'\n     \n')
     result = Text._render_data_diff(item.content, rev1, rev2)
     assert '<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>' in result
     # If fairly similar diffs are correctly spanned or not, also check indent
     rev1 = update_item(item_name, {}, u'One Two Three Four\nSix\n\ud55c')
     rev2 = update_item(item_name, {}, u'Two Three Seven Four\nSix\n\ud55c')
     result = Text._render_data_diff(item.content, rev1, rev2)
     assert '<span>One </span>Two Three Four' in result
     assert 'Two Three <span>Seven </span>Four' in result
     # Check for diff_html.diff return types
     assert reduce(lambda x, y: x and y, [isinstance(i[1], unicode) and isinstance(i[3], unicode) for i in diff_html.diff(u'One Two Three Four\nSix\n', u'Two Three Seven Four\nSix Seven\n')], True)
Beispiel #33
0
    def test_item_can_have_several_names(self):
        content = u"This is page content"

        update_item(
            u'Page', {
                NAME: [
                    u'Page',
                    u'Another name',
                ],
                CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'
            }, content)

        item1 = Item.create(u'Page')
        assert item1.name == u'Page'
        assert item1.meta[CONTENTTYPE] == 'text/x.moin.wiki;charset=utf-8'
        assert item1.content.data == content

        item2 = Item.create(u'Another name')
        assert item2.name == u'Another name'
        assert item2.meta[CONTENTTYPE] == 'text/x.moin.wiki;charset=utf-8'
        assert item2.content.data == content

        assert item1.rev.revid == item2.rev.revid
Beispiel #34
0
    def test_rename_acts_only_in_active_name_in_case_there_are_several_names(
            self):
        content = u"This is page content"

        update_item(
            u'Page', {
                NAME: [
                    u'First',
                    u'Second',
                    u'Third',
                ],
                CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'
            }, content)

        item = Item.create(u'Second')
        item.rename(u'New name', comment=u'renamed')

        item1 = Item.create(u'First')
        assert item1.name == u'First'
        assert item1.meta[CONTENTTYPE] == 'text/x.moin.wiki;charset=utf-8'
        assert item1.content.data == content

        item2 = Item.create(u'New name')
        assert item2.name == u'New name'
        assert item2.meta[CONTENTTYPE] == 'text/x.moin.wiki;charset=utf-8'
        assert item2.content.data == content

        item3 = Item.create(u'Third')
        assert item3.name == u'Third'
        assert item3.meta[CONTENTTYPE] == 'text/x.moin.wiki;charset=utf-8'
        assert item3.content.data == content

        assert item1.rev.revid == item2.rev.revid == item3.rev.revid

        item4 = Item.create(u'Second')
        assert item4.meta[CONTENTTYPE] == CONTENTTYPE_NONEXISTENT
Beispiel #35
0
 def test_InlineIncludeImage(self):
     # the 3rd parameter, u'',  should be a binary string defining a png image, but it is not needed for this simple test
     update_item(u"logo.png", {CONTENTTYPE: u"image/png"}, u"")
     # simple transclusion
     update_item(u"page1", {CONTENTTYPE: u"text/x.moin.wiki;charset=utf-8"}, u"{{logo.png}}")
     rendered = Item.create(u"page1").content._render_data()
     assert '<p><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
     assert '/logo.png" /></span></p>' in rendered
     # within paragraph
     update_item(u"page1", {CONTENTTYPE: u"text/x.moin.wiki;charset=utf-8"}, u"text {{logo.png}} text")
     rendered = Item.create(u"page1").content._render_data()
     assert '<p>text <span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
     assert '/logo.png" /></span> text</p>' in rendered
     # within markup
     update_item(
         u"page1",
         {CONTENTTYPE: u"text/x.moin.wiki;charset=utf-8"},
         u"Normal ''italic '''bold {{logo.png}} bold''' italic'' normal",
     )
     rendered = Item.create(u"page1").content._render_data()
     assert (
         '<p>Normal <em>italic <strong>bold <span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src='
         in rendered
     )
     assert '/logo.png" /></span> bold</strong> italic</em> normal</p>' in rendered
     # multiple transclusions
     update_item(u"page1", {CONTENTTYPE: u"text/x.moin.wiki;charset=utf-8"}, u"{{logo.png}}{{logo.png}}")
     rendered = Item.create(u"page1").content._render_data()
     assert '<p><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
     assert (
         '/logo.png" /></span><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src='
         in rendered
     )
     # check for old bug
     assert "<p />" not in rendered
     assert "<p></p>" not in rendered
    def test_copy_group_item(self):
        """
        Tests copying a group item.
        """
        py.test.skip("item.copy() is not finished")

        become_trusted()
        item = update_item(u'SomeGroup', 0,  {USERGROUP: ["ExampleUser"]}, DATA)
        item.copy(u'SomeOtherGroup')

        result = u'ExampleUser' in flaskg.groups[u'SomeOtherGroup']
        assert result

        result = u'ExampleUser' in flaskg.groups[u'SomeGroup']
        assert result
Beispiel #37
0
    def test_InlineIncludeLogo(self):
        # the 3rd parameter, u'',  should be a binary string defining a png image, but it is not needed for this simple test
        update_item(u'logo', {CONTENTTYPE: u'image/png'}, u'')

        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{logo}}')
        rendered = MoinWiki.create(u'page1')._render_data()
        assert '<img alt="logo" class="moin-transclusion"' in rendered

        # <p /> is not valid html5; should be <p></p>. to be valid.  Even better, there should be no empty p's.
        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{logo}}{{logo}}')
        rendered = MoinWiki.create(u'page1')._render_data()
        assert '<p />' not in rendered
        assert '<p></p>' not in rendered
Beispiel #38
0
 def test_serialize_rev(self):
     become_trusted()
     params = (u'foo1', 0, dict(m1=u"m1"), 'bar1')
     item = update_item(*params)
     rev = item.get_revision(0)
     xmlfile = StringIO()
     serialize(rev, xmlfile)
     xml = xmlfile.getvalue()
     expected = (
         XML_DECL + '<revision revno="0">'
         '<meta>'
         '<entry key="mimetype"><str>application/octet-stream</str>\n</entry>\n'
         '<entry key="sha1"><str>763675d6a1d8d0a3a28deca62bb68abd8baf86f3</str>\n</entry>\n'
         '<entry key="m1"><str>m1</str>\n</entry>\n'
         '<entry key="name"><str>foo1</str>\n</entry>\n'
         '<entry key="uuid"><str>foo1</str>\n</entry>\n'
         '</meta>\n'
         '<data coding="base64"><chunk>YmFyMQ==</chunk>\n</data>\n'
         '</revision>\n')
     assert expected == xml
Beispiel #39
0
 def test_ExternalInclude(self):
     # external include
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u'{{http://moinmo.in}}')
     rendered = Item.create(u'page1').content._render_data()
     assert '<object class="moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object>' in rendered
     # external include embedded within text (object is an inline tag)
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u'before {{http://moinmo.in}} after')
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>before <object class="moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object> after</p>' in rendered
     # external include embedded within text italic and bold markup (object is an inline tag)
     update_item(
         u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
         u"before ''italic '''bold {{http://moinmo.in}} bold''' italic'' normal"
     )
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>before <em>italic <strong>bold <object class="moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object> bold</strong> italic</em> normal</p>' in rendered
Beispiel #40
0
 def test_serialize_item(self):
     become_trusted()
     testparams = [
         (u'foo2', 0, dict(m1=u"m1r0"), 'bar2'),
         (u'foo2', 1, dict(m1=u"m1r1"), 'baz2'),
     ]
     for params in testparams:
         item = update_item(*params)
     xmlfile = StringIO()
     serialize(item, xmlfile)
     xml = xmlfile.getvalue()
     expected = (
         XML_DECL + '<item name="foo2">'
         '<meta></meta>\n'
         '<revision revno="0">'
         '<meta>'
         '<entry key="mimetype"><str>application/octet-stream</str>\n</entry>\n'
         '<entry key="sha1"><str>033c4846b506a4a48e32cdf54515c91d3499adb3</str>\n</entry>\n'
         '<entry key="m1"><str>m1r0</str>\n</entry>\n'
         '<entry key="name"><str>foo2</str>\n</entry>\n'
         '<entry key="uuid"><str>foo2</str>\n</entry>\n'
         '</meta>\n'
         '<data coding="base64"><chunk>YmFyMg==</chunk>\n</data>\n'
         '</revision>\n'
         '<revision revno="1">'
         '<meta>'
         '<entry key="mimetype"><str>application/octet-stream</str>\n</entry>\n'
         '<entry key="sha1"><str>f91d8fc20a5de853e62105cc1ee0bf47fd7ded0f</str>\n</entry>\n'
         '<entry key="m1"><str>m1r1</str>\n</entry>\n'
         '<entry key="name"><str>foo2</str>\n</entry>\n'
         '<entry key="uuid"><str>foo2</str>\n</entry>\n'
         '</meta>\n'
         '<data coding="base64"><chunk>YmF6Mg==</chunk>\n</data>\n'
         '</revision>\n'
         '</item>\n')
     assert expected == xml
Beispiel #41
0
    def test_rename_recursion(self):
        update_item(u'Page', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u'Page 1')
        update_item(u'Page/Child',
                    {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u'this is child')
        update_item(u'Page/Child/Another',
                    {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u'another child')

        item = Item.create(u'Page')
        item.rename(u'Renamed_Page', comment=u'renamed')

        # items at original name and its contents after renaming
        item = Item.create(u'Page')
        assert item.name == u'Page'
        assert item.meta[CONTENTTYPE] == CONTENTTYPE_NONEXISTENT
        item = Item.create(u'Page/Child')
        assert item.name == u'Page/Child'
        assert item.meta[CONTENTTYPE] == CONTENTTYPE_NONEXISTENT
        item = Item.create(u'Page/Child/Another')
        assert item.name == u'Page/Child/Another'
        assert item.meta[CONTENTTYPE] == CONTENTTYPE_NONEXISTENT

        # item at new name and its contents after renaming
        item = Item.create(u'Renamed_Page')
        assert item.name == u'Renamed_Page'
        assert item.meta[NAME_OLD] == [u'Page']
        assert item.meta[COMMENT] == u'renamed'
        assert item.content.data == u'Page 1'

        item = Item.create(u'Renamed_Page/Child')
        assert item.name == u'Renamed_Page/Child'
        assert item.meta[NAME_OLD] == [u'Page/Child']
        assert item.meta[COMMENT] == u'renamed'
        assert item.content.data == u'this is child'

        item = Item.create(u'Renamed_Page/Child/Another')
        assert item.name == u'Renamed_Page/Child/Another'
        assert item.meta[NAME_OLD] == [u'Page/Child/Another']
        assert item.meta[COMMENT] == u'renamed'
        assert item.content.data == u'another child'
    def test_member_removed_from_group_item(self):
        """
        Tests appending a member to a large list of group members and
        recreating the item without the member.
        """
        become_trusted()

        # long list of users
        members = create_random_string_list()
        update_item(u'UserGroup', {USERGROUP: members}, DATA)

        # updates the text with the text_user
        test_user = create_random_string_list(length=15, count=1)[0]
        update_item(u'UserGroup', {USERGROUP: [test_user]}, DATA)
        result = test_user in flaskg.groups[u'UserGroup']
        assert result

        # updates the text without test_user
        update_item(u'UserGroup', {}, DATA)
        result = test_user in flaskg.groups[u'UserGroup']
        assert not result
Beispiel #43
0
    def test_member_removed_from_group_item(self):
        """
        Tests appending a member to a large list of group members and
        recreating the item without the member.
        """
        become_trusted()

        # long list of users
        members = create_random_string_list()
        update_item(u'UserGroup', {USERGROUP: members}, DATA)

        # updates the text with the text_user
        test_user = create_random_string_list(length=15, count=1)[0]
        update_item(u'UserGroup', {USERGROUP: [test_user]}, DATA)
        result = test_user in flaskg.groups[u'UserGroup']
        assert result

        # updates the text without test_user
        update_item(u'UserGroup', {}, DATA)
        result = test_user in flaskg.groups[u'UserGroup']
        assert not result
Beispiel #44
0
    def test_rename_recursion(self):
        update_item(u'Page', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Page 1')
        update_item(u'Page/Child', {CONTENTTYPE: u'text/x.moin.wiki'}, u'this is child')
        update_item(u'Page/Child/Another', {CONTENTTYPE: u'text/x.moin.wiki'}, u'another child')

        item = Item.create(u'Page')
        item.rename(u'Renamed_Page', comment=u'renamed')

        # items at original name and its contents after renaming
        item = Item.create(u'Page')
        assert item.name == u'Page'
        assert item.meta[CONTENTTYPE] == 'application/x-nonexistent'
        item = Item.create(u'Page/Child')
        assert item.name == u'Page/Child'
        assert item.meta[CONTENTTYPE] == 'application/x-nonexistent'
        item = Item.create(u'Page/Child/Another')
        assert item.name == u'Page/Child/Another'
        assert item.meta[CONTENTTYPE] == 'application/x-nonexistent'

        # item at new name and its contents after renaming
        item = Item.create(u'Renamed_Page')
        assert item.name == u'Renamed_Page'
        assert item.meta['name_old'] == u'Page'
        assert item.meta['comment'] == u'renamed'
        assert item.data == u'Page 1'

        item = Item.create(u'Renamed_Page/Child')
        assert item.name == u'Renamed_Page/Child'
        assert item.meta['name_old'] == u'Page/Child'
        assert item.meta['comment'] == u'renamed'
        assert item.data == u'this is child'

        item = Item.create(u'Renamed_Page/Child/Another')
        assert item.name == u'Renamed_Page/Child/Another'
        assert item.meta['name_old'] == u'Page/Child/Another'
        assert item.meta['comment'] == u'renamed'
        assert item.data == u'another child'
Beispiel #45
0
    def test_rename_recursion(self):
        update_item(u'Page', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'Page 1')
        update_item(u'Page/Child', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'this is child')
        update_item(u'Page/Child/Another', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'another child')

        item = Item.create(u'Page')
        item.rename(u'Renamed_Page', comment=u'renamed')

        # items at original name and its contents after renaming
        item = Item.create(u'Page')
        assert item.name == u'Page'
        assert item.meta[CONTENTTYPE] == CONTENTTYPE_NONEXISTENT
        item = Item.create(u'Page/Child')
        assert item.name == u'Page/Child'
        assert item.meta[CONTENTTYPE] == CONTENTTYPE_NONEXISTENT
        item = Item.create(u'Page/Child/Another')
        assert item.name == u'Page/Child/Another'
        assert item.meta[CONTENTTYPE] == CONTENTTYPE_NONEXISTENT

        # item at new name and its contents after renaming
        item = Item.create(u'Renamed_Page')
        assert item.name == u'Renamed_Page'
        assert item.meta[NAME_OLD] == [u'Page']
        assert item.meta[COMMENT] == u'renamed'
        assert item.content.data == u'Page 1'

        item = Item.create(u'Renamed_Page/Child')
        assert item.name == u'Renamed_Page/Child'
        assert item.meta[NAME_OLD] == [u'Page/Child']
        assert item.meta[COMMENT] == u'renamed'
        assert item.content.data == u'this is child'

        item = Item.create(u'Renamed_Page/Child/Another')
        assert item.name == u'Renamed_Page/Child/Another'
        assert item.meta[NAME_OLD] == [u'Page/Child/Another']
        assert item.meta[COMMENT] == u'renamed'
        assert item.content.data == u'another child'
Beispiel #46
0
 def custom_setup(self):
     become_trusted()
     for group, members in self.test_groups.iteritems():
         update_item(group, {USERGROUP: members}, DATA)
Beispiel #47
0
    def test_InlineInclude(self):

        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u'before {{page2}} after')
        # transclude single paragraph as inline
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u'Single line')
        rendered = Item.create(u'page1').content._render_data()
        assert '<p>before <span class="moin-transclusion" data-href="/page2">Single line</span> after</p>' in rendered
        # transclude multiple paragraphs as block
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u'Two\n\nParagraphs')
        rendered = Item.create(u'page1').content._render_data()
        assert '<p>before </p><div class="moin-transclusion" data-href="/page2"><p>Two</p><p>Paragraphs</p></div><p> after</p></div>' in rendered
        # transclude single paragraph with internal markup as inline
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u"this text contains ''italic'' string")
        rendered = Item.create(u'page1').content._render_data()
        assert 'before <span class="moin-transclusion" data-href="/page2">this text contains <em>italic</em>' in rendered
        # transclude single paragraph as only content within a paragraph
        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u'Content of page2 is\n\n{{page2}}')
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u"Single Line")
        rendered = Item.create(u'page1').content._render_data()
        assert '<p>Content of page2 is</p><p><span class="moin-transclusion" data-href="/page2">Single Line</span></p>' in rendered
        # transclude single row table within a paragraph, block element forces paragraph to be split into 2 parts
        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u'before {{page2}} after')
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u"|| table || cell ||")
        rendered = Item.create(u'page1').content._render_data()
        assert '<p>before </p><div class="moin-transclusion" data-href="/page2"><table' in rendered
        assert '</table></div><p> after</p>' in rendered
        assert rendered.count('<table') == 1
        # transclude two row table within a paragraph, block element forces paragraph to be split into 2 parts
        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u'before {{page2}} after')
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u"|| this || has ||\n|| two || rows ||")
        rendered = Item.create(u'page1').content._render_data()
        # inclusion of block item within a paragraph results in a before and after p
        assert '<p>before </p><div class="moin-transclusion" data-href="/page2"><table' in rendered
        assert '</table></div><p> after</p>' in rendered
        assert rendered.count('<table') == 1
        # transclude nonexistent item
        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u'before {{nonexistent}} after')
        rendered = Item.create(u'page1').content._render_data()
        assert '<p>before <span class="moin-transclusion" data-href="/nonexistent"><a href="/+modify/nonexistent">' in rendered
        assert '</a></span> after</p>' in rendered
        # transclude empty item
        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u'text {{page2}} text')
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u"")
        rendered = Item.create(u'page1').content._render_data()
        assert '<p>text <span class="moin-transclusion" data-href="/page2"></span> text</p>' in rendered
    def test_InlineInclude(self):

        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'before {{page2}} after')
        # transclude single paragraph as inline
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'Single line')
        rendered = Item.create(u'page1').content._render_data()
        assert '<p>before <span class="moin-transclusion" data-href="/page2">Single line</span> after</p>' in rendered
        # transclude multiple paragraphs as block
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'Two\n\nParagraphs')
        rendered = Item.create(u'page1').content._render_data()
        assert '<p>before </p><div class="moin-transclusion" data-href="/page2"><p>Two</p><p>Paragraphs</p></div><p> after</p></div>' in rendered
        # transclude single paragraph with internal markup as inline
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"this text contains ''italic'' string")
        rendered = Item.create(u'page1').content._render_data()
        assert 'before <span class="moin-transclusion" data-href="/page2">this text contains <em>italic</em>' in rendered
        # transclude single paragraph as only content within a paragraph
        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'Content of page2 is\n\n{{page2}}')
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Single Line")
        rendered = Item.create(u'page1').content._render_data()
        assert '<p>Content of page2 is</p><p><span class="moin-transclusion" data-href="/page2">Single Line</span></p>' in rendered
        # transclude single row table within a paragraph, block element forces paragraph to be split into 2 parts
        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'before {{page2}} after')
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"|| table || cell ||")
        rendered = Item.create(u'page1').content._render_data()
        assert '<p>before </p><div class="moin-transclusion" data-href="/page2"><table' in rendered
        assert '</table></div><p> after</p>' in rendered
        assert rendered.count('<table>') == 1
        # transclude two row table within a paragraph, block element forces paragraph to be split into 2 parts
        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'before {{page2}} after')
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"|| this || has ||\n|| two || rows ||")
        rendered = Item.create(u'page1').content._render_data()
        # inclusion of block item within a paragraph results in a before and after p
        assert '<p>before </p><div class="moin-transclusion" data-href="/page2"><table' in rendered
        assert '</table></div><p> after</p>' in rendered
        assert rendered.count('<table>') == 1
        # transclude nonexistent item
        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'before {{nonexistent}} after')
        rendered = Item.create(u'page1').content._render_data()
        assert '<p>before <span class="moin-transclusion" data-href="/nonexistent"><a href="/+modify/nonexistent">' in rendered
        assert '</a></span> after</p>' in rendered
        # transclude empty item
        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'text {{page2}} text')
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"")
        rendered = Item.create(u'page1').content._render_data()
        assert '<p>text <span class="moin-transclusion" data-href="/page2"></span> text</p>' in rendered
Beispiel #49
0
    def test_rename_recursion_with_multiple_names_and_children(self):
        update_item(
            u'Foo', {
                CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8',
                NAME: [u'Other', u'Page', u'Foo'],
            }, u'Parent')
        update_item(u'Page/Child',
                    {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u'Child of Page')
        update_item(u'Other/Child2',
                    {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u'Child of Other')
        update_item(
            u'Another', {
                CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8',
                NAME: [u'Another', u'Page/Second'],
            }, u'Both')
        update_item(u'Page/Second/Child',
                    {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u'Child of Second')
        update_item(u'Another/Child',
                    {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                    u'Child of Another')

        item = Item.create(u'Page')

        item.rename(u'Renamed', comment=u'renamed')

        assert Item.create(
            u'Page/Child').meta[CONTENTTYPE] == CONTENTTYPE_NONEXISTENT
        assert Item.create(u'Renamed/Child').content.data == u'Child of Page'
        assert Item.create(
            u'Page/Second').meta[CONTENTTYPE] == CONTENTTYPE_NONEXISTENT
        assert Item.create(u'Renamed/Second').content.data == u'Both'
        assert Item.create(u'Another').content.data == u'Both'
        assert Item.create(
            u'Page/Second/Child').meta[CONTENTTYPE] == CONTENTTYPE_NONEXISTENT
        assert Item.create(
            u'Renamed/Second/Child').content.data == u'Child of Second'
        assert Item.create(u'Other/Child2').content.data == u'Child of Other'
        assert Item.create(
            u'Another/Child').content.data == u'Child of Another'
 def test_IncludeAsLinkAlternate(self):
     # the 3rd parameter, u'',  should be a binary string defining a png image, but it is not needed for this simple test
     update_item(u'logo.png', {CONTENTTYPE: u'image/png'}, u'')
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Single Line")
     # image as link alternate
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"text [[page2|{{logo.png}}]] text")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>text <a href="/page2"><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src="' in rendered
     assert '/logo.png" /></span></a> text</p>' in rendered
     # link alternate with image embedded in markup
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"text [[page2|plain '''bold {{logo.png}} bold''' plain]] text")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>text <a href="/page2">plain <strong>bold <span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src="' in rendered
     assert '/logo.png" /></span> bold</strong> plain</a> text</p>' in rendered
     # nonexistent image used in link alternate
     # XXX html validation errora: A inside A - the image alternate turns into an A-tag to create the non-existant image.  Error is easily seen.
     # IE9, Firefox, Chrome, Safari, and Opera display this OK;  the only usable hyperlink is to create the missing image.
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"text [[page2|{{logoxxx.png}}]] text")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>text <a href="/page2"><span class="moin-transclusion" data-href="/logoxxx.png"><a href="/+modify/logoxxx.png">' in rendered
     assert '</a></span></a> text</p>' in rendered
     # image used as alternate to nonexistent page
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"text [[page2xxx|{{logo.png}}]] text")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>text <a class="moin-nonexistent" href="/page2xxx"><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src="' in rendered
     assert '/logo.png" /></span></a> text</p>' in rendered
     # transclude block elem as link alternate to nonexistent page
     # XXX html validation errors, block element inside A.
     # IE9, Firefox, Chrome, Safari, and Opera display this OK;  the hyperlink is the entire div enclosing the block elem
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'text [[MyPage|{{page2}}]] text')
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Double\n\nLine")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>text <a class="moin-nonexistent" href="/MyPage"><div class="moin-transclusion" data-href="/page2"><p>Double</p><p>Line</p></div></a> text</p>' in rendered
     # transclude empty item as link alternate to nonexistent page
     # hyperlink will be empty span and invisible
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'text [[MyPage|{{page2}}]] text')
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>text <a class="moin-nonexistent" href="/MyPage"><span class="moin-transclusion" data-href="/page2"></span></a> text</p>' in rendered
     # transclude external page as link alternate to nonexistent page
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'text [[MyPage|{{http://moinmo.in}}]] text')
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>text <a class="moin-nonexistent" href="/MyPage"><object class="moin-http moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object></a> text</p>' in rendered
 def test_InlineIncludeImage(self):
     # the 3rd parameter, u'',  should be a binary string defining a png image, but it is not needed for this simple test
     update_item(u'logo.png', {CONTENTTYPE: u'image/png'}, u'')
     # simple transclusion
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'{{logo.png}}')
     rendered = Item.create(u'page1').content._render_data()
     assert '<p><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
     assert '/logo.png" /></span></p>' in rendered
     # simple transclusion with alt text and width
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'{{logo.png|my alt text|width="100"}}')
     rendered = Item.create(u'page1').content._render_data()
     assert '<p><span class="moin-transclusion" data-href="/logo.png"><img alt="my alt text" src=' in rendered
     assert 'logo.png" width="100" /></span></p>' in rendered
     # within paragraph
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'text {{logo.png}} text')
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>text <span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
     assert '/logo.png" /></span> text</p>' in rendered
     # within markup
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Normal ''italic '''bold {{logo.png}} bold''' italic'' normal")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>Normal <em>italic <strong>bold <span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
     assert '/logo.png" /></span> bold</strong> italic</em> normal</p>' in rendered
     # multiple transclusions
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u'{{logo.png}}{{logo.png}}')
     rendered = Item.create(u'page1').content._render_data()
     assert '<p><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
     assert '/logo.png" /></span><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
     # check for old bug
     assert '<p />' not in rendered
     assert '<p></p>' not in rendered
 def test_InlineIncludeWithinMarkup(self):
     # transclude single line item within italic and bold markup
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Normal ''italic '''bold {{page2}} bold''' italic'' normal")
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Single Line")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>Normal <em>italic <strong>bold <span class="moin-transclusion" data-href="/page2">Single Line</span> bold</strong> italic</em> normal</p>' in rendered
     # transclude double line item within italic and bold markup
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Normal ''italic '''bold {{page2}} bold''' italic'' normal")
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Double\n\nLine")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>Normal <em>italic <strong>bold </strong></em></p><div class="moin-transclusion" data-href="/page2"><p>Double</p><p>Line</p></div><p><em><strong> bold</strong> italic</em> normal</p>' in rendered
     # transclude single line item within comment
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"comment /* before {{page2}} after */")
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Single Line")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>comment <span class="comment">before <span class="moin-transclusion" data-href="/page2">Single Line</span> after</span></p>' in rendered
     # transclude double line item within comment
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"comment /* before {{page2}} after */")
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'}, u"Double\n\nLine")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>comment <span class="comment">before </span></p><div class="comment moin-transclusion" data-href="/page2"><p>Double</p><p>Line</p></div><p><span class="comment"> after</span></p>' in rendered
 def test_InlineIncludeCreole(self):
     # transclude single paragraph as inline using creole parser
     update_item(u'creole', {CONTENTTYPE: u'text/x.moin.creole;charset=utf-8'}, u'creole item')
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.creole;charset=utf-8'}, u'before {{creole}} after')
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>before <span class="moin-transclusion" data-href="/creole">creole item</span> after</p>' in rendered
Beispiel #54
0
    def test_dict(self):
        become_trusted()
        somedict = {u"One": u"1", u"Two": u"2"}
        update_item(u'TestDict', {SOMEDICT: somedict}, "This is a dict item.")

        return u"TestDict"
Beispiel #55
0
 def test_InlineIncludeWithinMarkup(self):
     # transclude single line item within italic and bold markup
     update_item(
         u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
         u"Normal ''italic '''bold {{page2}} bold''' italic'' normal")
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u"Single Line")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>Normal <em>italic <strong>bold <span class="moin-transclusion" data-href="/page2">Single Line</span> bold</strong> italic</em> normal</p>' in rendered
     # transclude double line item within italic and bold markup
     update_item(
         u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
         u"Normal ''italic '''bold {{page2}} bold''' italic'' normal")
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u"Double\n\nLine")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>Normal <em>italic <strong>bold </strong></em></p><div class="moin-transclusion" data-href="/page2"><p>Double</p><p>Line</p></div><p><em><strong> bold</strong> italic</em> normal</p>' in rendered
     # transclude single line item within comment
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u"comment /* before {{page2}} after */")
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u"Single Line")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>comment <span class="comment">before <span class="moin-transclusion" data-href="/page2">Single Line</span> after</span></p>' in rendered
     # transclude double line item within comment
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u"comment /* before {{page2}} after */")
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u"Double\n\nLine")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>comment <span class="comment">before </span></p><div class="comment moin-transclusion" data-href="/page2"><p>Double</p><p>Line</p></div><p><span class="comment"> after</span></p>' in rendered
Beispiel #56
0
 def test_InlineIncludeImage(self):
     # the 3rd parameter, u'',  should be a binary string defining a png image, but it is not needed for this simple test
     update_item(u'logo.png', {CONTENTTYPE: u'image/png'}, u'')
     # simple transclusion
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u'{{logo.png}}')
     rendered = Item.create(u'page1').content._render_data()
     assert '<p><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
     assert '/logo.png" /></span></p>' in rendered
     # simple transclusion with alt text and width
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u'{{logo.png|my alt text|width="100"}}')
     rendered = Item.create(u'page1').content._render_data()
     assert '<p><span class="moin-transclusion" data-href="/logo.png"><img alt="my alt text" src=' in rendered
     assert 'logo.png" width="100" /></span></p>' in rendered
     # within paragraph
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u'text {{logo.png}} text')
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>text <span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
     assert '/logo.png" /></span> text</p>' in rendered
     # within markup
     update_item(
         u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
         u"Normal ''italic '''bold {{logo.png}} bold''' italic'' normal")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>Normal <em>italic <strong>bold <span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
     assert '/logo.png" /></span> bold</strong> italic</em> normal</p>' in rendered
     # multiple transclusions
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u'{{logo.png}}{{logo.png}}')
     rendered = Item.create(u'page1').content._render_data()
     assert '<p><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
     assert '/logo.png" /></span><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src=' in rendered
     # check for old bug
     assert '<p />' not in rendered
     assert '<p></p>' not in rendered
Beispiel #57
0
 def test_IncludeAsLinkAlternate(self):
     # the 3rd parameter, u'',  should be a binary string defining a png image, but it is not needed for this simple test
     update_item(u'logo.png', {CONTENTTYPE: u'image/png'}, u'')
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u"Single Line")
     # image as link alternate
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u"text [[page2|{{logo.png}}]] text")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>text <a href="/page2"><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src="' in rendered
     assert '/logo.png" /></span></a> text</p>' in rendered
     # link alternate with image embedded in markup
     update_item(
         u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
         u"text [[page2|plain '''bold {{logo.png}} bold''' plain]] text")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>text <a href="/page2">plain <strong>bold <span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src="' in rendered
     assert '/logo.png" /></span> bold</strong> plain</a> text</p>' in rendered
     # nonexistent image used in link alternate
     # XXX html validation errora: A inside A - the image alternate turns into an A-tag to create the non-existant image.  Error is easily seen.
     # IE9, Firefox, Chrome, Safari, and Opera display this OK;  the only usable hyperlink is to create the missing image.
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u"text [[page2|{{logoxxx.png}}]] text")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>text <a href="/page2"><span class="moin-transclusion" data-href="/logoxxx.png"><a href="/+modify/logoxxx.png">' in rendered
     assert '</a></span></a> text</p>' in rendered
     # image used as alternate to nonexistent page
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u"text [[page2xxx|{{logo.png}}]] text")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>text <a class="moin-nonexistent" href="/page2xxx"><span class="moin-transclusion" data-href="/logo.png"><img alt="logo.png" src="' in rendered
     assert '/logo.png" /></span></a> text</p>' in rendered
     # transclude block elem as link alternate to nonexistent page
     # XXX html validation errors, block element inside A.
     # IE9, Firefox, Chrome, Safari, and Opera display this OK;  the hyperlink is the entire div enclosing the block elem
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u'text [[MyPage|{{page2}}]] text')
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u"Double\n\nLine")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>text <a class="moin-nonexistent" href="/MyPage"><div class="moin-transclusion" data-href="/page2"><p>Double</p><p>Line</p></div></a> text</p>' in rendered
     # transclude empty item as link alternate to nonexistent page
     # hyperlink will be empty span and invisible
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u'text [[MyPage|{{page2}}]] text')
     update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u"")
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>text <a class="moin-nonexistent" href="/MyPage"><span class="moin-transclusion" data-href="/page2"></span></a> text</p>' in rendered
     # transclude external page as link alternate to nonexistent page
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki;charset=utf-8'},
                 u'text [[MyPage|{{http://moinmo.in}}]] text')
     rendered = Item.create(u'page1').content._render_data()
     assert '<p>text <a class="moin-nonexistent" href="/MyPage"><object class="moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object></a> text</p>' in rendered
Beispiel #58
0
 def test_ExternalInclude(self):
     update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{http://moinmo.in}}')
     rendered = MoinWiki.create(u'page1')._render_data()
     assert '<object class="moin-http moin-transclusion" data="http://moinmo.in" data-href="http://moinmo.in">http://moinmo.in</object>' in rendered
Beispiel #59
0
    def test_InlineInclude(self):
        # issue #28
        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Content of page2 is "{{page2}}".')

        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Single line')
        rendered = MoinWiki.create(u'page1')._render_data()
        assert '<p>Content of page2 is "<span class="moin-transclusion" data-href="/page2">Single line</span>".</p>' in rendered

        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Two\n\nParagraphs')
        rendered = MoinWiki.create(u'page1')._render_data()
        assert '<p>Content of page2 is "</p><div class="moin-transclusion" data-href="/page2"><p>Two</p><p>Paragraphs</p></div><p>".</p></div>' in rendered

        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"this text contains ''italic'' string")
        rendered = MoinWiki.create(u'page1')._render_data()
        assert 'Content of page2 is "<span class="moin-transclusion" data-href="/page2">this text contains <em>italic</em>' in rendered

        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Content of page2 is\n\n{{page2}}')
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"Single Line")
        rendered = MoinWiki.create(u'page1')._render_data()
        assert '<p>Content of page2 is</p><p><span class="moin-transclusion" data-href="/page2">Single Line</span></p>' in rendered

        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Content of page2 is "{{page2}}"')
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"|| table || cell ||")
        rendered = MoinWiki.create(u'page1')._render_data()
        assert 'Content of page2 is "</p>' in rendered
        assert '<table>' in rendered
        assert rendered.count('<table>') == 1

        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'Content of page2 is "{{page2}}"')
        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u"|| this || has ||\n|| two || rows ||")
        rendered = MoinWiki.create(u'page1')._render_data()
        assert 'Content of page2 is "</p>' in rendered
        assert '<table>' in rendered
        assert rendered.count('<table>') == 1
Beispiel #60
0
 def _publish_entry(self, entry, ptime, acl=None):
     meta = self.entry_meta.copy()
     meta[PTIME] = ptime
     if acl is not None:
         meta[ACL] = acl
     update_item(entry['name'], meta, entry['data'])