Beispiel #1
0
    def test_Init(self):
        self.REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
        d = self.d
        d.PUT(self.REQUEST, self.RESPONSE)
        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(d.cooked_text.find('<p>') >= 0)

        d = Document('foo', text='')
        self.REQUEST['BODY'] = BASIC_HTML
        d.PUT(self.REQUEST, self.RESPONSE)
        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')
Beispiel #2
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 #3
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 #4
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 #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()) == 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 #6
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'
        ]
Beispiel #7
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'])
Beispiel #8
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'])
Beispiel #9
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
Beispiel #10
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)