[Zope3-checkins] CVS: Products3/NewsSite/tests - test_newssiteview.py:1.1

Axel Bringenberg A.Bringenberg@srz-berlin.de
Wed, 26 Mar 2003 09:49:32 -0500


Update of /cvs-repository/Products3/NewsSite/tests
In directory cvs.zope.org:/tmp/cvs-serv21418

Added Files:
	test_newssiteview.py 
Log Message:
 - added


=== Added File Products3/NewsSite/tests/test_newssiteview.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.
#
##############################################################################
"""Test news site views.

$Id: test_newssiteview.py,v 1.1 2003/03/26 14:49:31 bringi Exp $
"""

import unittest

from zopeproducts.NewsSite.interfaces import INewsSite
from zopeproducts.NewsSite.NewsItem.interfaces import INewsItem

from zope.publisher.interfaces.browser import IBrowserView
from zope.component.view import provideView
from zope.app.interfaces.dublincore import ICMFDublinCore



#############################################################################
# If your tests change any global registries, then uncomment the
# following import and include CleanUp as a base class of your
# test. It provides a setUp and tearDown that clear global data that
# has registered with the test cleanup framework.  If your class has
# its own setUp or tearDown, make sure you call the CleanUp setUp and
# tearDown from them, or the benefits of using CleanUp will be lost.
# Don't use CleanUp based tests outside the Zope package.

from zope.testing.cleanup import CleanUp # Base class w registry cleanup

class DummyNewsSite:
	__implements__ = INewsSite

	def __len__(self):
		return len(self.data)

	def	__getitem__(self, index):
		return self.data[index]

	def __init__(self):
		self.data=[]

class DummyNewsItem:
	__implements__ = INewsItem

	def __init__(self, body, date):
		self.body = body
		self.date = date
		self.lead = u"blabla"
		self.title = u"Blah"

class DummyNoNewsItem:
	body = u"no news"

class DummyDublinCoreAdapter:
	__implements__ = ICMFDublinCore
	__used_for__ = INewsItem

	def __init__(self, context):
		self.context = context
		
	def getEffectiveDate(self):
		return self.context.date

#############################################################################

class TestNewsSiteView(unittest.TestCase):

    def _getTargetClass(self):
        from zopeproducts.NewsSite.newssite import NewsSiteView

        return NewsSiteView

    def _makeOne(self, context=None, request=None, *args, **kw):
        return self._getTargetClass()(context, request, *args, **kw)

    def test_create(self):
        newssite = self._makeOne()
        self.failUnless(IBrowserView.isImplementedBy(newssite))
	
	def test_list(self):
		site = DummyNewsSite()
		site.data.append(DummyNewsItem(u"lola", datestime('2003-01-03')))
		site.data.append(DummyNewsItem(u"texttext", datetime('2003-01-01')))
		site.data.append(DummyNewsItem(u"lilo", datestime('2003-01-04')))
		site.data.append(DummyNoNewsItem())
		site.data.append(DummyNewsItem(u"blalbla", datestime('2003-01-02')))
		view = self._makeOne(site)
		
		filtered = view.listNewsItems()

		texts = [x.body for x in filtered]

		self.failIf(u"no news" in texts)
		self.assertEqual([u"texttext",u"blalbla",u"lola",u"lilo"], texts)

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


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