Example #1
0
    def testSTX(self):
        self.REQUEST['BODY'] = SIMPLE_STRUCTUREDTEXT
        d = Document('foo')
        d.PUT(self.REQUEST, self.RESPONSE)

        rnlinesplit = compile(r'\r?\n?')

        get_text = d.manage_FTPget()
        simple_lines = rnlinesplit.split(SIMPLE_STRUCTUREDTEXT)
        get_lines = rnlinesplit.split(get_text)

        # strip off headers
        simple_headers = []
        while simple_lines and simple_lines[0]:
            simple_headers.append(simple_lines[0])
            simple_lines = simple_lines[1:]

        get_headers = []
        while get_lines and get_lines[0]:
            get_headers.append(get_lines[0])
            get_lines = get_lines[1:]

        self.assertEqual(get_lines, simple_lines)

        for header in simple_headers:
            self.failUnless(header in get_headers)
Example #2
0
 def test_HtmlWithoutNewlines(self):
     REQUEST = fakeRequest()
     d = Document('foo')
     REQUEST['BODY'] = string.join(string.split(BASIC_HTML, '\n'), '')
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     assert d.Format() == 'text/html'
     assert d.Description() == 'Describe me'
Example #3
0
    def testSTX( self ):
        self.REQUEST['BODY']=SIMPLE_STRUCTUREDTEXT
        d = Document( 'foo' )
        d.PUT(self.REQUEST, self.RESPONSE)

        rnlinesplit = compile( r'\r?\n?' )

        get_text = d.manage_FTPget()
        simple_lines = rnlinesplit.split( SIMPLE_STRUCTUREDTEXT )
        get_lines = rnlinesplit.split( get_text )

        # strip off headers
        simple_headers = []
        while simple_lines and simple_lines[0]:
            simple_headers.append( simple_lines[0] )
            simple_lines = simple_lines[1:]

        get_headers = []
        while get_lines and get_lines[0]:
            get_headers.append( get_lines[0] )
            get_lines = get_lines[1:]

        self.assertEqual( get_lines, simple_lines )

        for header in simple_headers:
            self.failUnless( header in get_headers )
Example #4
0
 def test_deletePropagation(self):
    # import pdb; pdb.set_trace()
     portal_catalog = CatalogTool()
     self.root._setObject('portal_catalog', portal_catalog)
     catalog = self.root.portal_catalog
     portal_discussion = DiscussionTool()
     self.root._setObject('portal_discussion', portal_discussion)
     portal_url = URLTool()
     self.root._setObject('portal_url', portal_url)
     portal_workflow = WorkflowTool()
     self.root._setObject('portal_workflow', portal_workflow) 
     test = Document('test')
     self.root._setObject('test', test)
     test = self.root.test
     test.allow_discussion = 1
     assert len(catalog) == 1
     portal_discussion.createDiscussionFor(test)
     talkback = test.talkback
     talkback.createReply(title='test'
                          , text='blah'
                          )
     foo = talkback.getReplies()[0]
     assert len(catalog) == 2
     self.root._delObject('test')
     assert len(catalog) == 0
Example #5
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
Example #6
0
 def test_PutHtml(self):
     d = Document('foo')
     self._request.body = BASIC_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)
    def test_indexableContent_html(self):
        from Products.CMFCore.CatalogTool import IndexableObjectWrapper
        from Products.CMFDefault.Document import Document

        d = Document('foo', title='Foo', text_format='html',
                     text='foo content')
        d.setLanguage('en')
        try:
            w = IndexableObjectWrapper(ob=d, catalog=None)
        except TypeError:
            w = IndexableObjectWrapper({}, d) # BBB: for CMF < 2.2
        a = self._makeOne(w)

        icc = a.indexableContent(['Title', 'Description'])
        self.assertEqual(icc.getFields(), ['Description', 'Title'])
        self.assertEqual(icc.getFieldData('Title')[0],
                         {'content': u'Foo', 'language': 'en'})
        self.assertEqual(icc.getFieldData('Description')[0],
                         {'content': u'', 'language': 'en'})

        icc = a.indexableContent(['SearchableText'])
        self.assertEqual(icc.getFields(), ['SearchableText'])
        self.assertEqual(icc.getFieldData('SearchableText')[0],
                         {'content': u'Foo', 'language': 'en'})
        self.assertEqual(icc.getFieldData('SearchableText')[1],
                         {'content': u'', 'language': 'en'})
        self.assertEqual(icc.getFieldData('SearchableText')[2],
                         {'content': u'foo content', 'language': 'en'})
