• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python testing.registerModels函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中repoze.bfg.testing.registerModels函数的典型用法代码示例。如果您正苦于以下问题:Python registerModels函数的具体用法?Python registerModels怎么用?Python registerModels使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了registerModels函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_already_member

 def test_already_member(self):
     from zope.interface import Interface
     from zope.interface import directlyProvides
     from karl.models.interfaces import ICommunity
     context = testing.DummyModel(title='thetitle')
     context.member_names = set(('userid',))
     context.moderator_names = set()
     directlyProvides(context, ICommunity)
     foo = testing.DummyModel()
     request = testing.DummyRequest()
     renderer = testing.registerDummyRenderer('templates/community.pt')
     from karl.models.interfaces import ICommunityInfo
     from karl.models.interfaces import ICatalogSearch
     from karl.models.interfaces import IGridEntryInfo
     from karl.models.adapters import CatalogSearch
     catalog = karltesting.DummyCatalog({1:'/foo'})
     testing.registerModels({'/foo':foo})
     context.catalog = catalog
     testing.registerAdapter(DummyGridEntryAdapter, (Interface, Interface),
                             IGridEntryInfo)
     testing.registerAdapter(DummyAdapter, (Interface, Interface),
                             ICommunityInfo)
     testing.registerAdapter(CatalogSearch, (Interface), ICatalogSearch)
     testing.registerDummySecurityPolicy('userid')
     self._callFUT(context, request)
     self.assertEqual(len(renderer.actions), 2)
     self.assertEqual(renderer.actions, [
         ('Edit', 'edit.html'),
         ('Delete', 'delete.html'),
     ])
开发者ID:boothead,项目名称:karl,代码行数:30,代码来源:test_community.py


示例2: test_it_dryrun

 def test_it_dryrun(self):
     from zope.interface import directlyProvides
     from karl.models.interfaces import ISite
     a = testing.DummyModel()
     b = testing.DummyModel()
     testing.registerModels({'a':a, 'b':b})
     L = []
     output = L.append
     site = testing.DummyModel()
     site.update_indexes = lambda *arg: L.append('updated')
     catalog = DummyCatalog({'a':1, 'b':2})
     directlyProvides(site, ISite)
     site.catalog = catalog
     transaction = DummyTransaction()
     self._callFUT(site, output=output, transaction=transaction,
                   dry_run=True)
     self.assertEqual(catalog.reindexed, [1, 2])
     self.assertEqual(L,
                      ['updating indexes',
                       'updated',
                       '*** aborting ***',
                       'reindexing a',
                       'reindexing b',
                       '*** aborting ***'])
     self.assertEqual(transaction.aborted, 2)
     self.assertEqual(transaction.committed, 0)
开发者ID:boothead,项目名称:karl,代码行数:26,代码来源:test_catalog.py


示例3: test_it_with_indexes

 def test_it_with_indexes(self):
     from zope.interface import directlyProvides
     from karl.models.interfaces import ISite
     a = testing.DummyModel()
     testing.registerModels({'a':a})
     L = []
     output = L.append
     site = testing.DummyModel()
     site.update_indexes = lambda *arg: L.append('updated')
     catalog = DummyCatalog({'a':1})
     catalog.index = DummyIndex()
     directlyProvides(site, ISite)
     site.catalog = catalog
     transaction = DummyTransaction()
     self._callFUT(site, output=output, transaction=transaction,
                   indexes=('index',))
     self.assertEqual(L,
                      ['updating indexes',
                       'updated',
                       '*** committing ***',
                       "reindexing only indexes ('index',)",
                       'reindexing a',
                       '*** committing ***'])
     self.assertEqual(transaction.committed, 2)
     self.assertEqual(catalog.index.indexed, {1:a})
开发者ID:boothead,项目名称:karl,代码行数:25,代码来源:test_catalog.py


