Beispiel #1
0
 def test_PutHtmlWithDoctype(self):
     d = Document('foo')
     html = '%s\n\n  \n   %s' % (DOCTYPE, BASIC_HTML)
     self._request.body = html
     r = d.PUT(self._request, self._response)
     self.assertEqual(d.Format(), 'text/html')
     self.assertEqual(d.Description(), 'Describe me')
     self.assertEqual(r.status, 204)
Beispiel #2
0
 def test_UpperedHtml(self):
     d = Document('foo')
     d.edit(text_format='', text=string.upper(BASIC_HTML))
     assert d.Format() == 'text/html'
     assert d.title == 'TITLE IN TAG'
     assert string.find(d.text, '</BODY') == -1
     assert d.Description() == 'DESCRIBE ME'
     assert len(d.Contributors()) == 3
Beispiel #3
0
    def test_PutStructuredText(self):
        d = Document('foo')

        self._request.body = BASIC_STRUCTUREDTEXT

        r = d.PUT(self._request, self._response)
        self.assertEqual(d.Format(), 'text/plain')
        self.assertEqual(r.status, 204)
Beispiel #4
0
    def test_PutStructuredTextWithHTML(self):
        d = Document('foo')

        self._request.body = STX_WITH_HTML

        r = d.PUT(self._request, self._response)
        self.assertEqual(d.Format(), 'text/plain')
        self.assertEqual(r.status, 204)
Beispiel #5
0
 def test_PutHtml(self):
     d = Document('foo')
     self._request.body = BASIC_HTML
     r = d.PUT(self._request, self._response)
     assert d.Format() == 'text/html', "%s != %s" % (d.Format(),
                                                     'text/html')
     assert d.Description() == 'Describe me'
     assert r.status == 204
Beispiel #6
0
    def test_STX_NoHeaders_but_colon(self):
        d = Document('foo')
        d.editMetadata(title="Plain STX",
                       description="Look, Ma, no headers!",
                       subject=("plain", "STX"))

        d.edit(text_format='structured-text', text=STX_NO_HEADERS_BUT_COLON)
        self.assertEqual(d.EditableBody(), STX_NO_HEADERS_BUT_COLON)
Beispiel #7
0
    def test_Init(self):
        d = Document('foo', text=BASIC_STRUCTUREDTEXT)
        assert d.Format() == 'text/plain'
        assert d.Title() == 'My Document'
        assert d.Description() == 'A document by me'
        assert len(d.Contributors()) == 3
        assert string.find(d.cooked_text, '<p>') >= 0

        d = Document('foo', text=BASIC_HTML)
        assert d.Format() == 'text/html'
        assert d.Title() == 'Title in tag'
        assert len(d.Contributors()) == 2

        d = Document('foo', title='Foodoc')
        assert d.text == ''
        assert d.title == 'Foodoc'
        assert d.Format() == 'text/plain'
Beispiel #8
0
    def test_StructuredText(self):
        d = Document('foo')
        d.edit(text_format='structured-text', text=BASIC_STRUCTUREDTEXT)

        assert d.Format() == 'text/plain'
        assert d.Title() == 'My Document'
        assert d.Description() == 'A document by me'
        assert len(d.Contributors()) == 3
        assert string.find(d.cooked_text, '<p>') >= 0
Beispiel #9
0
    def test_PutStructuredTextWithHTML(self):
        d = Document('foo')

        self._request.body = STX_WITH_HTML

        r = d.PUT(self._request, self._response)
        assert d.Format() == 'text/plain', "%s != %s" % (d.Format(),
                                                         'text/plain')
        assert r.status == 204
Beispiel #10
0
 def test_PutHtmlWithDoctype(self):
     d = Document('foo')
     html = '%s\n\n  \n   %s' % (DOCTYPE, BASIC_HTML)
     self._request.body = html
     r = d.PUT(self._request, self._response)
     assert d.Format() == 'text/html', "%s != %s" % (d.Format(),
                                                     'text/html')
     assert d.Description() == 'Describe me'
     assert r.status == 204
