[Zope3-checkins] CVS: Zope3/src/zope/app/browser/index/field/tests - __init__.py:1.1 test_control.py:1.1

Marius Gedminas mgedmin@codeworks.lt
Sun, 22 Jun 2003 12:10:57 -0400


Update of /cvs-repository/Zope3/src/zope/app/browser/index/field/tests
In directory cvs.zope.org:/tmp/cvs-serv11775/src/zope/app/browser/index/field/tests

Added Files:
	__init__.py test_control.py 
Log Message:
Added views for FieldIndex


=== Added File Zope3/src/zope/app/browser/index/field/tests/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/app/browser/index/field/tests/test_control.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.
#
##############################################################################
"""Unit test for field index browser views

$Id: test_control.py,v 1.1 2003/06/22 16:10:56 mgedmin Exp $
"""

import unittest
from zope.interface import implements
from zope.publisher.browser import TestRequest
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.component import getServiceManager
from zope.app.services.servicenames import HubIds
from zope.app.interfaces.services.hub import IObjectHub
from zope.app.interfaces.dublincore import IZopeDublinCore
from zope.exceptions import NotFoundError

class DublinCoreStub:

    implements(IZopeDublinCore)

    def __init__(self, title):
        self.title = title

class ObjectHubStub:

    implements(IObjectHub)

    def getPath(self, id):
        return {101: '/a', 102: '/b'}[id]

    def getObject(self, id):
        if id == 102:
            return DublinCoreStub(title='Foo')
        else:
            raise NotFoundError

class FieldIndexStub:

    def search(self, values):
        assert values == 'xyzzy'
        return [101, 102]

class TestControlView(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        service_manager = getServiceManager(None)
        service_manager.defineService(HubIds, IObjectHub)
        service_manager.provideService(HubIds, ObjectHubStub())

    def test_query(self):
        from zope.app.browser.index.field.control import ControlView
        index = FieldIndexStub()
        request = TestRequest()
        view = ControlView(index, request)
        request.form['queryText'] = 'xyzzy'
        results = view.query()
        self.assertEquals(results, {'results': [
                                            {'location': '/a'},
                                            {'location': '/b', 'title': 'Foo'}
                                        ],
                                    'nresults': 2,
                                    'first': 1,
                                    'last': 2,
                                    'total': 2})


def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestControlView))
    return suite


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