示例4: test_with_both_params_w_tags_tool

    def test_with_both_params_w_tags_tool(self):
        root = testing.DummyModel()
        root.catalog = karltesting.DummyCatalog({1:'/community/target'})
        context = root['community'] = testing.DummyModel()
        target = context['target'] = testing.DummyModel()
        target.title = 'Target'
        testing.registerModels({'/community/target': target})
        tags = root.tags = DummyTags()
        def _getUsers(tags=None, items=None, community=None):
            assert list(tags) == ['tag1']
            assert list(items) == [1]
            assert community == 'community'
            return ['phred']
        tags.getUsers = _getUsers
        def _getTags(items=None, users=None, community=None):
            assert list(items) == [1]
            assert list(users) == ['phred']
            assert community == 'community'
            return ['tag2']
        tags.getTags = _getTags
        profiles = root['profiles'] = testing.DummyModel()
        p1 = profiles['phred'] = testing.DummyModel()
        p1.firstname, p1.lastname = 'J. Phred', 'Bloggs'
        request = testing.DummyRequest()
        request.params = {'tag': 'tag1', 'docid': '1'}

        result = self._callFUT(context, request)

        self.assertEqual(len(result['users']), 1)
        self.assertEqual(result['users'][0]['login'], 'phred')
        self.assertEqual(result['users'][0]['fullname'], 'J. Phred Bloggs')
        self.assertEqual(result['users'][0]['also'], ['tag2'])
开发者ID:cguardia,项目名称:karl,代码行数:32,代码来源:test_tags.py


示例5: test_excludes_inactive

    def test_excludes_inactive(self):
        from datetime import datetime
        from datetime import timedelta
        from opencore.utils import coarse_datetime_repr
        now = datetime.now()
        today = now.today()
        six_months_ago = today - timedelta(days=180)
        self._set_TODAY(today)
        self._register()
        context = testing.DummyModel()
        profiles = context['profiles'] = testing.DummyModel()
        profiles[None] = testing.DummyModel()
        catalog = context.catalog = oitesting.DummyCatalog(
                                      {1: '/foo', 2: '/bar'})
        foo = testing.DummyModel(content_modified=now - timedelta(1))
        bar = testing.DummyModel(content_modified=now - timedelta(32))
        testing.registerModels({'/foo': foo,
                                '/bar': bar,
                               })
        request = testing.DummyRequest()

        info = self._callFUT(context, request)

        self.assertEqual(len(catalog.queries), 1)
        query = catalog.queries[0]
        self.assertEqual(query['content_modified'],
                         (coarse_datetime_repr(six_months_ago), None))

        communities = info['communities']
        self.assertEqual(len(communities), 2)
        self.assertEqual(communities[0].context, foo)
        self.assertEqual(communities[1].context, bar)
        self.failUnless(info['actions'])
        _checkCookie(request, 'active')
开发者ID:lonetwin,项目名称:opencore,代码行数:34,代码来源:test_communities.py


示例6: test_with_tag_multiple_users

    def test_with_tag_multiple_users(self):
        from zope.interface import directlyProvides
        from repoze.lemonade.testing import registerContentFactory
        context = testing.DummyModel()
        context.title = 'title'
        testing.registerModels({'/foo': context})
        directlyProvides(context, IDummyBlogEntry)
        registerContentFactory(testing.DummyModel, IDummyBlogEntry)
        tags = context.tags = DummyTags(users=('dummy', 'dummy2'))
        def _getRelated(tag, degree=1, community=None, user=None):
            assert tag == 'tag1'
            assert degree == 1
            assert community is None
            assert user is None
            return []
        tags.getRelatedTags = _getRelated
        context.catalog = karltesting.DummyCatalog({1:'/foo'})
        request = testing.DummyRequest()
        request.subpath = [u'tag1']

        result = self._callFUT(context, request)

        self.assertEqual(result['tag'], u'tag1')
        self.assertEqual(len(result['entries']), 1)
        entry = result['entries'][0]
        self.assertEqual(entry['description'], '')
        self.assertEqual(entry['title'], 'title')
        self.assertEqual(entry['href'], 'http://example.com/')
        self.assertEqual(entry['tagusers_count'], '2 people')
        self.assertEqual(entry['type'], 'Blog Entry')
        self.assertEqual(entry['tagusers_href'],
                         'http://example.com/tagusers.html?tag=tag1&docid=1')
        self.assertEqual(len(result['related']), 0)
