[Zope3-checkins] CVS: Zope3/src/zope/app/onlinehelp/tests - __init__.py:1.1 help.txt:1.1 help2.txt:1.1 test_helpdirectives.py:1.1 test_onlinehelp.py:1.1 test_onlinehelptopic.py:1.1

Stephan Richter srichter@cbu.edu
Tue, 7 Jan 2003 07:27:57 -0500


Update of /cvs-repository/Zope3/src/zope/app/onlinehelp/tests
In directory cvs.zope.org:/tmp/cvs-serv14439/app/onlinehelp/tests

Added Files:
	__init__.py help.txt help2.txt test_helpdirectives.py 
	test_onlinehelp.py test_onlinehelptopic.py 
Log Message:
Implementation of the OnlineHelp proposal. Since we do not have STX yet,
it works only with regular Text or HTML files at the moment. 

I added a box to the Rotterdam skin which shows all relevant Help Topics.
Currently you can only see a Help Topic for the File Upload screen. 

To Do:

  - Clean up code a bit.

  - Write Documentation (ZCML, Recipe, ...)

  - Implement STX or ReST support.

  - Writing Help File for the various screens!


=== Added File Zope3/src/zope/app/onlinehelp/tests/__init__.py ===
##############################################################################
#
# Copyright (c) 2002, 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.
#
##############################################################################
"""Test Directory

$Id: __init__.py,v 1.1 2003/01/07 12:27:52 srichter Exp $
"""


=== Added File Zope3/src/zope/app/onlinehelp/tests/help.txt ===
This is a help!

=== Added File Zope3/src/zope/app/onlinehelp/tests/help2.txt ===
This is another help!

=== Added File Zope3/src/zope/app/onlinehelp/tests/test_helpdirectives.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
"""Test the gts ZCML namespace directives.

$Id: test_helpdirectives.py,v 1.1 2003/01/07 12:27:52 srichter Exp $
"""
import os
import unittest

from cStringIO import StringIO

from zope.interface import Interface
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.configuration.xmlconfig import xmlconfig, Context, XMLConfig
from zope.configuration.exceptions import ConfigurationError

import zope.app.onlinehelp
from zope.app.onlinehelp import help
import zope.app.onlinehelp.tests
from zope.app.onlinehelp.tests.test_onlinehelptopic import testdir

template = """<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:help='http://namespaces.zope.org/help'>
   xmlns:test='http://www.zope.org/NS/Zope3/test'>
   %s
   </zopeConfigure>"""

class I1(Interface):
    pass

class View:
    pass


class DirectivesTest(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        XMLConfig('meta.zcml', zope.app.onlinehelp)()

    def test_register(self):
        self.assertEqual(help.keys(), [])
        xmlconfig(StringIO(template % (
            '''
              <help:register 
                  id = "help1"
                  title = "Help"
                  for = "zope.app.onlinehelp.tests.test_helpdirectives.I1"
                  view = "zope.app.onlinehelp.tests.test_helpdirectives.View"
                  doc_path = "./help.txt" />
                  '''
            )), None, Context([], zope.i18n.tests))
        self.assertEqual(help.keys(), ['help1'])
        self.assertEqual(help._registry[(I1, View)][0].title, 'Help')
        help._register = {}
        del help['help1']

    def test_unregister(self):
        self.assertEqual(help.keys(), [])
        path = os.path.join(testdir(), 'help.txt')
        help.registerHelpTopic('', 'help', 'Help',
                               path, 'txt', I1, View)
        # XXX: Requires CA setup
        #xmlconfig(StringIO(template % (
        #    '''
        #      <help:unregister path="help1" />
        #      '''
        #    )), None, Context([], zope.i18n.tests))
        #self.assertEqual(help.keys(), [])



def test_suite():
    return unittest.makeSuite(DirectivesTest)

if __name__ == '__main__':
    unittest.TextTestRunner().run(test_suite())


=== Added File Zope3/src/zope/app/onlinehelp/tests/test_onlinehelp.py ===
##############################################################################
#
# Copyright (c) 2002, 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.
#
##############################################################################
"""Test OnlineHelp

$Id: test_onlinehelp.py,v 1.1 2003/01/07 12:27:52 srichter Exp $
"""
import os
from unittest import TestSuite, makeSuite
from zope.interface import Interface
from zope.app.onlinehelp import OnlineHelp
from test_onlinehelptopic import TestOnlineHelpTopic, testdir

class I1(Interface):
    pass

class View:
    pass

class TestOnlineHelp(TestOnlineHelpTopic):

    def setUp(self):
        path = os.path.join(testdir(), 'help.txt')
        self.topic = OnlineHelp('Help', path, 'txt')

    def test_registerHelpTopic(self):
        path = os.path.join(testdir(), 'help2.txt')
        self.topic.registerHelpTopic('', 'help2', 'Help 2',
                                     path, 'txt', I1, View)
        self.assertEqual(self.topic['help2'].title, 'Help 2')
        self.assertEqual(self.topic._registry[(I1, View)][0].title, 'Help 2')

        # XXX: Needs CA setup
        #self.topic.unregisterHelpTopic('help2')
        #self.assertEqual(self.topic.get('help2', None), None)
        #self.assertEqual(self.topic._registry[(I1, View)], [])
        
    def test_getTopicsForInterfaceAndView(self):
        path = os.path.join(testdir(), 'help2.txt')
        self.topic.registerHelpTopic('', 'help2', 'Help 2',
                                     path, 'txt', I1, View)
        self.assertEqual(
            self.topic.getTopicsForInterfaceAndView(I1, View)[0].title,
            'Help 2')

def test_suite():
    return TestSuite((
        makeSuite(TestOnlineHelp),
        ))


=== Added File Zope3/src/zope/app/onlinehelp/tests/test_onlinehelptopic.py ===
##############################################################################
#
# Copyright (c) 2002, 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.
#
##############################################################################
"""Test OnlineHelpTopic

$Id: test_onlinehelptopic.py,v 1.1 2003/01/07 12:27:52 srichter Exp $
"""
import os
from unittest import TestCase, TestSuite, makeSuite
from zope.app.onlinehelp import OnlineHelpTopic

def testdir():
    import zope.app.onlinehelp.tests
    return os.path.dirname(zope.app.onlinehelp.tests.__file__)

class TestOnlineHelpTopic(TestCase):

    def setUp(self):
        path = os.path.join(testdir(), 'help.txt')
        self.topic = OnlineHelpTopic('Help', path, 'txt')

    def test_title(self):
        self.assertEqual(self.topic.getTitle(), 'Help')
        self.assertEqual(self.topic.title, 'Help')
        self.topic.setTitle('Help1')
        self.assertEqual(self.topic.getTitle(), 'Help1')
        self.assertEqual(self.topic.title, 'Help1')
        self.topic.title = 'Help2'
        self.assertEqual(self.topic.getTitle(), 'Help2')
        self.assertEqual(self.topic.title, 'Help2')

    def test_content(self):
        self.assertEqual(self.topic.getContent(),
                         '<p>This is a help!</p>')
        path = os.path.join(testdir(), 'help.txt')
        self.topic.setContentPath(path, 'foo')
        self.assertEqual(self.topic.getContent(),
                         'This is a help!')

def test_suite():
    return TestSuite((
        makeSuite(TestOnlineHelpTopic),
        ))