Esempio n. 1
0
 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'),
     ])
Esempio n. 2
0
 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)
Esempio n. 3
0
 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})
Esempio n. 4
0
    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'])
Esempio n. 5
0
    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')
Esempio n. 6
0
    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)
Esempio n. 7
0
 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)
Esempio n. 8
0
    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))
Esempio n. 9
0
    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)
Esempio n. 10
0
    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)
Esempio n. 11
0
 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)
Esempio n. 12
0
 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)
Esempio n. 13
0
 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
Esempio n. 14
0
 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)
Esempio n. 15
0
 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)
Esempio n. 16
0
    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)
Esempio n. 17
0
    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')
Esempio n. 18
0
    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)
Esempio n. 19
0
 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')
Esempio n. 20
0
    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)
Esempio n. 21
0
    def test_with_both_params_no_tags_tool(self):
        root = testing.DummyModel()
        path = root['path'] = testing.DummyModel()
        to = path['to'] = testing.DummyModel()
        target = to['item'] = testing.DummyModel()
        target.title = 'Target'
        testing.registerModels({'/path/to/item': target})
        request = testing.DummyRequest()
        request.params = {'tag': 'tag1', 'docid': '1'}
        context = testing.DummyModel()
        context.catalog = DummyCatalog()

        result = self._callFUT(context, request)

        self.assertEqual(result['tag'], 'tag1')
        self.assertEqual(result['url'], 'http://example.com/path/to/item/')
        self.assertEqual(result['title'], 'Target')
        self.assertEqual(len(result['users']), 0)
Esempio n. 22
0
 def test_it(self):
     from zope.interface import Interface
     from opencore.models.interfaces import ICatalogSearch
     from opencore.models.adapters import CatalogSearch
     from opencore.testing import DummyProfile
     catalog = opentesting.DummyCatalog({1:'/foo', 2:'/bar'})
     testing.registerAdapter(CatalogSearch, (Interface), ICatalogSearch)
     context = testing.DummyModel()
     context.catalog = catalog
     foo = DummyProfile()
     testing.registerModels({'/foo':foo})
     request = testing.DummyRequest(
         params={'titlestartswith':'A'})
     renderer = testing.registerDummyRenderer('templates/profiles.pt')
     self._callFUT(context, request)
     profiles = list(renderer.profiles)
     self.assertEqual(len(profiles), 1)
     self.assertEqual(profiles[0], foo)
Esempio n. 23
0
 def test_it(self):
     from zope.interface import Interface
     from karl.models.interfaces import ICommunity
     import datetime
     context = testing.DummyModel(title='thetitle')
     directlyProvides(context, ICommunity)
     context.member_names = context.moderator_names = set()
     context.title = "Community"
     foo = testing.DummyModel()
     foo.modified = datetime.datetime(2009, 9, 2, 10, 28, 0)
     request = testing.DummyRequest()
     renderer = testing.registerDummyRenderer('templates/atom.pt')
     from karl.models.interfaces import ICatalogSearch
     from karl.models.adapters import CatalogSearch
     catalog = karltesting.DummyCatalog({1:'/foo'})
     testing.registerModels({'/foo':foo})
     context.catalog = catalog
     testing.registerAdapter(CatalogSearch, (Interface), ICatalogSearch)
     self._callFUT(context, request)
Esempio n. 24
0
 def test_unfound_model(self):
     from repoze.bfg.interfaces import ILogger
     class DummyLogger:
         def warn(self, msg):
             self.msg = msg
     logger = DummyLogger()
     testing.registerUtility(logger, ILogger, 'repoze.bfg.debug')
     a = testing.DummyModel()
     b = testing.DummyModel()
     testing.registerModels({'/a':a})
     context = testing.DummyModel()
     context.catalog = karltesting.DummyCatalog({1:'/a', 2:'/b'})
     adapter = self._makeOne(context)
     num, docids, resolver = adapter()
     self.assertEqual(num, 2)
     self.assertEqual(list(docids), [1, 2])
     results = filter(None, map(resolver, docids))
     self.assertEqual(results, [a])
     self.assertEqual(logger.msg, 'Model missing: /b')
Esempio n. 25
0
    def test_with_tag_multiple_users(self):
        from zope.interface import directlyProvides
        from repoze.lemonade.testing import registerContentFactory
        from opencore.models.interfaces import ICommunity
        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 == 'community'
            return ('dummy', 'dummy2')
        tags.getUsers = _getUsers
        def _getRelated(tag, degree=1, community=None, user=None):
            assert tag == 'tag1'
            assert degree == 1
            assert community == 'community'
            assert user is None
            return []
        tags.getRelatedTags = _getRelated
        root.catalog = oitesting.DummyCatalog({1:'/community'})
        context = root['community'] = testing.DummyModel()
        context.title = 'title'
        testing.registerModels({'/community': context})
        directlyProvides(context, ICommunity)
        registerContentFactory(testing.DummyModel, ICommunity)
        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/community/')
        self.assertEqual(entry['tagusers_count'], '2 people')
        self.assertEqual(entry['type'], 'Community')
        self.assertEqual(entry['tagusers_href'],
                         'http://example.com/community/'
                         'tagusers.html?tag=tag1&docid=1')
        self.assertEqual(len(result['related']), 0)