开发者ID:cguardia,项目名称:karl,代码行数:33,代码来源:test_tags.py


示例7: test_it_pathre

 def test_it_pathre(self):
     import re
     from zope.interface import directlyProvides
     from opencore.models.interfaces import ISite
     a = testing.DummyModel()
     b = testing.DummyModel()
     testing.registerModels({'a':a, 'b':b})
     L = []
     output = L.append
     site = testing.DummyModel()
     site.update_indexes = lambda *arg: L.append('updated')
     catalog = DummyCatalog({'a':1, 'b':2})
     directlyProvides(site, ISite)
     site.catalog = catalog
     transaction = DummyTransaction()
     self._callFUT(site, output=output, transaction=transaction,
                   path_re=re.compile('a'))
     self.assertEqual(catalog.reindexed, [1])
     self.assertEqual(L,
                      ['updating indexes',
                       'updated',
                       '*** committing ***',
                       'reindexing a',
                       '*** committing ***'])
     self.assertEqual(transaction.committed, 2)
开发者ID:amarandon,项目名称:opencore,代码行数:25,代码来源:test_catalog.py


示例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))
开发者ID:boothead,项目名称:karl,代码行数:34,代码来源:test_mailin.py


示例9: test_quarantine_message

    def test_quarantine_message(self):
        from repoze.bfg.testing import DummyModel
        from repoze.bfg.testing import registerModels
        info = {'targets': [{'community': 'testing',
                             'tool': 'random',
                             'in_reply_to': '7FFFFFFF', # token for docid 0
                             'author': 'phreddy',
                             }],
                'subject': 'Feedback',
                'exception': 'Not witty enough',
               }
        text = 'This entry stinks!'
        attachments = ()
        message = DummyMessage(info, text, attachments)
        self._set_up_queue([message,])

        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})

        mailin()
        q_message, error = self.queue.quarantined[0]
        self.assertEqual(q_message, message)
        self.failUnless('Not witty enough' in error)
        self.assertEqual(len(self.mailer), 1)
开发者ID:cguardia,项目名称:karl,代码行数:31,代码来源:test_mailin.py


示例10: test_process_message_reply_w_attachment

    def test_process_message_reply_w_attachment(self):
        from repoze.bfg.testing import DummyModel
        from repoze.bfg.testing import registerModels
        info = {'targets': [{'report': None,
                             'community': 'testing',
                             'tool': 'random',
                             'in_reply_to': '7FFFFFFF', # token for docid 0
                             }],
                'author': 'phreddy',
                'subject': 'Feedback'
               }
        text = 'This entry stinks!'
        attachments = ()
        message = DummyMessage(info, text, attachments)
        self._set_up_queue([message,])

        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})

        mailin()
        mailin.close()

        self.assertEqual(len(self.handlers), 1)
        handler = self.handlers[0]
        self.assertEqual(handler.context, entry)
        self.assertEqual(handler.handle_args,
                         (message, info, text, attachments))
        self.assertEqual(len(self.mailer), 0)
开发者ID:cguardia,项目名称:karl,代码行数:35,代码来源:test_mailin.py


示例11: test_my_communities

 def test_my_communities(self):
     from zope.interface import Interface
     from karl.models.interfaces import ICommunityInfo
     from karl.models.interfaces import ICatalogSearch
     from karl.models.interfaces import ILetterManager
     from karl.models.adapters import CatalogSearch
     catalog = karltesting.DummyCatalog({1:'/foo'})
     testing.registerAdapter(DummyAdapter, (Interface, Interface),
                             ICommunityInfo)
     testing.registerAdapter(CatalogSearch, (Interface), ICatalogSearch)
     testing.registerAdapter(DummyLetterManager, Interface,
                             ILetterManager)
     testing.registerDummySecurityPolicy('admin',
                                         ['group.community:yum:bar'])
     context = testing.DummyModel()
     yum = testing.DummyModel()
     context['yum'] = yum
     yum.title = 'Yum!'
     context.catalog = catalog
     foo = testing.DummyModel()
     testing.registerModels({'/foo':foo})
     request = testing.DummyRequest(
         params={'titlestartswith':'A'})
     renderer = testing.registerDummyRenderer('templates/communities.pt')
     self._callFUT(context, request)
     self.assertEqual(len(renderer.communities), 1)
     self.assertEqual(renderer.communities[0].context, foo)
     self.failUnless(renderer.communities)
     self.failUnless(renderer.actions)
     self.failUnless(renderer.my_communities[0].context, yum)
