Ejemplo n.º 1
0
    def test_BasicHtmlPUT(self):
        REQUEST = fakeRequest()
        REQUEST['BODY'] = 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
        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'
            ]
Ejemplo n.º 2
0
 def test_HtmlWithoutNewlines(self):
     REQUEST = fakeRequest()
     d = NewsItem('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'
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())
     assert d.Format() == 'text/html'
     assert d.Description() == 'Describe me'
Ejemplo n.º 4
0
    def test_StructuredText(self):
        REQUEST=fakeRequest()
        REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
        d = Document('foo')
        d.PUT(REQUEST, RESPONSE=fakeResponse())
        assert hasattr(d, 'cooked_text')
        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'
            ]
Ejemplo n.º 5
0
 def test_EntityInTitle(self):
     REQUEST = fakeRequest()
     REQUEST['BODY'] = ENTITY_IN_TITLE
     d = NewsItem('foo')
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     assert d.title == '&Auuml;rger', "Title '%s' being lost" % (
         d.title )
Ejemplo n.º 6
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
Ejemplo n.º 7
0
 def test_BasicHtml(self):
     REQUEST = fakeRequest()
     REQUEST['BODY']=BASIC_HTML
     d = NewsItem('foo')
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     assert d.Format() == 'text/html', d.Format()
     assert d.title == 'Title in tag'
     assert string.find(d.text, '</body>') == -1
     assert d.Description() == 'Describe me'
     assert len(d.Contributors()) == 2
Ejemplo n.º 8
0
 def test_UpperedHtml(self):
     REQUEST = fakeRequest()
     REQUEST['BODY'] = string.upper(BASIC_HTML)
     d = NewsItem('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()) == 2
Ejemplo n.º 9
0
 def test_BasicHtml(self):
     REQUEST = fakeRequest()
     REQUEST['BODY'] = BASIC_HTML
     d = NewsItem('foo')
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     assert d.Format() == 'text/html', d.Format()
     assert d.title == 'Title in tag'
     assert string.find(d.text, '</body>') == -1
     assert d.Description() == 'Describe me'
     assert len(d.Contributors()) == 2
Ejemplo n.º 10
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
Ejemplo n.º 11
0
    def test_StructuredText(self):
        REQUEST = fakeRequest()
        REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
        d = NewsItem('foo')
        d.PUT(REQUEST, RESPONSE=fakeResponse())

        assert d.Format() == 'text/plain'
        assert d.Title() == 'My NewsItem'
        assert d.Description() == 'A news item by me'
        assert len(d.Contributors()) == 3
        assert string.find(d.cooked_text, '<p>') >= 0
Ejemplo n.º 12
0
 def test_StructuredText(self):
     REQUEST = fakeRequest()
     REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
     d = NewsItem('foo')
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     
     assert d.Format() == 'text/plain'
     assert d.Title() == 'My NewsItem'
     assert d.Description() == 'A news item by me'
     assert len(d.Contributors()) == 3
     assert string.find(d.cooked_text, '<p>') >= 0
Ejemplo n.º 13
0
    def test_Init(self):
        REQUEST = fakeRequest()
        REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
        d = NewsItem('foo', text='')
        d.PUT(REQUEST, RESPONSE=fakeResponse())
        assert d.Format() == 'text/plain'
        assert d.Title() == 'My NewsItem', d.Title()
        assert d.Description() == 'A news item by me'
        assert len(d.Contributors()) == 3
        assert string.find(d.cooked_text, '<p>') >= 0

        d = NewsItem('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()) == 2

        d = NewsItem('foo', text_format='structured-text', title='Foodoc')
        assert d.text == ''
        assert d.title == 'Foodoc'
        assert d.Format() == 'text/plain'
Ejemplo n.º 14
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'
Ejemplo n.º 15
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
Ejemplo n.º 16
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]
Ejemplo n.º 17
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]
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"))
        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()
Ejemplo n.º 19
0
    def test_BasicHtmlPUT(self):
        REQUEST = fakeRequest()
        REQUEST['BODY'] = 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
        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'
        ]
Ejemplo n.º 20
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()
Ejemplo n.º 21
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]
Ejemplo n.º 22
0
    def test_StructuredText(self):
        REQUEST = fakeRequest()
        REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
        d = Document('foo')
        d.PUT(REQUEST, RESPONSE=fakeResponse())
        assert hasattr(d, 'cooked_text')
        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'
        ]
Ejemplo n.º 23
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]
Ejemplo n.º 24
0
 def test_HtmlWithDoctype(self):
     REQUEST = fakeRequest()
     d = NewsItem('foo')
     REQUEST['BODY'] = '%s\n%s' % (DOCTYPE, BASIC_HTML)
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     assert d.Description() == 'Describe me'
Ejemplo n.º 25
0
 def test_EntityInTitle(self):
     REQUEST = fakeRequest()
     REQUEST['BODY'] = ENTITY_IN_TITLE
     d = Document('foo')
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     assert d.title == '&Auuml;rger', "Title '%s' being lost" % (d.title)
Ejemplo n.º 26
0
 def test_HtmlWithDoctype(self):
     REQUEST = fakeRequest()
     d = Document('foo')
     REQUEST['BODY'] = '%s\n%s' % (DOCTYPE, BASIC_HTML)
     d.PUT(REQUEST, RESPONSE=fakeResponse())
     assert d.Description() == 'Describe me'