Ejemplo n.º 1
0
    def test_BasicHtmlPUT(self):
        REQUEST = fakeRequest()
        REQUEST['BODY'] = 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 )
        self.assertEqual( 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)
        self.assertEqual( d._stx_level, 1 )

        subj = list(d.Subject())
        self.assertEqual( len(subj), 4 )
        subj.sort()
        self.assertEqual( subj, [ 'content management'
                                , 'framework'
                                , 'unit tests'
                                , 'zope'
                                ] )
Ejemplo n.º 2
0
    def testSTX( self ):
        REQUEST=fakeRequest()
        REQUEST['BODY']=SIMPLE_STRUCTUREDTEXT
        d = Document( 'foo' )
        d.PUT(REQUEST, RESPONSE=fakeResponse())

        rnlinesplit = re.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 )
Ejemplo n.º 3
0
 def test_HtmlWithoutNewlines(self):
     REQUEST=fakeRequest()
     d = Document('foo')
     REQUEST['BODY'] = string.join(string.split(BASIC_HTML, '\n'), '')
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     self.assertEqual( d.Format(), 'text/html' )
     self.assertEqual( d.Description(), 'Describe me' )
Ejemplo n.º 4
0
    def test_Init(self):
        REQUEST=fakeRequest()
        REQUEST['BODY']=BASIC_STRUCTUREDTEXT
        d = Document('foo')
        d.PUT(REQUEST, RESPONSE=fakeResponse())
        self.assertEqual( d.Format(), 'text/plain' )
        self.assertEqual( d.Title(), 'My Document' )
        self.assertEqual( d.Description(), 'A document by me' )
        self.assertEqual( len(d.Contributors()), 3 )
        self.failUnless( string.find(d.cooked_text, '<p>') >= 0 )

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

        d = Document('foo', text_format='structured-text', title='Foodoc')
        self.assertEqual( d.text, '' )
        self.failIf( d.CookedBody() )
        self.assertEqual( d.title, 'Foodoc' )
        self.assertEqual( d.Format(), 'text/plain' )

        # Tracker issue 435:  initial text is not cooked.
        d = Document('foo', text_format='structured-text', text=STX_NO_HEADERS)
        self.assertEqual( d.EditableBody(), STX_NO_HEADERS )
        self.failUnless( d.CookedBody() )
        self.assertEqual( d.Format(), 'text/plain' )
Ejemplo n.º 5
0
    def test_StructuredText(self):
        REQUEST=fakeRequest()
        REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
        d = Document('foo')
        d.PUT(REQUEST, RESPONSE=fakeResponse())
        self.failUnless( hasattr(d, 'cooked_text') )
        self.assertEqual( d.Format(), 'text/plain' )
        self.assertEqual( d.Title(), 'My Document' )
        self.assertEqual( d.Description(), 'A document by me' )
        self.assertEqual( len(d.Contributors()), 3 )
        self.failUnless( string.find(d.cooked_text, '<p>') >= 0 )
        self.failUnless( string.find(d.CookedBody(), '<h1') >= 0 )

        # Make sure extra HTML is NOT found
        self.failUnless( string.find(d.cooked_text, '<title>') < 0 )
        self.failUnless( string.find(d.cooked_text, '<body>') < 0 )

        # test subject/keyword headers
        subj = list(d.Subject())
        self.assertEqual( len(subj), 4 )
        subj.sort()
        self.assertEqual( subj, [ 'content management'
                                , 'framework'
                                , 'unit tests'
                                , 'zope'
                                ] )
Ejemplo n.º 6
0
    def test_Init(self):
        REQUEST = fakeRequest()
        REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
        d = Document('foo')
        d.PUT(REQUEST, RESPONSE=fakeResponse())
        self.assertEqual(d.Format(), 'text/plain')
        self.assertEqual(d.Title(), 'My Document')
        self.assertEqual(d.Description(), 'A document by me')
        self.assertEqual(len(d.Contributors()), 3)
        self.failUnless(string.find(d.cooked_text, '<p>') >= 0)

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

        d = Document('foo', text_format='structured-text', title='Foodoc')
        self.assertEqual(d.text, '')
        self.failIf(d.CookedBody())
        self.assertEqual(d.title, 'Foodoc')
        self.assertEqual(d.Format(), 'text/plain')

        # Tracker issue 435:  initial text is not cooked.
        d = Document('foo', text_format='structured-text', text=STX_NO_HEADERS)
        self.assertEqual(d.EditableBody(), STX_NO_HEADERS)
        self.failUnless(d.CookedBody())
        self.assertEqual(d.Format(), 'text/plain')