Beispiel #11
0
    def test_PutStructuredText(self):
        d = Document('foo')

        self._request.body = BASIC_STRUCTUREDTEXT

        r = d.PUT(self._request, self._response)
        assert d.Format() == 'text/plain', '%s != %s' % (d.Format(),
                                                         'text/plain')
        assert r.status == 204
Beispiel #12
0
 def test_BigHtml(self):
     d = Document('foo')
     s = []
     looper = '<li> number %s</li>'
     for i in range(12000):
         s.append(looper % i)
     body = '<ul>\n%s\n</ul>' % string.join(s, '\n')
     html = HTML_TEMPLATE % {'title': 'big document', 'body': body}
     d.edit(text_format=None, text=html)
     assert d.CookedBody() == body
Beispiel #13
0
 def test_UpperedHtml(self):
     REQUEST = fakeRequest()
     REQUEST['BODY'] = string.upper(BASIC_HTML)
     d = Document('foo')
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     self.assertEqual(d.Format(), 'text/html')
     self.assertEqual(d.title, 'TITLE IN TAG')
     self.assertEqual(string.find(d.text, '</BODY'), -1)
     self.assertEqual(d.Description(), 'DESCRIBE ME')
     self.assertEqual(len(d.Contributors()), 3)
Beispiel #14
0
 def test_UpperedHtml(self):
     REQUEST = fakeRequest()
     REQUEST['BODY'] = string.upper(BASIC_HTML)
     d = Document('foo')
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     assert d.Format() == 'text/html'
     assert d.title == 'TITLE IN TAG'
     assert string.find(d.text, '</BODY') == -1
     assert d.Description() == 'DESCRIBE ME'
     assert len(d.Contributors()) == 3
Beispiel #15
0
    def test_deletePropagation(self):

        self.root._setObject('test', Document('test'))
        test = self.root.test

        test.allow_discussion = 1
        talkback = self.discussion_tool.getDiscussionFor(test)
        talkback.createReply(title='test', text='blah')
        self.root._delObject('test')
        assert len(self.catalog_tool) == 0
Beispiel #16
0
 def test_BigHtml_via_upload(self):
     d = Document('foo')
     s = []
     looper = '<li> number %s</li>'
     for i in range(12000):
         s.append(looper % i)
     body = '<ul>\n%s\n</ul>' % string.join(s, '\n')
     html = HTML_TEMPLATE % {'title': 'big document', 'body': body}
     from StringIO import StringIO
     file = StringIO(html)
     d.edit(text_format='html', text='', file=file)
     assert d.CookedBody() == body
Beispiel #17
0
 def setUp(self):
     self.portal = self.layer['portal']
     setRoles(self.portal, TEST_USER_ID, ['Manager'])
     self.portal.invokeFactory('Folder', 'target')
     self.portal.invokeFactory('Folder', 'folder')
     self.folder = self.portal['folder']
     self.folder.invokeFactory('Document', 'd1')
     self.folder.d1.setEffectiveDate(DateTime('2009/04/22'))
     self.folder.invokeFactory('Folder', 'relativeTarget')
     o = Document('cmf', 'CMF Content', '', '', '')
     o.setEffectiveDate(DateTime('2009/04/22'))
     self.folder._setObject('cmf', o, suppress_events=True)
Beispiel #18
0
    def test_Init(self):
        REQUEST = fakeRequest()
        REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
        d = Document('foo')
        d.PUT(REQUEST, RESPONSE=fakeResponse())
        assert d.Format() == 'text/plain'
        assert d.Title() == 'My Document'
        assert d.Description() == 'A document by me'
        assert len(d.Contributors()) == 3
        assert string.find(d.cooked_text, '<p>') >= 0

        d = Document('foo', text='')
        REQUEST['BODY'] = BASIC_HTML
        d.PUT(REQUEST, RESPONSE=fakeResponse())
        assert d.Format() == 'text/html'
        assert d.Title() == 'Title in tag'
        assert len(d.Contributors()) == 3

        d = Document('foo', text_format='structured-text', title='Foodoc')
        assert d.text == ''
        assert d.title == 'Foodoc'
        assert d.Format() == 'text/plain'