Example #8
0
    def test_StructuredText(self):
        d = Document('foo')
        assert hasattr(d, 'cooked_text')
        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
        assert string.find(d.CookedBody(), '<h1') >= 0

        # Make sure extra HTML is NOT found
        assert string.find(d.cooked_text, '<title>') == -1, d.cooked_text
        assert string.find(d.cooked_text, '<body>') == -1, d.cooked_text

        # test subject/keyword headers
        subj = list(d.Subject())
        assert len(subj) == 4
        subj.sort()
        assert subj == [
            'content management',
            'framework',
            'unit tests',
            'zope'
            ]
Example #9
0
 def edit( self, text, description=None, text_format=None ):
     """Edit the News Item.
     """
     if text_format is None:
         text_format = getattr(self, 'text_format', 'structured-text')
     if description is not None:
         self.setDescription( description )
     Document.edit( self, text_format, text )
Example #10
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
Example #11
0
 def edit(self, text, description=None, text_format=None):
     """Edit the News Item.
     """
     if text_format is None:
         text_format = getattr(self, 'text_format', 'structured-text')
     if description is not None:
         self.setDescription(description)
     Document.edit(self, text_format, text)
Example #12
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)
Example #13
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)
Example #14
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)
Example #15
0
 def __init__(self, id, title='', description='', text_format='', text=''):
     Document.__init__(self,
                       id,
                       title=title,
                       description=description,
                       text_format=text_format or self.text_format,
                       text=text)
     self.text_format = text_format or self.TEXT_FORMAT
Example #16
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
Example #17
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
Example #18
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
Example #19
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 )
Example #20
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
Example #21
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
Example #22
0
    def test_StructuredText(self):
        d = Document('foo')
        assert hasattr(d, 'cooked_text')
        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

        # Make sure extra HTML is NOT found
        assert string.find(d.cooked_text, '<title>') == -1, d.cooked_text
        assert string.find(d.cooked_text, '<body>') == -1, d.cooked_text

        # test subject/keyword headers
        subj = list(d.Subject())
        assert len(subj) == 4
        subj.sort()
        assert subj == [
            'content management',
            'framework',
            'unit tests',
            'zope'
            ]
 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)
 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)
Example #25
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
    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
Example #27
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)
Example #28
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)
     self.assertEqual( d.CookedBody(), body )
Example #29
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
 def testDocumentImplements(self):
     tool = self._makeOne()
     document = Document(id='foo')
     self.assertTrue(
         tool.objectImplements(document, getDottedName(IContentish)))
     self.assertTrue(
         tool.objectImplements(document, getDottedName(IDublinCore)))
Example #31
0
 def test_Empty(self):
     d = Document('foo')
     assert d.title == ''
     assert d.description == ''
     assert d.text == ''
     assert d.text_format == 'structured-text'
     assert d._stx_level == 1
Example #32
0
    def afterSetUp(self):
        super(TestHTMLImageCacheableFromContentBehaviorRegistration, self).\
                afterSetUp()
        self.context = Document('document')
        zope.interface.alsoProvides(self.context, IAttributeAnnotatable)
        self.behavior_assignable_factory = None

        # This will enable the behavior for our document.
        class BehaviorAssignable(object):
            zope.component.adapts(Document)
            zope.interface.implements(IBehaviorAssignable)

            def __init__(self, context):
                self.context = context

            def supports(self, behavior_interface):
                return behavior_interface is \
                        behaviors.IHTMLImageCacheableFromContent

            def enumerate_behaviors(self):
                i = behaviors.IHTMLImageCacheableFromContent
                yield zope.component.queryUtility(IBehavior,
                                                  name=i.__identifier__)

        zope.component.provideAdapter(BehaviorAssignable)
        self.behavior_assignable_factory = BehaviorAssignable
Example #33
0
 def test_Empty(self):
     d = Document('foo', text_format='structured-text')
     self.assertEqual(d.title, '')
     self.assertEqual(d.description, '')
     self.assertEqual(d.text, '')
     self.assertEqual(d.text_format, 'structured-text')
     self.assertEqual(d._stx_level, 1)
Example #34
0
    def test_itemCatloguing(self):

        self.root._setObject('test', Document('test'))
        test = self.root.test
        catalog = self.catalog_tool._catalog
        test.allow_discussion = 1
        assert len(self.catalog_tool) == 1
        assert has_path(catalog, test.getPhysicalPath())
        talkback = self.discussion_tool.getDiscussionFor(test)
        assert talkback.getPhysicalPath() == ( '', 'test', 'talkback' ), \
            talkback.getPhysicalPath()
        talkback.createReply(title='test', text='blah')
        assert len(self.catalog_tool) == 2
        for reply in talkback.getReplies():
            assert has_path(catalog, reply.getPhysicalPath())
            assert has_path(catalog, '/test/talkback/%s' % reply.getId())

        reply1 = talkback.getReplies()[0]
        talkback1 = self.discussion_tool.getDiscussionFor(reply1)
        talkback1.createReply(title='test2', text='blah2')
        for reply in talkback.getReplies():
            assert has_path(catalog, reply.getPhysicalPath())
            assert has_path(catalog, '/test/talkback/%s' % reply.getId())
        for reply in talkback1.getReplies():
            assert has_path(catalog, reply.getPhysicalPath())
            assert has_path(catalog, '/test/talkback/%s' % reply.getId())