Ejemplo n.º 7
0
    def testSTX(self):
        REQUEST = fakeRequest()
        REQUEST['BODY'] = SIMPLE_STRUCTUREDTEXT
        d = Document('foo')
        d.PUT(REQUEST, RESPONSE=fakeResponse())

        rnlinesplit = re.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)
Ejemplo n.º 8
0
 def test_HtmlWithoutNewlines(self):
     REQUEST = fakeRequest()
     d = Document('foo')
     REQUEST['BODY'] = string.join(string.split(BASIC_HTML, '\n'), '')
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     self.assertEqual(d.Format(), 'text/html')
     self.assertEqual(d.Description(), 'Describe me')
Ejemplo n.º 9
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)
Ejemplo n.º 10
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 )
Ejemplo n.º 11
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())
     self.assertEqual( d.CookedBody(), body )
Ejemplo n.º 12
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())
     self.assertEqual(d.CookedBody(), body)
Ejemplo n.º 13
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 )
Ejemplo n.º 14
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)
Ejemplo n.º 15
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())
Ejemplo n.º 16
0
    def test_StructuredText(self):
        REQUEST = fakeRequest()
        REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
        d = Document('foo')
        d.PUT(REQUEST, RESPONSE=fakeResponse())
        self.failUnless(hasattr(d, 'cooked_text'))
        self.assertEqual(d.Format(), 'text/plain')
        self.assertEqual(d.Title(), 'My Document')
        self.assertEqual(d.Description(), 'A document by me')
        self.assertEqual(len(d.Contributors()), 3)
        self.failUnless(string.find(d.cooked_text, '<p>') >= 0)
        self.failUnless(string.find(d.CookedBody(), '<h1') >= 0)

        # Make sure extra HTML is NOT found
        self.failUnless(string.find(d.cooked_text, '<title>') < 0)
        self.failUnless(string.find(d.cooked_text, '<body>') < 0)

        # test subject/keyword headers
        subj = list(d.Subject())
        self.assertEqual(len(subj), 4)
        subj.sort()
        self.assertEqual(
            subj, ['content management', 'framework', 'unit tests', 'zope'])
Ejemplo n.º 17
0
    def test_BasicHtmlPUT(self):
        REQUEST = fakeRequest()
        REQUEST['BODY'] = 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)
        self.assertEqual(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)
        self.assertEqual(d._stx_level, 1)

        subj = list(d.Subject())
        self.assertEqual(len(subj), 4)
        subj.sort()
        self.assertEqual(
            subj, ['content management', 'framework', 'unit tests', 'zope'])
Ejemplo n.º 18
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() )
Ejemplo n.º 19
0
 def test_EntityInTitle(self):
     REQUEST = fakeRequest()
     REQUEST['BODY'] = ENTITY_IN_TITLE
     d = Document('foo')
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     self.assertEqual(d.title, '&Auuml;rger')
Ejemplo n.º 20
0
 def test_HtmlWithDoctype(self):
     REQUEST = fakeRequest()
     d = Document('foo')
     REQUEST['BODY'] = '%s\n%s' % (DOCTYPE, BASIC_HTML)
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     self.assertEqual(d.Description(), 'Describe me')
Ejemplo n.º 21
0
 def test_EntityInTitle(self):
     REQUEST=fakeRequest()
     REQUEST['BODY'] = ENTITY_IN_TITLE 
     d = Document('foo')
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     self.assertEqual( d.title, '&Auuml;rger' )
Ejemplo n.º 22
0
 def test_HtmlWithDoctype(self):
     REQUEST=fakeRequest()
     d = Document('foo')
     REQUEST['BODY'] = '%s\n%s' % (DOCTYPE, BASIC_HTML)
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     self.assertEqual( d.Description(), 'Describe me' )