Beispiel #19
0
 def test_BigHtml(self):
     REQUEST = fakeRequest()
     d = Document('foo')
     s = []
     looper = '<li> number %s</li>'
     for i in range(12000):
         s.append(looper % i)
     body = '<ul>\n%s\n</ul>' % string.join(s, '\n')
     REQUEST['BODY'] = HTML_TEMPLATE % {
         'title': 'big document',
         'body': body
     }
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     assert d.CookedBody() == body
Beispiel #20
0
    def __call__(self, id, title=None, *args, **kw):
        item = super(_HomeFolderFactory, self).__call__(id,
                                                        title=title,
                                                        *args,
                                                        **kw)

        # Create Member's initial content
        subitem = Document('index_html', "{0}'s Home".format(id),
                           "{0}'s front page".format(id), 'structured-text',
                           DEFAULT_MEMBER_CONTENT % id)
        subitem.manage_setLocalRoles(id, ['Owner'])
        subitem._setPortalTypeName('Document')
        item._setObject('index_html', subitem, suppress_events=True)
        return item
Beispiel #21
0
    def test_nestedReplies( self ):
        self.root._setObject( 'test', Document( 'test' ) )
        test = self.root.test
        test.allow_discussion = 1
        talkback = self.discussion_tool.getDiscussionFor( test )
        assert talkback._getDiscussable() == test
        assert talkback._getDiscussable( outer=1 ) == test
        assert not talkback.hasReplies( test )
        assert len( talkback.getReplies() ) == 0

        talkback.createReply( title='test'
                            , text='blah'
                            )
        assert talkback.hasReplies( test )
        assert len( talkback.getReplies() ) == 1

        reply1 = talkback.getReplies()[0]
        items = talkback._container.items()
        assert items[0][0] == reply1.getId()
        assert reply1.inReplyTo() == test

        parents = reply1.parentsInThread()
        assert len( parents ) == 1
        assert test in parents

        talkback1 = self.discussion_tool.getDiscussionFor( reply1 )
        assert talkback == talkback1
        assert len( talkback1.getReplies() ) == 0
        assert len( talkback.getReplies() ) == 1

        talkback1.createReply( title='test2'
                             , text='blah2'
                             )
        assert len( talkback._container ) == 2
        assert talkback1.hasReplies( reply1 )
        assert len( talkback1.getReplies() ) == 1
        assert len( talkback.getReplies() ) == 1

        reply2 = talkback1.getReplies()[0]
        assert reply2.inReplyTo() == reply1

        parents = reply2.parentsInThread()
        assert len( parents ) == 2
        assert parents[ 0 ] == test
        assert parents[ 1 ] == reply1

        parents = reply2.parentsInThread( 1 )
        assert len( parents ) == 1
        assert parents[ 0 ] == reply1
Beispiel #22
0
    def test_BasicHtml(self):
        d = Document('foo', text=BASIC_HTML)
        assert d.Format() == 'text/html'
        assert d.title == 'Title in tag'
        assert string.find(d.text, '</body>') == -1
        assert d.Description() == 'Describe me'
        assert len(d.Contributors()) == 2

        subj = list(d.Subject())
        assert len(subj) == 4
        subj.sort()
        assert subj == [
            'content management',
            'framework',
            'unit tests',
            'zope'
            ]