开发者ID:boothead,项目名称:karl,代码行数:30,代码来源:test_communities.py


示例12: test_valid

 def test_valid(self):
     from karl.views.baseforms import AppState
     from karl.views.baseforms import HomePath
     from repoze.bfg.testing import DummyModel
     from repoze.bfg.testing import registerModels
     registerModels({'item0': DummyModel()})
     state = AppState(context=DummyModel())
     val = HomePath()
     val.to_python("item0", state)
开发者ID:boothead,项目名称:karl,代码行数:9,代码来源:test_baseforms.py


示例13: _makeCommunity

 def _makeCommunity(self):
     from zope.interface import directlyProvides
     from karl.models.interfaces import ICommunity
     community = testing.DummyModel(title='thetitle')
     directlyProvides(community, ICommunity)
     foo = testing.DummyModel(__name__='foo')
     catalog = karltesting.DummyCatalog({1:'/foo'})
     testing.registerModels({'/foo':foo})
     community.catalog = catalog
     return community
开发者ID:cguardia,项目名称:karl,代码行数:10,代码来源:test_community.py


示例14: test_invalid_path

 def test_invalid_path(self):
     from karl.views.baseforms import AppState
     from karl.views.baseforms import HomePath
     from repoze.bfg.testing import DummyModel
     from formencode.validators import Invalid
     from repoze.bfg.testing import registerModels
     registerModels({})
     state = AppState(context=DummyModel())
     val = HomePath()
     self.assertRaises(Invalid, val.to_python, "item0", state)
开发者ID:boothead,项目名称:karl,代码行数:10,代码来源:test_baseforms.py


示例15: test_avoid_circular_redirect

 def test_avoid_circular_redirect(self):
     from karl.views.baseforms import AppState
     from karl.views.baseforms import HomePath
     from repoze.bfg.testing import DummyModel
     from formencode.validators import Invalid
     from repoze.bfg.testing import registerModels
     site = DummyModel()
     registerModels({'//': site})
     state = AppState(context=site)
     val = HomePath()
     self.assertRaises(Invalid, val.to_python, "//", state)
开发者ID:boothead,项目名称:karl,代码行数:11,代码来源:test_baseforms.py


示例16: test___call___w_catalog_good_docid_not_in_community

    def test___call___w_catalog_good_docid_not_in_community(self):
        from zope.interface import directlyProvides
        from karl.models.interfaces import ICommunity
        context = testing.DummyModel()
        site = context.site = testing.DummyModel()
        profiles = site['profiles'] = testing.DummyModel()
        user1 = profiles['user1'] = testing.DummyModel()
        testing.registerModels({'/profiles/user1': user1})
        catalog = site.catalog = testing.DummyModel()
        catalog.document_map = DummyDocumentMap({123: '/profiles/user1'})

        adapter = self._makeOne(context)

        self.assertEqual(adapter(123), None)
开发者ID:boothead,项目名称:karl,代码行数:14,代码来源:tests.py


示例17: test___call___w_catalog_good_docid

    def test___call___w_catalog_good_docid(self):
        from zope.interface import directlyProvides
        from karl.models.interfaces import ICommunity
        context = testing.DummyModel()
        site = context.site = testing.DummyModel()
        commune = site['commune'] = testing.DummyModel()
        directlyProvides(commune, ICommunity)
        doc = commune['doc'] = testing.DummyModel()
        testing.registerModels({'/commune/doc': doc})
        catalog = site.catalog = testing.DummyModel()
        catalog.document_map = DummyDocumentMap({123: '/commune/doc'})

        adapter = self._makeOne(context)

        self.assertEqual(adapter(123), 'commune')
