Пример #1
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'
Пример #2
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'
            ]
Пример #3
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)
Пример #4
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
Пример #5
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')
Пример #6
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
Пример #7
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)
Пример #8
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
Пример #9
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
Пример #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
Пример #11
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)
Пример #12
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
Пример #13
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()
Пример #14
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 )
Пример #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"))
        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()
Пример #16
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())
Пример #17
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'
            ]
Пример #18
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()) == 3

        d = Document('foo', title='Foodoc')
        assert d.text == ''
        assert d.title == 'Foodoc'
        assert d.Format() == 'text/plain'
Пример #19
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'
        ]
Пример #20
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'
Пример #21
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'])
Пример #22
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'])
Пример #23
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'
        ]
Пример #24
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'
Пример #25
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'
Пример #26
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'
Пример #27
0
class DocumentPUTTests(RequestTest):
    def setUp(self):
        RequestTest.setUp(self)
        self.d = Document('foo')

    def test_PUTBasicHTML(self):
        self.REQUEST['BODY'] = BASIC_HTML
        d = self.d
        r = d.PUT(self.REQUEST, self.RESPONSE)
        self.failUnless(hasattr(d, 'cooked_text'))
        self.assertEqual(d.Format(), 'text/html')
        self.assertEqual(d.title, 'Title in tag')
        self.assertEqual(d.text.find('</body>'), -1)
        self.assertEqual(d.Description(), 'Describe me')
        self.assertEqual(len(d.Contributors()), 3)
        self.assertEqual(d.Contributors()[-1],
                         'Benotz, Larry J ([email protected])')
        self.assertEqual(d.cooked_text, '\n  <h1>Not a lot here</h1>\n ')
        self.assertEqual(r.status, 204)

        subj = list(d.Subject())
        self.assertEqual(len(subj), 4)
        subj.sort()
        self.assertEqual(
            subj, ['content management', 'framework', 'unit tests', 'zope'])

    def test_PUTSimpleXHTML(self):
        self.REQUEST['BODY'] = SIMPLE_XHTML
        d = self.d
        r = d.PUT(self.REQUEST, self.RESPONSE)
        self.failUnless(hasattr(d, 'cooked_text'))
        self.assertEqual(d.Format(), 'text/html')
        self.assertEqual(d.Description(), 'Describe me')
        self.assertEqual(d.cooked_text, '\n  <h1>Not a lot here</h1>\n ')
        self.assertEqual(r.status, 204)

    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)