Beispiel #23
0
    def testHTML( self ):
        self.REQUEST['BODY']=BASIC_HTML
        d = Document( 'foo' )
        d.PUT(self.REQUEST, self.RESPONSE)

        rnlinesplit = compile( r'\r?\n?' )
        simple_lines = rnlinesplit.split( BASIC_HTML )
        get_lines = rnlinesplit.split( d.manage_FTPget() )

        # strip off headers
        meta_pattern = compile( r'meta name="([a-z]*)" '
                                 + r'content="([a-z]*)"'
                                 )
        title_pattern = compile( r'<title>(.*)</title>' )
        simple_headers = []
        while simple_lines and simple_lines[0] != '<BODY>':
            header = simple_lines[0].strip().lower() 
            match = meta_pattern.search( header )
            if match:
                simple_headers.append( match.groups() )
            else:
                match = title_pattern.search( header )
                if match:
                    simple_headers.append( ( 'title', match.group(1) ) )
            simple_lines = simple_lines[1:]

        get_headers = []
        while get_lines and get_lines[0] != '<BODY>':
            header = get_lines[0].strip().lower()
            match = meta_pattern.search( header )
            if match:
                get_headers.append( match.groups() )
            else:
                match = title_pattern.search( header )
                if match:
                    get_headers.append( ( 'title', match.group(1) ) )
            get_lines = get_lines[1:]

        self.assertEqual( get_lines, simple_lines )

        self.failUnless( get_headers )
        self.failUnless( simple_headers )
        self.failUnless( len( get_headers ) >= len( simple_headers ) )

        for header in simple_headers:
            self.failUnless( header in get_headers )
Beispiel #24
0
    def testHTML(self):
        REQUEST = fakeRequest()
        REQUEST['BODY'] = SIMPLE_HTML
        d = Document('foo')
        d.PUT(REQUEST, RESPONSE=fakeResponse())

        simple_lines = string.split(SIMPLE_HTML, '\n')
        get_lines = string.split(d.manage_FTPget(), '\n')

        # strip off headers
        meta_pattern = re.compile(r'meta name="([a-z]*)" ' +
                                  r'content="([a-z]*)"')
        title_pattern = re.compile(r'<title>(.*)</title>')
        simple_headers = []
        while simple_lines and simple_lines[0] != '<BODY>':
            header = string.lower(string.strip(simple_lines[0]))
            match = meta_pattern.search(header)
            if match:
                simple_headers.append(match.groups())
            else:
                match = title_pattern.search(header)
                if match:
                    simple_headers.append(('title', match.group(1)))
            simple_lines = simple_lines[1:]

        get_headers = []
        while get_lines and get_lines[0] != '<BODY>':
            header = string.lower(string.strip(get_lines[0]))
            match = meta_pattern.search(header)
            if match:
                get_headers.append(match.groups())
            else:
                match = title_pattern.search(header)
                if match:
                    get_headers.append(('title', match.group(1)))
            get_lines = get_lines[1:]

        assert get_lines == simple_lines

        assert get_headers
        assert simple_headers
        assert len(get_headers) >= len(simple_headers)

        for header in simple_headers:
            assert header in get_headers, [header, get_headers]
Beispiel #25
0
    def test_policy( self ):

        self.root._setObject( 'test', Document( 'test' ) )
        test = self.root.test
        self.assertRaises( DiscussionNotAllowed
                         , self.discussion_tool.getDiscussionFor
                         , test
                         )
        assert getattr( test, 'talkback', None ) is None

        test.allow_discussion = 1
        assert self.discussion_tool.getDiscussionFor( test )
        assert test.talkback

        del test.talkback
        del test.allow_discussion
        FTI = FactoryTypeInformation
        self.types_tool._setObject( 'Document'
                                  , FTI( 'Document'
                                       , meta_type=Document.meta_type
                                       , product='CMFDefault'
                                       , factory='addDocument'
                                       )
                                  )
        self.assertRaises( DiscussionNotAllowed
                         , self.discussion_tool.getDiscussionFor
                         , test
                         )
        assert getattr( test, 'talkback', None ) is None

        self.types_tool.Document.allow_discussion = 1
        assert self.discussion_tool.getDiscussionFor( test )
        assert test.talkback

        del test.talkback
        self.types_tool.Document.allow_discussion = 0
        self.assertRaises( DiscussionNotAllowed
                         , self.discussion_tool.getDiscussionFor
                         , test
                         )
        assert getattr( test, 'talkback', None ) is None

        test.allow_discussion = 1
        assert self.discussion_tool.getDiscussionFor( test )
        assert test.talkback