开发者ID:boothead,项目名称:karl,代码行数:15,代码来源:tests.py


示例18: test_with_both_params_no_tags_tool

    def test_with_both_params_no_tags_tool(self):
        root = testing.DummyModel()
        root.catalog = karltesting.DummyCatalog({1:'/community/target'})
        context = root['community'] = testing.DummyModel()
        target = context['target'] = testing.DummyModel()
        target.title = 'Target'
        testing.registerModels({'/community/target': target})
        request = testing.DummyRequest()
        request.params = {'tag': 'tag1', 'docid': '1'}

        result = self._callFUT(context, request)

        self.assertEqual(result['tag'], 'tag1')
        self.assertEqual(result['url'], 'http://example.com/community/target/')
        self.assertEqual(result['title'], 'Target')
        self.assertEqual(len(result['users']), 0)
开发者ID:cguardia,项目名称:karl,代码行数:16,代码来源:test_tags.py


示例19: test_wo_groups

 def test_wo_groups(self):
     self._register()
     context = testing.DummyModel()
     profiles = context['profiles'] = testing.DummyModel()
     profiles[None] = testing.DummyModel()
     context.catalog = oitesting.DummyCatalog({1:'/foo'})
     foo = testing.DummyModel()
     testing.registerModels({'/foo':foo})
     request = testing.DummyRequest(
         params={'titlestartswith':'A'})
     info = self._callFUT(context, request)
     communities = info['communities']
     self.assertEqual(len(communities), 1)
     self.assertEqual(communities[0].context, foo)
     self.failUnless(communities)
     self.failUnless(info['actions'])
     _checkCookie(request, 'all')
开发者ID:lonetwin,项目名称:opencore,代码行数:17,代码来源:test_communities.py


示例20: test_with_tag_multiple_users

    def test_with_tag_multiple_users(self):
        from zope.interface import directlyProvides
        from repoze.lemonade.testing import registerContentFactory
        from karl.models.interfaces import IProfile
        root = testing.DummyModel()
        tags = root.tags = DummyTags()
        def _getUsers(tags=None, items=None, community=None):
            assert list(tags) == ['tag1']
            assert list(items) == [1]
            assert community is None
            return ('dummy', 'dummy2')
        tags.getUsers = _getUsers
        def _getRelated(tag, degree=1, community=None, user=None):
            assert tag == 'tag1'
            assert degree == 1
            assert community is None
            assert user == 'phred'
            return []
        tags.getRelatedTags = _getRelated
        root.catalog = karltesting.DummyCatalog({1:'/profiles/phred'})
        profiles = root['profiles'] = testing.DummyModel()
        context = profiles['phred'] = testing.DummyModel()
        context.title = 'title'
        testing.registerModels({'/profiles/phred': context})
        directlyProvides(context, IProfile)
        registerContentFactory(testing.DummyModel, IProfile)
        request = testing.DummyRequest()
        request.subpath = [u'tag1']
        renderer = testing.registerDummyRenderer(
                                'templates/profile_showtag.pt')

        self._callFUT(context, request)

        self.assertEqual(renderer.tag, u'tag1')
        self.assertEqual(len(renderer.entries), 1)
        entry = renderer.entries[0]
        self.assertEqual(entry['description'], '')
        self.assertEqual(entry['title'], 'title')
        self.assertEqual(entry['href'], 'http://example.com/profiles/phred/')
        self.assertEqual(entry['tagusers_count'], '2 people')
        self.assertEqual(entry['type'], 'Profile')
        self.assertEqual(entry['tagusers_href'],
                         'http://example.com/profiles/phred/'
                         'tagusers.html?tag=tag1&docid=1')
        self.assertEqual(len(renderer.related), 0)
开发者ID:boothead,项目名称:karl,代码行数:45,代码来源:test_tags.py



注:本文中的repoze.bfg.testing.registerModels函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testing.registerUtility函数代码示例发布时间:2022-05-26
下一篇:
Python testing.registerDummySecurityPolicy函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap