Back to index

plone3  3.1.7
wickedtestcase.py
Go to the documentation of this file.
00001 import os
00002 from cStringIO import StringIO
00003 from Testing import ZopeTestCase
00004 from Testing.ZopeTestCase import PortalTestCase, installProduct
00005 from Products.CMFCore.utils  import getToolByName
00006 from Products.PloneTestCase import ptc
00007 from Products.PloneTestCase.layer import PloneSite 
00008 from wicked.atcontent.Extensions.Install import install as installWicked
00009 import wicked.at.config as config
00010 from wicked.testing.xml import xstrip as strip
00011 from wicked.normalize import titleToNormalizedId
00012 from wicked.registration import BasePloneWickedRegistration 
00013 from zope.interface import Interface
00014 from Products.Five import zcml
00015 from App.Product import initializeProduct
00016 from App.ProductContext import ProductContext
00017 
00018 ptc.setupPloneSite(products=['wicked.atcontent'])
00019 
00020 TITLE1 = "Cop Shop"
00021 TITLE2 = 'DMV Computer has died'
00022 
00023 USELXML = False
00024 
00025 import transaction as txn
00026 #from collective.testing.debug import autopsy
00027 
00028 def init_product(module_, app, init_func=None):
00029     product = initializeProduct(module_,
00030                                 module_.__name__,
00031                                 module_.__path__[0],
00032                                 app)
00033     
00034     product.package_name = module_.__name__
00035     
00036     if init_func is not None:
00037         newContext = ProductContext(product, app, module_)
00038         init_func(newContext)
00039 
00040 
00041 class WickedSite(PloneSite):
00042 
00043     @classmethod
00044     def setUp(cls):
00045         app = ZopeTestCase.app()
00046         plone = app.plone
00047         reg = BasePloneWickedRegistration(plone)
00048         import wicked.atcontent
00049         from wicked.atcontent.zope2 import initialize
00050         init_product(wicked.atcontent, app, initialize)
00051         zcml.load_config("configure.zcml", package=wicked.atcontent)
00052         reg.handle()
00053         txn.commit()
00054         ZopeTestCase.close(app)
00055 
00056     @classmethod
00057     def tearDown(cls):
00058         app = ZopeTestCase.app()
00059         plone = app.plone
00060         reg = BasePloneWickedRegistration(plone)
00061         reg.handle(unregister=True)
00062         txn.commit()
00063         ZopeTestCase.close(app)
00064 
00065 # This is the test case. You will have to add test_<methods> to your
00066 # class in order to assert things about your Product.
00067 class WickedTestCase(ptc.PloneTestCase):
00068 
00069     layer = WickedSite
00070     setter = 'setBody'
00071 
00072     def set_text(self, content, text, **kw):
00073         setter = getattr(content, self.setter)
00074         setter(text, **kw)
00075     
00076     def afterSetUp(self):
00077         #self.loginAsPortalOwner()
00078         # add some pages
00079         id1 = titleToNormalizedId(TITLE1)
00080         id2 = titleToNormalizedId(TITLE2)
00081         try:
00082             self.page1 = makeContent(self.folder,id1,self.wicked_type,title=TITLE1)
00083         except :
00084             import sys, pdb
00085             pdb.post_mortem(sys.exc_info()[2])
00086         self.page2 = makeContent(self.folder,id2,self.wicked_type, title=TITLE2)
00087 
00088     strip = staticmethod(strip)
00089  
00090     def getRenderedWickedField(self, doc):
00091         fieldname = self.wicked_field
00092         text = doc.getField(fieldname).get(doc)
00093         return self.strip(text)
00094 
00095     def failIfAddLink(self, doc):
00096         """ does wicked field text contain a wicked-generated add link? """
00097         # XXX make test stronger, support looking for specific links
00098         home_url= doc.absolute_url()
00099         text = self.getRenderedWickedField(doc)
00100         if home_url in text:
00101             self.fail("%s FOUND:\n\n %s" %(home_url, text))
00102 
00103     def failUnlessAddLink(self, doc):
00104         """ does wicked field text contain a wicked-generated add link? """
00105         # XXX make test stronger, support looking for specific links
00106         home_url= doc.absolute_url()
00107         text = self.getRenderedWickedField(doc)
00108         if not home_url in text:
00109             self.fail("%s NOT FOUND:\n\n %s" %(home_url, text))
00110 
00111     def failIfWickedLink(self, doc, dest):
00112         dest = dest.absolute_url()
00113         text = self.getRenderedWickedField(doc)
00114         if dest in text:
00115             self.fail("%s FOUND:\n\n %s" %(dest, text))
00116 
00117     failIfMatch = failIfWickedLink
00118 
00119     def failUnlessWickedLink(self, doc, dest):
00120         dest = dest.absolute_url()
00121         text = self.getRenderedWickedField(doc)
00122         if not dest in text:
00123             self.fail("%s NOT FOUND:\n\n %s" %(dest, text))
00124 
00125     failUnlessMatch = failUnlessWickedLink
00126 
00127     def hasAddLink(self, doc):
00128         """ does wicked field text contain a wicked-generated add link? """
00129         # XXX make test stronger, support looking for specific links
00130         return doc.absolute_url() in self.getRenderedWickedField(doc)
00131 
00132     def hasWickedLink(self, doc, dest):
00133         """ does wicked field text contain a resolved wicked link to
00134         the specified dest object?  """
00135         # XXX make test stronger
00136         return dest.absolute_url() in self.getRenderedWickedField(doc)
00137 
00138 
00139 
00140 def makeContent(container, id, portal_type, **kw):
00141     container.invokeFactory(id=id, type_name=portal_type, **kw)
00142     o = getattr(container, id)
00143     return o