[Zope3-checkins] CVS: Products3/demo/messageboard/step5/tests - __init__.py:1.1 test_fields.py:1.1 test_message.py:1.1 test_messageboard.py:1.1 test_size.py:1.1

Stephan Richter srichter@cosmos.phy.tufts.edu
Tue, 10 Jun 2003 17:49:52 -0400


Update of /cvs-repository/Products3/demo/messageboard/step5/tests
In directory cvs.zope.org:/tmp/cvs-serv20196/step5/tests

Added Files:
	__init__.py test_fields.py test_message.py 
	test_messageboard.py test_size.py 
Log Message:
This is step 6 of the message board which implements a new ISized adapter 
for the Message object.


=== Added File Products3/demo/messageboard/step5/tests/__init__.py ===
# Package Maker


=== Added File Products3/demo/messageboard/step5/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 21:49:51 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/step5/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 21:49:51 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/step5/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 21:49:51 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()


=== Added File Products3/demo/messageboard/step5/tests/test_size.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 Size Tests

$Id: test_size.py,v 1.1 2003/06/10 21:49:51 srichter Exp $
"""
import unittest
from zope.app.interfaces.size import ISized
from zopeproducts.messageboard.message import Message, MessageSized

class Stub:
    pass

class SizedTest(unittest.TestCase):

    def test_interface(self):
        self.assert_(ISized.isImplementedBy(MessageSized(Message())))

    def test_sizeForSorting(self):
        size = MessageSized(Message())
        self.assertEqual(('item', 0), size.sizeForSorting())
        size._message.setObject('msg1', Message()) 
        self.assertEqual(('item', 1), size.sizeForSorting())
        size._message.setObject('att1', Stub()) 
        self.assertEqual(('item', 2), size.sizeForSorting())

    def test_sizeForDisplay(self):
        size = MessageSized(Message())
        self.assertEqual('0 replies, 0 attachments',
                         size.sizeForDisplay())
        size._message.setObject('msg1', Message()) 
        self.assertEqual('1 reply, 0 attachments',
                         size.sizeForDisplay())
        size._message.setObject('msg2', Message()) 
        self.assertEqual('2 replies, 0 attachments',
                         size.sizeForDisplay())
        size._message.setObject('att1', Stub()) 
        self.assertEqual('2 replies, 1 attachment',
                         size.sizeForDisplay())
        size._message.setObject('att2', Stub()) 
        self.assertEqual('2 replies, 2 attachments',
                         size.sizeForDisplay())

def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(SizedTest),
        ))

if __name__ == '__main__':
    unittest.main()