[Zope3-checkins] CVS: Products3/demo/messageboard/step3/tests - __init__.py:1.1 test_fields.py:1.1 test_message.py:1.1 test_messageboard.py:1.1
Stephan Richter
srichter@cosmos.phy.tufts.edu
Tue, 10 Jun 2003 10:40:46 -0400
Update of /cvs-repository/Products3/demo/messageboard/step3/tests
In directory cvs.zope.org:/tmp/cvs-serv23711/step3/tests
Added Files:
__init__.py test_fields.py test_message.py
test_messageboard.py
Log Message:
Okay, here is the code for step 3: Custom Schema Fields and Form Widgets.
=== Added File Products3/demo/messageboard/step3/tests/__init__.py ===
# Package Maker
=== Added File Products3/demo/messageboard/step3/tests/test_fields.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Message Board Tests
$Id: test_fields.py,v 1.1 2003/06/10 14:40:45 srichter Exp $
"""
import unittest
from zope.schema.tests.test_strfield import TextTest
from zopeproducts.messageboard.fields import HTML, ForbiddenTags
class HTMLTest(TextTest):
_Field_Factory = HTML
def test_AllowedTagsHTMLValidate(self):
html = self._Field_Factory(allowed_tags=('h1','pre'))
html.validate(u'<h1>Blah</h1>')
html.validate(u'<pre>Blah</pre>')
html.validate(u'<h1><pre>Blah</pre></h1>')
html.validate(u'<h1 style="..."><pre>Blah</pre></h1>')
html.validate(u'<h1 style="..."><pre f="">Blah</pre></h1>')
self.assertRaisesErrorNames(ForbiddenTags, html.validate,
u'<h2>Foo</h2>')
self.assertRaisesErrorNames(ForbiddenTags, html.validate,
u'<h2><pre>Foo</pre></h2>')
self.assertRaisesErrorNames(ForbiddenTags, html.validate,
u'<h2 attr="blah">Foo</h2>')
def test_ForbiddenTagsHTMLValidate(self):
html = self._Field_Factory(forbidden_tags=('h2','pre'))
html.validate(u'<h1>Blah</h1>')
html.validate(u'<h1 style="...">Blah</h1>')
html.validate(u'<h1 style="..."><div>Blah</div></h1>')
html.validate(u'<h1 style="..."><div f="">Blah</div></h1>')
self.assertRaisesErrorNames(ForbiddenTags, html.validate,
u'<h2>Foo</h2>')
self.assertRaisesErrorNames(ForbiddenTags, html.validate,
u'<h2><div>Foo</div></h2>')
self.assertRaisesErrorNames(ForbiddenTags, html.validate,
u'<h2 attr="blah">Foo</h2>')
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(HTMLTest),
))
if __name__ == '__main__':
unittest.main()
=== Added File Products3/demo/messageboard/step3/tests/test_message.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Message Board Tests
$Id: test_message.py,v 1.1 2003/06/10 14:40:45 srichter Exp $
"""
import unittest
from zope.testing.doctestunit import DocTestSuite
from zope.app.container.tests.test_icontainer import \
BaseTestIContainer, DefaultTestData
from zopeproducts.messageboard.message import Message
from zopeproducts.messageboard.interfaces import IMessage
class Test(BaseTestIContainer, unittest.TestCase):
def makeTestObject(self):
return Message()
def makeTestData(self):
return DefaultTestData()
def test_interface(self):
self.assert_(IMessage.isImplementedBy(
self.makeTestObject()))
def test_title():
"""
>>> msg = Message()
>>> msg.title
u''
>>> msg.title = u'Message Title'
>>> msg.title
u'Message Title'
"""
def test_body():
"""
>>> msg = Message()
>>> msg.body
u''
>>> msg.body = u'Message Body'
>>> msg.body
u'Message Body'
"""
def test_suite():
return unittest.TestSuite((
DocTestSuite(),
unittest.makeSuite(Test),
))
if __name__ == '__main__':
unittest.main()
=== Added File Products3/demo/messageboard/step3/tests/test_messageboard.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Message Board Tests
$Id: test_messageboard.py,v 1.1 2003/06/10 14:40:45 srichter Exp $
"""
import unittest
from zope.app.container.tests.test_icontainer import \
BaseTestIContainer, DefaultTestData
from zopeproducts.messageboard.messageboard import MessageBoard
from zopeproducts.messageboard.interfaces import IMessageBoard
class Test(BaseTestIContainer, unittest.TestCase):
def makeTestObject(self):
return MessageBoard()
def makeTestData(self):
return DefaultTestData()
def test_interface(self):
self.assert_(IMessageBoard.isImplementedBy(
self.makeTestObject()))
def test_description(self):
board = self.makeTestObject()
self.assertEqual(u'', board.description)
board.description = u'Message Board Description'
self.assertEqual('Message Board Description',
board.description)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Test),
))
if __name__ == '__main__':
unittest.main()