Esempio n. 26
0
 def _makeCommunity(self):
     from zope.interface import directlyProvides
     from karl.models.interfaces import ICommunity
     community = testing.DummyModel(title='thetitle')
     catalog = karltesting.DummyCatalog({1: '/profiles/phred',
                                         2: '/profiles/bharney',
                                         3: '/profiles/wylma',
                                        })
     phred = testing.DummyModel(__name__='phred')
     bharney = testing.DummyModel(__name__='bharney')
     wylma = testing.DummyModel(__name__='wylma')
     testing.registerModels({'/profiles/phred':phred,
                             '/profiles/bharney':bharney,
                             '/profiles/wylma':wylma,
                            })
     community.catalog = catalog
     community.member_names = set(['phred', 'bharney', 'wylma'])
     community.moderator_names = set(['bharney'])
     directlyProvides(community, ICommunity)
     return community
Esempio n. 27
0
 def test_recent_items(self):
     from zope.interface import Interface
     from zope.interface import directlyProvides
     from karl.models.interfaces import ICommunity
     from karl.models.interfaces import ICatalogSearch
     from karl.models.interfaces import IGridEntryInfo
     testing.registerAdapter(DummySearchAdapter, Interface, ICatalogSearch)
     testing.registerAdapter(DummyAdapter,
                             (Interface, Interface), IGridEntryInfo)
     f = testing.DummyModel()
     testing.registerModels({'/communities/1/file':f})
     context = testing.DummyModel()
     directlyProvides(context, ICommunity)
     context.searchresults = [f]
     context.catalog = karltesting.DummyCatalog({1:'/communities/1/file'})
     request = testing.DummyRequest()
     api = self._makeOne(context, request)
     recent_items = api.recent_items
     self.assertEqual(len(recent_items), 1)
     self.assertEqual(recent_items[0].context, f)
Esempio n. 28
0
    def test_with_tag(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 _getRelated(tag, degree=1, community=None, user=None):
            assert tag == 'tag1'
            assert degree == 1
            assert community is None
            assert user == 'phred'
            return ['tag2', 'tag3']
        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']

        result = self._callFUT(context, request)

        self.assertEqual(tags.getItems_called_with,
                        (('tag1',), ('phred',), None))
        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/profiles/phred/')
        self.assertEqual(entry['tagusers_count'], '1 person')
        self.assertEqual(entry['type'], 'Person')
        self.assertEqual(entry['tagusers_href'],
                         'http://example.com/profiles/phred/'
                         'tagusers.html?tag=tag1&docid=1')
        self.assertEqual(len(result['related']), 2)
        self.assertEqual(result['related'][0], 'tag2')
        self.assertEqual(result['related'][1], 'tag3')
Esempio n. 29
0
    def test_with_tag(self):
        from zope.interface import directlyProvides
        from repoze.lemonade.testing import registerContentFactory
        from karl.models.interfaces import ICommunity
        root = testing.DummyModel()
        tags = root.tags = DummyTags()
        def _getRelated(tag, degree=1, community=None, user=None):
            assert tag == 'tag1'
            assert degree == 1
            assert community == 'community'
            assert user is None
            return ['tag2', 'tag3']
        tags.getRelatedTags = _getRelated
        root.catalog = karltesting.DummyCatalog({1:'/community'})
        context = root['community'] = testing.DummyModel()
        context.title = 'title'
        testing.registerModels({'/community': context})
        directlyProvides(context, ICommunity)
        registerContentFactory(testing.DummyModel, ICommunity)
        request = testing.DummyRequest()
        request.subpath = [u'tag1']
        renderer = testing.registerDummyRenderer(
                                'templates/community_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/community/')
        self.assertEqual(entry['tagusers_count'], '1 person')
        self.assertEqual(entry['type'], 'Community')
        self.assertEqual(entry['tagusers_href'],
                         'http://example.com/community/'
                         'tagusers.html?tag=tag1&docid=1')
        self.assertEqual(len(renderer.related), 2)
        self.assertEqual(renderer.related[0], 'tag2')
        self.assertEqual(renderer.related[1], 'tag3')
Esempio n. 30
0
 def test_w_groups(self):
     self._register()
     testing.registerDummySecurityPolicy('admin',
                                         ['group.community:yum:bar'])
     context = testing.DummyModel()
     profiles = context['profiles'] = testing.DummyModel()
     profiles['admin'] = testing.DummyModel()
     yum = testing.DummyModel()
     context['yum'] = yum
     yum.title = 'Yum!'
     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')