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' ]
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 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)
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
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)
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 )
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 )
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
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
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 )
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 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')
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()
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()
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
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 )
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)
def test_EditStructuredTextWithHTML(self): d = Document('foo') d.edit(text_format='structured-text', text=STX_WITH_HTML) self.assertEqual(d.Format(), 'text/plain')
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')
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'
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'
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)
def test_EditStructuredTextWithHTML(self): d = Document('foo') d.edit(text_format='structured-text', text=STX_WITH_HTML) self.assertEqual( d.Format(), 'text/plain' )
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')
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 )