Example #35
0
    def testHTML( self ):
        REQUEST=fakeRequest()
        REQUEST['BODY']=SIMPLE_HTML
        d = Document( 'foo' )
        d.PUT(REQUEST, RESPONSE=fakeResponse())

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

        # 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:]

        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 )
Example #36
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
Example #37
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 )
 def __init__(self,
             id, 
             title='',
             position='',
             topic='',
             description='',
             source='',
             url='',
             text='',
     		text_format='',
     ):
     """ Instanciates an Article """
     Document.__init__(self, id, title, description, text_format, text)
     self.position = position
     self.topic = topic
     self.source = source
     self.url = string.split(url,'\n')
Example #39
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]
 def edit(self,   
         title='',
         position='',
         topic='',
         description='',
         source='',
         url='',
         text='',
         text_format='',
         file='',
         ):
     """ Edit article properties """     
     Document.edit(self, text_format, text, file)
     self.editMetadata(title=title, description=description)
     self.position=position
     self.topic=topic
     self.source = source
     self.url = string.split(url,'\n')
Example #41
0
 def _edit(self, text_format, text, file='', safety_belt=''):
     got = Document._edit(self,
                          text_format or self.text_format,
                          text=text,
                          file=file,
                          safety_belt=safety_belt)
     # The document stubbornly insists on a text format it likes, despite
     # our explicit specification - set it back:
     self.text_format = text_format or self.TEXT_FORMAT
Example #42
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)
Example #43
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
Example #44
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
    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
Example #46
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()
Example #47
0
 def handleText(self, text, format=None, stx_level=None):
     """Handle the raw text, returning headers, body, cooked, format"""
     if not format:
         format = self.guessFormat(text)
     if format != self.TEXT_FORMAT:
         return Document.handleText(self, text, format=format,
                                    stx_level=stx_level or self._stx_level)
     else:
         body = text
         cooked = util.format_webtext(body)
         headers = {}
         return headers, body, cooked, format
Example #48
0
class TestDocumentPUT(RequestTest):

    def setUp(self):
        RequestTest.setUp(self)
        self.d = Document('foo')

    def test_PutStructuredTextWithHTML(self):
            
        self.REQUEST['BODY'] = STX_WITH_HTML

        r = self.d.PUT(self.REQUEST, self.RESPONSE)
        self.assertEqual( self.d.Format(), 'text/plain' )
        self.assertEqual( r.status, 204 )

    def test_PutStructuredText(self):

        self.REQUEST['BODY'] = BASIC_STRUCTUREDTEXT

        r = self.d.PUT(self.REQUEST, self.RESPONSE)
        self.assertEqual( self.d.Format(), 'text/plain' )
        self.assertEqual( r.status, 204 )

    def test_PutHtmlWithDoctype(self):
        
        html = '%s\n\n  \n   %s' % (DOCTYPE, BASIC_HTML)
        self.REQUEST['BODY'] = html
        
        r = self.d.PUT(self.REQUEST, self.RESPONSE)
        self.assertEqual( self.d.Format(), 'text/html' )
        self.assertEqual( self.d.Description(), 'Describe me' )
        self.assertEqual( r.status, 204 )

    def test_PutHtml(self):
        
        self.REQUEST['BODY'] = BASIC_HTML
        r = self.d.PUT(self.REQUEST, self.RESPONSE)
        self.assertEqual( self.d.Format(), 'text/html' )
        self.assertEqual( self.d.Description(), 'Describe me' )
        self.assertEqual( r.status, 204 )
Example #49
0
 def guessFormat(self, text):
     """Infer inner document content type."""
     # Respect the registered text_format, if we can, else sniff.
     if string.lower(self.text_format) == self.TEXT_FORMAT:
         return self.TEXT_FORMAT
     elif string.lower(self.text_format) == 'html':
         return 'text/html'
     elif string.lower(self.text_format) in [
             'stx', 'structuredtext', 'structured-text', 'structured_text'
     ]:
         return 'structured-text'
     else:
         return Document.guessFormat(self, text)
