Back to index

plone3  3.1.7
test_scope.py
Go to the documentation of this file.
00001 import os, sys, time
00002 import unittest
00003 from sets import Set
00004 import traceback
00005 
00006 from Testing import ZopeTestCase
00007 
00008 from wicked.normalize import titleToNormalizedId
00009 from wicked.config import BACKLINK_RELATIONSHIP
00010 from wicked.atcontent.ironicwiki import IronicWiki
00011 from wickedtestcase import WickedTestCase, makeContent, WickedSite
00012 
00013 from zope.component import adapter, provideAdapter
00014 from zope.interface import implementer, Interface
00015 from zope.interface import alsoProvides, noLongerProvides
00016 from wicked.interfaces import IScope, IAmWicked, IAmWickedField
00017 
00018 class IScopedField(IAmWickedField):
00019     """ scope marker """
00020 
00021 
00022 @implementer(IScope)
00023 @adapter(IScopedField, IAmWicked)
00024 def scopeTester(field, context):
00025     """
00026     a demo scope function for testing, returns a scope that includes
00027     the parent of the current container, but not anything two levels
00028     (or more) up
00029     """
00030     scope_obj = context.aq_inner.aq_parent
00031     if not context.isPrincipiaFolderish:
00032         scope_obj = scope_obj.aq_inner.aq_parent
00033     path = '/'.join(scope_obj.getPhysicalPath())
00034     return path
00035 
00036 
00037 class Scoped(WickedSite):
00038     
00039     @classmethod
00040     def setUp(cls):
00041         alsoProvides(IronicWiki.schema['body'], IScopedField)
00042         # @@ maybe make this local?
00043         provideAdapter(scopeTester)
00044         
00045     @classmethod
00046     def tearDown(cls):
00047         # clear out markers
00048         noLongerProvides(IronicWiki.schema['body'], IScopedField)        
00049 
00050 
00051 class TestWickedScope(WickedTestCase):
00052     wicked_type = 'IronicWiki'
00053     wicked_field = 'body'
00054     layer = Scoped
00055 
00056     def test_registration(self):
00057         # test our test ;)
00058         from zope.component import getMultiAdapter
00059         assert getMultiAdapter((IronicWiki.schema['body'], self.page1), IScope) \
00060                == '/plone/Members'
00061 
00062     def test_insideScope(self):
00063         # @@ this test passes without "scope". bogus?
00064         f2 = makeContent(self.folder, 'f2', 'Folder')
00065         w1 = makeContent(f2, 'w1', 'IronicWiki',
00066                           title='W1 Title')
00067         
00068         self.set_text(w1, "((%s))" % self.page1.Title())
00069         self.failUnlessWickedLink(w1, self.page1)
00070 
00071     def test_outsideScope(self):
00072         f2 = makeContent(self.folder, 'f2', 'Folder')
00073         f3 = makeContent(f2, 'f3', 'Folder')
00074         w1 = makeContent(f3, 'w1', 'IronicWiki',
00075                           title='W1 Title')
00076         self.set_text(w1, "((%s))" % self.page1.Title())
00077         self.failIfWickedLink(w1, self.page1)
00078         
00079 
00080 def test_suite():
00081     suite = unittest.TestSuite()
00082     suite.addTest(unittest.makeSuite(TestWickedScope))
00083     return suite