Beispiel #26
0
 def setUp( self ):
     
     SecurityTest.setUp(self)
     
     root = self.root
     root._setObject( 'portal_discussion', DiscussionTool() )
     self.discussion_tool = root.portal_discussion
     root._setObject( 'portal_catalog', CatalogTool() )
     self.catalog_tool = root.portal_catalog
     root._setObject( 'portal_url', URLTool() )
     self.url_tool = root.portal_url
     root._setObject( 'portal_workflow', WorkflowTool() ) 
     self.workflow_tool = root.portal_workflow
     root._setObject( 'portal_types', TypesTool() )
     types_tool = self.types_tool = root.portal_types
     try: root._delObject('test')
     except AttributeError: pass
     root._setObject( 'test', Document( 'test' ) )
Beispiel #27
0
    def test_BasicHtml(self):
        d = Document('foo', text=BASIC_HTML)
        assert d.Format() == 'text/html'
        assert d.title == 'Title in tag'
        assert string.find(d.text, '</body>') == -1
        assert d.Description() == 'Describe me'
        assert len(d.Contributors()) == 3
        assert d.Contributors()[-1] == 'Benotz, Larry J ([email protected])'

        # Since the format is html, the STX level operands should
        # have no effect.
        ct = d.CookedBody(stx_level=3, setlevel=1)
        assert d._stx_level == 1

        subj = list(d.Subject())
        assert len(subj) == 4
        subj.sort()
        assert subj == [
            'content management', 'framework', 'unit tests', 'zope'
        ]
Beispiel #28
0
    def test_STX_NoHeaders(self):
        d = Document('foo')
        d._editMetadata(title="Plain STX",
                        description="Look, Ma, no headers!",
                        subject=("plain", "STX"))
        assert d.Format() == 'text/html'
        assert d.Title() == 'Plain STX'
        assert d.Description() == 'Look, Ma, no headers!'
        assert len(d.Subject()) == 2
        assert 'plain' in d.Subject()
        assert 'STX' in d.Subject()

        d.edit(text_format='structured-text', text=STX_NO_HEADERS)

        assert d.Format() == 'text/plain'
        assert d.Title() == 'Plain STX'
        assert d.Description() == 'Look, Ma, no headers!'
        assert len(d.Subject()) == 2
        assert 'plain' in d.Subject()
        assert 'STX' in d.Subject()
Beispiel #29
0
    def __call__(self, id, title=None, *args, **kw):
        item = super(_BBBHomeFolderFactory, self).__call__(id,
                                                           title=title,
                                                           *args,
                                                           **kw)

        # Create Member's initial content
        mtool = getUtility(IBaseTool)
        if hasattr(mtool, 'createMemberContent'):
            wrapped = item.__of__(mtool.getMembersFolder())
            mtool.createMemberContent(member=mtool.getMemberById(id),
                                      member_id=id,
                                      member_folder=wrapped)
        else:
            subitem = Document('index_html', "{0}'s Home".format(id),
                               "{0}'s front page".format(id),
                               'structured-text', DEFAULT_MEMBER_CONTENT % id)
            subitem.manage_setLocalRoles(id, ['Owner'])
            subitem._setPortalTypeName('Document')
            item._setObject('index_html', subitem, suppress_events=True)
        return item
Beispiel #30
0
    def test_STX_Levels(self):
        d = Document('foo', text=BASIC_STRUCTUREDTEXT)
        assert d._stx_level == 1

        ct = d.CookedBody()
        assert string.find(d.CookedBody(), '<h1') >= 0
        assert d._stx_level == 1

        ct = d.CookedBody(stx_level=2)
        assert not (string.find(ct, '<h1') >= 0)
        assert string.find(ct, '<h2') >= 0
        assert d._stx_level == 1

        ct = d.CookedBody(stx_level=2, setlevel=1)
        assert not (string.find(ct, '<h1') >= 0)
        assert string.find(ct, '<h2') >= 0
        assert d._stx_level == 2

        ct = d.CookedBody()
        assert d._stx_level == 2
        assert not (string.find(d.CookedBody(), '<h1') >= 0)
        assert string.find(d.CookedBody(), '<h2') >= 0