Example #50
0
 def guessFormat(self, text):
     """Infer inner document content type."""
     # Respect the registered text_format, if we can, else sniff.
     if string.lower(self.text_format) == self.TEXT_FORMAT:
         return self.TEXT_FORMAT
     elif string.lower(self.text_format) == 'html':
         return 'text/html'
     elif string.lower(self.text_format) in ['stx', 'structuredtext',
                                             'structured-text',
                                             'structured_text']:
         return 'structured-text'
     else:
         return Document.guessFormat(self, text)
Example #51
0
    def test_STX_Levels(self):
        d = Document('foo')
        d.edit(text_format='structured-text', 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
Example #52
0
    def test_STX_Levels(self):
        d = Document('foo')
        d.edit(text_format='structured-text', text=BASIC_STRUCTUREDTEXT)
        self.assertEqual( d._stx_level, 1 )

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

        ct = d.CookedBody(stx_level=2)
        self.failIf( (string.find(ct, '<h1') >= 0) )
        self.failUnless( string.find(ct, '<h2') >= 0 )
        self.assertEqual( d._stx_level, 1 )

        ct = d.CookedBody(stx_level=2, setlevel=1)
        self.failIf( (string.find(ct, '<h1') >= 0) )
        self.failUnless( string.find(ct, '<h2') >= 0 )
        self.assertEqual( d._stx_level, 2 )

        ct = d.CookedBody()
        self.assertEqual( d._stx_level, 2 )
        self.failIf( (string.find(d.CookedBody(), '<h1') >= 0) )
        self.failUnless( string.find(d.CookedBody(), '<h2') >= 0 )
Example #53
0
    def test_STX_NoHeaders( self ):
        REQUEST=fakeRequest()
        REQUEST['BODY']=STX_NO_HEADERS
        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.PUT(REQUEST, RESPONSE=fakeResponse())
        
        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()
Example #54
0
    def test_STX_NoHeaders( self ):
        REQUEST=fakeRequest()
        REQUEST['BODY']=STX_NO_HEADERS
        d = Document('foo')
        d.editMetadata( title="Plain STX"
                       , description="Look, Ma, no headers!"
                       , subject=( "plain", "STX" )
                       )
        self.assertEqual( d.Format(), 'text/html' )
        self.assertEqual( d.Title(), 'Plain STX' )
        self.assertEqual( d.Description(), 'Look, Ma, no headers!' )
        self.assertEqual( len( d.Subject() ), 2 )
        self.failUnless( 'plain' in d.Subject() )
        self.failUnless( 'STX' in d.Subject() )

        d.PUT(REQUEST, RESPONSE=fakeResponse())
        
        self.assertEqual( d.Format(), 'text/plain' )
        self.assertEqual( d.Title(), 'Plain STX' )
        self.assertEqual( d.Description(), 'Look, Ma, no headers!' )
        self.assertEqual( len( d.Subject() ), 2 )
        self.failUnless( 'plain' in d.Subject() )
        self.failUnless( 'STX' in d.Subject() )
Example #55
0
    def testSTX( self ):
        REQUEST=fakeRequest()
        REQUEST['BODY']=SIMPLE_STRUCTUREDTEXT
        d = Document( 'foo' )
        d.PUT(REQUEST, RESPONSE=fakeResponse())

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

        # strip off headers
        simple_headers = []
        while simple_lines and simple_lines[0]:
            simple_headers.append( simple_lines[0] )
            simple_lines = simple_lines[1:]

        get_headers = []
        while get_lines and get_lines[0]:
            get_headers.append( get_lines[0] )
            get_lines = get_lines[1:]

        assert get_lines == simple_lines

        for header in simple_headers:
            assert header in get_headers, [header, get_headers]
Example #56
0
 def test_EditStructuredTextWithHTML(self):
     d = Document('foo')
     d.edit(text_format='structured-text', text=STX_WITH_HTML)
     
     self.assertEqual( d.Format(), 'text/plain' )
Example #57
0
 def test_EntityInTitle(self):
     d = Document('foo')
     d.edit(text_format='html', text=ENTITY_IN_TITLE)
     assert d.title == '&Auuml;rger', "Title '%s' being lost" % (
         d.title )
Example #58
0
 def test_HtmlWithDoctype(self):
     d = Document('foo')
     html = '%s\n%s' % (DOCTYPE, BASIC_HTML)
     d.edit(text_format='', text=html)
     assert d.Description() == 'Describe me'
Example #59
0
 def test_EditStructuredTextWithHTML(self):
     d = Document('foo')
     d.edit(text_format=None, text=STX_WITH_HTML)
     
     assert d.Format() == 'text/plain', "%s != %s" % (
         d.Format(), 'text/plain')
Example #60
0
 def test_HtmlWithoutNewlines(self):
     d = Document('foo')
     html = string.join(string.split(BASIC_HTML, '\n'), '')
     d.edit(text_format='', text=html)
     assert d.Format() == 'text/html'
     assert d.Description() == 'Describe me'