Back to index

plone3  3.1.7
test_index.py
Go to the documentation of this file.
00001 ################################################################################
00002 #
00003 # Copyright (c) 2002-2005, Benjamin Saller <bcsaller@ideasuite.com>, and
00004 #                              the respective authors. All rights reserved.
00005 # For a list of Archetypes contributors see docs/CREDITS.txt.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions are met:
00009 #
00010 # * Redistributions of source code must retain the above copyright notice, this
00011 #   list of conditions and the following disclaimer.
00012 # * Redistributions in binary form must reproduce the above copyright notice,
00013 #   this list of conditions and the following disclaimer in the documentation
00014 #   and/or other materials provided with the distribution.
00015 # * Neither the name of the author nor the names of its contributors may be used
00016 #   to endorse or promote products derived from this software without specific
00017 #   prior written permission.
00018 #
00019 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00020 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00022 # FOR A PARTICULAR PURPOSE.
00023 #
00024 ################################################################################
00025 """
00026 """
00027 
00028 import time
00029 from Testing import ZopeTestCase
00030 from Products.Archetypes.atapi import *
00031 from Products.Archetypes.tests.atsitetestcase import ATSiteTestCase
00032 from Products.Archetypes.tests.utils import makeContent
00033 from Products.CMFCore.utils import getToolByName
00034 
00035 class ETagTest(ATSiteTestCase):
00036 
00037     def afterSetUp(self):
00038         self.setRoles(['Manager'])
00039         self.inst = makeContent(self.portal,
00040                                 portal_type='SimpleType',
00041                                 id='simple_type')
00042 
00043     #! time.sleep(1) is needed to get tests running on fast machines
00044 
00045     def test_etag_does_update_reindex_all(self):
00046         before = self.inst.http__etag(readonly=True)
00047         time.sleep(1)
00048         self.inst.reindexObject()
00049         after = self.inst.http__etag(readonly=True)
00050         self.failIf(before == after)
00051 
00052     def test_etag_update_on_edit(self):
00053         before = self.inst.http__etag(readonly=True)
00054         time.sleep(1)
00055         self.inst.edit(title='Bla')
00056         after = self.inst.http__etag(readonly=True)
00057         self.failIf(before == after)
00058 
00059     def test_etag_update_on_update(self):
00060         before = self.inst.http__etag(readonly=True)
00061         time.sleep(1)
00062         self.inst.update(title='Bla')
00063         after = self.inst.http__etag(readonly=True)
00064         self.failIf(before == after)
00065 
00066     def test_etag_update_on_processform(self):
00067         before = self.inst.http__etag(readonly=True)
00068         time.sleep(1)
00069         self.inst.processForm(data=1, values={'title':'Bla'})
00070         after = self.inst.http__etag(readonly=True)
00071         self.failIf(before == after)
00072 
00073 
00074 class ReindexTest(ATSiteTestCase):
00075 
00076     def afterSetUp(self):
00077         self.setRoles(['Manager'])
00078         self.inst = makeContent(self.portal,
00079                                 portal_type='SimpleType',
00080                                 id='simple_type')
00081         self.ct = getToolByName(self.portal, 'portal_catalog')
00082 
00083     def test_reindex_unindexes_old(self):
00084         ct = self.ct
00085         self.assertEquals(len(ct(SearchableText='Mosquito')), 0)
00086         self.inst.edit(title='Mosquito')
00087         self.assertEquals(len(ct(SearchableText='Mosquito')), 1)
00088         self.inst.edit(title='Libido')
00089         self.assertEquals(len(ct(SearchableText='Mosquito')), 0)
00090 
00091 def test_suite():
00092     from unittest import TestSuite, makeSuite
00093     suite = TestSuite()
00094     suite.addTest(makeSuite(ETagTest))
00095     suite.addTest(makeSuite(ReindexTest))
00096     return suite