本文整理汇总了Python中repoze.bfg.testing.registerAdapter函数的典型用法代码示例。如果您正苦于以下问题:Python registerAdapter函数的具体用法?Python registerAdapter怎么用?Python registerAdapter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了registerAdapter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_community_search
def test_community_search(self):
context = testing.DummyModel()
context.title = 'Citizens'
context.catalog = {}
context['profiles'] = profiles = testing.DummyModel()
profiles['tweedle dee'] = testing.DummyModel(title='Tweedle Dee')
from webob.multidict import MultiDict
from karl.models.interfaces import ICommunity
from zope.interface import directlyProvides
directlyProvides(context, ICommunity)
request = testing.DummyRequest(params=MultiDict({'body':'yo'}))
from zope.interface import Interface
from karl.models.interfaces import ICatalogSearch
from karl.views.interfaces import IAdvancedSearchResultsDisplay
from repoze.lemonade.testing import registerContentFactory
registerContentFactory(DummyContent, IDummyContent)
testing.registerAdapter(DummySearch, (Interface),
ICatalogSearch)
testing.registerAdapter(DummySearchResultsDisplay,
(Interface, Interface),
IAdvancedSearchResultsDisplay)
result = self._callFUT(context, request)
self.assertEqual(result['community'], 'Citizens')
self.assertEqual(result['terms'], ['yo'])
self.assertEqual(len(result['results']), 1)
示例2: test_creator_field
def test_creator_field(self):
from zope.interface import Interface
from zope.interface import implements
from opencore.models.interfaces import ICatalogSearch
from opencore.models.interfaces import IProfile
searched_for = {}
class Profile:
implements(IProfile)
profile = Profile()
profile.__name__ = 'admin'
class ProfileSearch:
def __init__(self, context):
pass
def __call__(self, **kw):
searched_for.update(kw)
return 1, [1], lambda x: profile
testing.registerAdapter(ProfileSearch, (Interface),
ICatalogSearch)
query, terms = self._callFUT({'creator': 'Ad'})
self.assertEquals(searched_for,
{'texts': 'Ad', 'interfaces': [IProfile]})
from repoze.lemonade.interfaces import IContent
self.assertEqual(query, {
'creator': {'query': ['admin'], 'operator': 'or'},
'interfaces': {'operator': 'or', 'query': []},
})
self.assertEqual(terms, ['Ad'])
示例3: test_handle_submit
def test_handle_submit(self):
self._register()
self._registerDummyWorkflow()
testing.registerDummySecurityPolicy('userid')
context = testing.DummyModel()
context.catalog = DummyCatalog()
context.tags = DummyTagEngine()
converted = {
'title':'a title',
'security_state': 'private',
'tags': ['thetesttag'],
}
from karl.content.interfaces import ICommunityFolder
from repoze.lemonade.interfaces import IContentFactory
testing.registerAdapter(lambda *arg: DummyCommunityFolder,
(ICommunityFolder,),
IContentFactory)
request = testing.DummyRequest()
controller = self._makeOne(context, request)
response = controller.handle_submit(converted)
self.assertEqual(response.location, 'http://example.com/a-title/')
self.assertEqual(context['a-title'].title, u'a title')
self.assertEqual(context['a-title'].userid, 'userid')
self.assertEqual(context.tags.updated,
[(None, 'userid', ['thetesttag'])])
示例4: test_jquery_set_preferred_view
def test_jquery_set_preferred_view(self):
from zope.interface import Interface
from opencore.models.interfaces import ICommunityInfo
context = testing.DummyModel(communities_name='communities')
communities = context['communities'] = testing.DummyModel()
yo = testing.DummyModel()
yo.title = 'Yo'
yi = testing.DummyModel()
yi.title = 'Yi'
communities['yo'] = yo
communities['yi'] = yi
profiles = context['profiles'] = testing.DummyModel()
foo = profiles['foo'] = testing.DummyModel()
foo.preferred_communities = None
request = testing.DummyRequest()
request.params = RequestParamsWithGetall()
request.params['preferred[]'] = ['Yi']
testing.registerDummySecurityPolicy(
'foo',
[
'group.community:yo:members',
'group.community:yo:moderators',
'group.community:yi:moderators',
]
)
testing.registerAdapter(DummyAdapterWithTitle, (Interface, Interface),
ICommunityInfo)
result = self._callFUT(context, request)
self.assertEqual(result['my_communities'][0].context, yi)
示例5: test_set_preferred_communities
def test_set_preferred_communities(self):
from zope.interface import Interface
from opencore.models.interfaces import ICommunityInfo
from opencore.views.communities import get_preferred_communities
context = testing.DummyModel()
yo = testing.DummyModel()
yo.title = 'Yo'
yi = testing.DummyModel()
yi.title = 'Yi'
context['yo'] = yo
context['yi'] = yi
profiles = context['profiles'] = testing.DummyModel()
foo = profiles['foo'] = testing.DummyModel()
foo.preferred_communities = None
request = testing.DummyRequest()
testing.registerDummySecurityPolicy(
'foo',
groupids=[
'group.community:yo:members',
'group.community:yo:moderators',
'group.community:yi:moderators',
'group.community:yang:moderators'
]
)
testing.registerAdapter(DummyAdapter, (Interface, Interface),
ICommunityInfo)
communities = ['yi']
self._callFUT(context, request, communities)
result = get_preferred_communities(context, request)
self.assertEqual(len(result), 1)
self.assertEqual(result[0], 'yi')
示例6: test_respect_alert_prefs
def test_respect_alert_prefs(self):
from repoze.sendmail.interfaces import IMailDelivery
from repoze.bfg.interfaces import IRequest
from karl.models.interfaces import IProfile
from karl.testing import DummyMailer
mailer = DummyMailer()
testing.registerUtility(mailer, IMailDelivery)
community = DummyCommunity()
community["foo"] = context = testing.DummyModel()
directlyProvides(context, IDummy)
site = community.__parent__.__parent__
site["profiles"] = profiles = testing.DummyModel()
profiles["a"] = DummyProfile()
profiles["b"] = DummyProfile()
profiles["b"].set_alerts_preference(community.__name__,
IProfile.ALERT_DIGEST)
profiles["c"] = DummyProfile()
profiles["c"].set_alerts_preference(community.__name__,
IProfile.ALERT_NEVER)
community.member_names = set(("a","c",))
community.moderator_names = set(("b",))
request = testing.DummyRequest()
testing.registerAdapter(DummyEmailAlertAdapter,
(IDummy, IProfile, IRequest), IAlert)
self._get_instance().emit(context, request)
self.assertEqual(1, len(mailer))
self.assertEqual(1, len(profiles["b"]._pending_alerts))
示例7: test_handle_submit
def test_handle_submit(self):
controller = self._makeOne(self.context, self.request)
converted = {}
# first set up the simple fields to submit
for fieldname, value in profile_data.items():
if fieldname == 'photo':
continue
converted[fieldname] = value
# then set up with the photo
from karl.models.interfaces import IImageFile
from karl.models.tests.test_image import one_pixel_jpeg as dummy_photo
from karl.testing import DummyUpload
from karl.views.tests.test_file import DummyImageFile
from repoze.lemonade.interfaces import IContentFactory
testing.registerAdapter(lambda *arg: DummyImageFile, (IImageFile,),
IContentFactory)
converted['photo'] = DummyUpload(filename='test.jpg',
mimetype='image/jpeg',
data=dummy_photo)
# finally submit
controller.handle_submit(converted)
for fieldname, value in profile_data.items():
if fieldname == 'photo':
continue
self.assertEqual(getattr(self.context, fieldname), value)
self.failUnless('photo.jpg' in self.context)
self.failUnless(len(self.context['photo.jpg'].stream.read()) > 1)
# make sure the www. URLs get prepended
converted['website'] = 'www.example.com'
controller.handle_submit(converted)
self.assertEqual(self.context.website, 'http://www.example.com')
示例8: test_processMessage_reply_no_attachments
def test_processMessage_reply_no_attachments(self):
from repoze.bfg.testing import DummyModel
from repoze.bfg.testing import registerAdapter
from repoze.bfg.testing import registerModels
from karl.adapters.interfaces import IMailinHandler
INFO = {'community': 'testing',
'tool': 'random',
'in_reply_to': '7FFFFFFF', # token for docid 0
'author': 'phreddy',
'subject': 'Feedback'
}
handler = DummyHandler()
def _handlerFactory(context):
handler.context = context
return handler
registerAdapter(_handlerFactory, DummyModel, IMailinHandler)
mailin = self._makeOne()
catalog = mailin.root.catalog = DummyCatalog()
cf = mailin.root['communities'] = DummyModel()
testing = cf['testing'] = DummyModel()
tool = testing['random'] = DummyModel()
entry = tool['entry'] = DummyModel()
comments = entry['comments'] = DummyModel()
catalog.document_map._map[0] = '/communities/testing/random/entry'
registerModels({'/communities/testing/random/entry': entry})
message = DummyMessage()
text = 'This entry stinks!'
attachments = ()
mailin.processMessage(message, INFO, text, attachments)
self.assertEqual(handler.context, entry)
self.assertEqual(handler.handle_args,
(message, INFO, text, attachments))
示例9: _registerLayoutProvider
def _registerLayoutProvider(self, **kw):
from repoze.bfg.testing import registerAdapter
from zope.interface import Interface
from karl.views.interfaces import ILayoutProvider
registerAdapter(DummyLayoutProvider,
(Interface, Interface),
ILayoutProvider)
示例10: setUp
def setUp(self):
cleanUp()
# Set up a dummy wiki
from karl.content.interfaces import IWiki
from karl.testing import DummyCommunity
from karl.testing import DummyProfile
from zope.interface import directlyProvides
community = DummyCommunity()
wiki = community["wiki"] = testing.DummyModel()
directlyProvides(wiki, IWiki)
wiki.title = "Wiki Title"
site = community.__parent__.__parent__
profiles = site["profiles"] = testing.DummyModel()
chris = profiles["chris"] = DummyProfile()
chris.title = "Chris Rossi"
self.context = wiki
# Register dummy catalog
from zope.interface import Interface
from karl.models.interfaces import ICatalogSearch
testing.registerAdapter(dummy_catalog_search, Interface, ICatalogSearch)
# Register atom entry adapter
from karl.views.interfaces import IAtomEntry
from karl.views.atom import GenericAtomEntry
testing.registerAdapter(GenericAtomEntry, (Interface, Interface), IAtomEntry)
示例11: test_processMessage_report
def test_processMessage_report(self):
from zope.interface import directlyProvides
from repoze.bfg.testing import DummyModel
from repoze.bfg.testing import registerAdapter
from karl.adapters.interfaces import IMailinHandler
from karl.models.interfaces import IPeopleDirectory
INFO = {'report': 'section+testing',
'community': None,
'tool': None,
'author': 'phreddy',
'subject': 'Feedback'
}
handler = DummyHandler()
def _handlerFactory(context):
handler.context = context
return handler
registerAdapter(_handlerFactory, DummyModel, IMailinHandler)
mailin = self._makeOne()
catalog = mailin.root.catalog = DummyCatalog()
pd = mailin.root['people'] = DummyModel()
directlyProvides(pd, IPeopleDirectory)
section = pd['section'] = DummyModel()
testing = section['testing'] = DummyModel()
message = DummyMessage()
text = 'This entry stinks!'
attachments = [('foo.txt', 'text/plain', 'My attachment')]
mailin.processMessage(message, INFO, text, attachments)
self.failUnless(handler.context is testing)
self.assertEqual(handler.handle_args,
(message, INFO, text, attachments))
示例12: test_user_home_path_w_subpath
def test_user_home_path_w_subpath(self):
from zope.interface import Interface
from zope.interface import directlyProvides
from repoze.bfg.interfaces import ITraverserFactory
from karl.testing import DummyCommunity
from karl.testing import DummyProfile
testing.registerDummySecurityPolicy("userid")
c = DummyCommunity()
site = c.__parent__.__parent__
directlyProvides(site, Interface)
c["foo"] = foo = testing.DummyModel()
site["profiles"] = profiles = testing.DummyModel()
profiles["userid"] = profile = DummyProfile()
profile.home_path = "/communities/community/foo/bar/baz"
testing.registerAdapter(
dummy_traverser_factory, Interface, ITraverserFactory
)
from karl.views.utils import get_user_home
request = testing.DummyRequest()
# Test from site root
target, extra_path = get_user_home(site, request)
self.failUnless(foo is target)
self.assertEqual(['bar', 'baz'], extra_path)
# Test from arbitrary point in tree
target, extra_path = get_user_home(c, request)
self.failUnless(foo is target)
self.assertEqual(['bar', 'baz'], extra_path)
示例13: test_with_parameter_withresults
def test_with_parameter_withresults(self):
def dummy_factory1(context, request, term):
pass
def dummy_factory2(context, request, term):
def results():
return 1, [1], lambda x: testing.DummyModel(title='yo')
return results
dummy_factory1.livesearch = dummy_factory2.livesearch = True
from repoze.lemonade.testing import registerListItem
from karl.models.interfaces import IGroupSearchFactory
registerListItem(IGroupSearchFactory, dummy_factory1, 'dummy1',
title='Dummy1', sort_key=1)
registerListItem(IGroupSearchFactory, dummy_factory2, 'dummy2',
title='Dummy2', sort_key=2)
context = testing.DummyModel()
request = testing.DummyRequest()
request.params = {
'val': 'somesearch',
}
def dummy_adapter(context, request):
return dict(title=context.title)
from karl.views.interfaces import ILiveSearchEntry
testing.registerAdapter(dummy_adapter,
(testing.DummyModel, testing.DummyRequest),
ILiveSearchEntry)
response = self._callFUT(context, request)
self.assertEqual(response.status, '200 OK')
from simplejson import loads
results = loads(response.body)
self.assertEqual(len(results), 1)
self.assertEqual(results[0]['title'], 'yo')
self.assertEqual(response.content_type, 'application/json')
示例14: test_comment_ordering
def test_comment_ordering(self):
context = DummyBlogEntry()
context['comments']['2'] = DummyComment(now=1233149510, text=u'before')
from karl.models.interfaces import ISite
from zope.interface import directlyProvides
from karl.testing import DummyProfile
directlyProvides(context, ISite)
from karl.content.interfaces import IBlog
from zope.interface import alsoProvides
alsoProvides(context, IBlog)
context['profiles'] = profiles = testing.DummyModel()
profiles['dummy'] = DummyProfile(title='Dummy Profile')
request = testing.DummyRequest()
def dummy_byline_info(context, request):
return context
from zope.interface import Interface
from karl.content.views.interfaces import IBylineInfo
testing.registerAdapter(dummy_byline_info, (Interface, Interface),
IBylineInfo)
self._register()
from karl.utilities.interfaces import IKarlDates
testing.registerUtility(dummy, IKarlDates)
renderer = testing.registerDummyRenderer('templates/show_blogentry.pt')
self._callFUT(context, request)
self.assertEqual(len(renderer.comments), 2)
self.assertEqual('before', renderer.comments[0]['text'])
self.assertEqual('sometext', renderer.comments[1]['text'])
示例15: setUp
def setUp(self):
cleanUp()
# Set up a dummy blog
from karl.content.interfaces import IBlog
from karl.testing import DummyCommunity
from karl.testing import DummyProfile
from zope.interface import directlyProvides
community = DummyCommunity()
blog = community["blog"] = testing.DummyModel()
directlyProvides(blog, IBlog)
blog.title = "Blog Title"
site = community.__parent__.__parent__
profiles = site["profiles"] = testing.DummyModel()
chris = profiles["chris"] = DummyProfile()
chris.title = "Chris Rossi"
self.context = blog
# Register dummy catalog
from zope.interface import Interface
from karl.models.interfaces import ICatalogSearch
testing.registerAdapter(dummy_catalog_search, Interface,
ICatalogSearch)
# Register blog entry adapter
from karl.views.interfaces import IAtomEntry
from karl.content.interfaces import IBlogEntry
from karl.views.atom import GenericAtomEntry
testing.registerAdapter(GenericAtomEntry, (IBlogEntry, Interface),
IAtomEntry)
testing.registerDummyRenderer('karl.views:templates/atomfeed.pt')