示例#1
0
 def test_it(self):
     context = testing.DummyModel()
     context.catalog = karltesting.DummyCatalog({})
     adapter = self._makeOne(context)
     num, docids, resolver = adapter()
     self.assertEqual(num, 0)
     self.assertEqual(list(docids), [])
示例#2
0
    def test_handle_submit_success(self):
        self._register()
        from zope.interface import directlyProvides
        from karl.models.interfaces import ISite
        from karl.models.interfaces import ICommunity
        from repoze.lemonade.interfaces import IContentFactory
        context = testing.DummyModel()
        directlyProvides(context, ISite)
        tags = context.tags = testing.DummyModel()
        _tagged = []
        def _update(item, user, tags):
            _tagged.append((item, user, tags))
        tags.update = _update
        karltesting.registerDummySecurityPolicy('userid')
        workflow = self._registerDummyWorkflow()
        karltesting.registerAdapter(lambda *arg: DummyCommunity,
                                    (ICommunity,),
                                    IContentFactory)
        dummy_tool_factory = DummyToolFactory()
        self._registerAddables([{'name':'blog', 'title':'blog',
                                 'component':dummy_tool_factory}])
        context.users = karltesting.DummyUsers({})
        context.catalog = karltesting.DummyCatalog({1:'/foo'})
        request = testing.DummyRequest()
        controller = self._makeOne(context, request)
        converted = {'title':'Thetitle yo',
                     'description':'thedescription',
                     'text':'thetext',
                     'tools': ['blog'],
                     'security_state': 'private',
                     'tags': ['foo'],
                     'default_tool': 'blog',
                     }
        result = controller.handle_submit(converted)
        rl = 'http://example.com/thetitle-yo/members/add_existing.html'
        self.failUnless(result.location.startswith(rl))
        community = context['thetitle-yo']
        self.assertEqual(community.title, 'Thetitle yo')
        self.assertEqual(community.description, 'thedescription')
        self.assertEqual(community.text, 'thetext')
        self.assertEqual(community.default_tool, 'blog')
        self.assertEqual(community.creator, 'userid')
        self.assertEqual(community.modified_by, 'userid')
        self.assertEqual(
            context.users.added_groups,
            [('userid', 'moderators'), ('userid', 'members') ]
        )
        self.assertEqual(dummy_tool_factory.added, True)
        self.assertEqual(len(_tagged), 1)
        self.assertEqual(_tagged[0][0], None)
        self.assertEqual(_tagged[0][1], 'userid')
        self.assertEqual(_tagged[0][2], ['foo'])
        self.assertEqual(workflow.transitioned[0]['to_state'], 'private')

        # try again w/ an invalid default_tool
        converted['title'] = 'Another title yo'
        converted['default_tool'] = 'wiki'
        result = controller.handle_submit(converted)
        community = context['another-title-yo']
        self.failUnless(community.default_tool is None)
示例#3
0
 def test_docid(self):
     from karl import testing as karltesting
     request = testing.DummyRequest()
     context = testing.DummyModel()
     context.catalog = karltesting.DummyCatalog()
     adapter = self._makeOne(context, request)
     self.assertEqual(adapter.docid, None)
示例#4
0
    def test_tags_with_counts(self):
        from zope.interface import directlyProvides
        from karl import testing as karltesting
        context = testing.DummyModel()
        request = testing.DummyRequest()
        context.catalog = karltesting.DummyCatalog()

        def dummy_getTagObjects(*args, **kw):
            self.assertEqual(kw['items'], (123,))
            return [testing.DummyModel(name='tag1', user='******'),
                    testing.DummyModel(name='tag1', user='******'),
                    testing.DummyModel(name='tag2', user='******'),
                   ]
        dummy_tags = testing.DummyModel()
        dummy_tags.getTagObjects = dummy_getTagObjects
        context.tags = dummy_tags
        directlyProvides(context, DummyInterface)
        adapter = self._makeOne(context, request)
        adapter._docid = 123
        adapter.username = u'admin'

        alltaginfo = adapter.tagswithcounts

        self.assertEqual(len(alltaginfo), 2, alltaginfo)
        self.assertEqual(alltaginfo[0]['count'], 2)
        self.assertEqual(alltaginfo[0]['tag'], u'tag1')
        self.assertEqual(alltaginfo[0]['snippet'], '')
        self.assertEqual(alltaginfo[1]['count'], 1)
        self.assertEqual(alltaginfo[1]['tag'], u'tag2')
        self.assertEqual(alltaginfo[1]['snippet'], 'nondeleteable')
示例#5
0
文件: test_tags.py 项目: lslaz1/karl
    def test_with_tag_multiple_users(self):
        from zope.interface import directlyProvides
        from repoze.lemonade.testing import registerContentFactory
        context = testing.DummyModel()
        context.title = 'title'
        karltesting.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)
示例#6
0
 def test_unfound_docid(self):
     context = testing.DummyModel()
     context.catalog = karltesting.DummyCatalog({})
     request = testing.DummyRequest()
     adapter = self._makeOne(context, request)
     num, docids, resolver = adapter()
     self.assertEqual(resolver(123), None)
示例#7
0
    def test_excludes_inactive(self):
        from datetime import datetime
        from datetime import timedelta
        from karl.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 = karltesting.DummyCatalog(
                                      {1: '/foo', 2: '/bar'})
        foo = testing.DummyModel(content_modified=now - timedelta(1))
        bar = testing.DummyModel(content_modified=now - timedelta(32))
        karltesting.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')
示例#8
0
    def test_with_group_filter(self):
        from BTrees import family32
        from zope.interface import directlyProvides
        from karl.models.interfaces import IPeopleReportGroupFilter
        from karl.models.interfaces import ISite
        site = testing.DummyModel()
        directlyProvides(site, ISite)
        site['people'] = testing.DummyModel()
        site['people'].catalog = karltesting.DummyCatalog({2: None, 3: None})
        index = DummyFieldIndex({
            'A': family32.IF.TreeSet([1]),
            'B': family32.IF.TreeSet([2, 5]),
            'C': family32.IF.TreeSet([3]),
            'D': family32.IF.TreeSet([4, 6]),
            })
        index.family = family32
        site['people'].catalog['lastnamestartswith'] = index

        report = testing.DummyModel()
        staff = report['office'] = testing.DummyModel(values=['staff'])
        directlyProvides(staff, IPeopleReportGroupFilter)
        site['report'] = report
        obj = self._makeOne(report)
        active = obj.get_active_letters()
        self.assertEqual(active, set(['B', 'C']))
        self.assertEqual(site['people'].catalog.queries, [{
            'groups': {'operator': 'or', 'query': ['staff']},
            }])
示例#9
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'})
     karltesting.registerModels({'/foo':foo})
     community.catalog = catalog
     return community
示例#10
0
 def _makeCommunity(self, results=None):
     from zope.interface import directlyProvides
     from karl.models.interfaces import ICommunity
     if results is None:
         results = [{}]
     community = testing.DummyModel(title='Interests Align')
     catalog = karltesting.DummyCatalog(*results)
     community.catalog = catalog
     directlyProvides(community, ICommunity)
     return community
示例#11
0
    def test_not_confirmed(self):
        from karl.testing import registerLayoutProvider
        registerLayoutProvider()

        request = testing.DummyRequest()
        context = testing.DummyModel(title='oldtitle')
        context.__name__  = 'thename'
        context.catalog = karltesting.DummyCatalog({})
        context.users = karltesting.DummyUsers({})
        karltesting.registerDummyRenderer('templates/delete_resource.pt')
        self._register()
        response = self._callFUT(context, request)
        self.assertTrue(isinstance(response, dict))
示例#12
0
 def test_it(self):
     from zope.interface import directlyProvides
     from karl.models.interfaces import ISite
     site = testing.DummyModel()
     directlyProvides(site, ISite)
     peopledir = testing.DummyModel()
     site['people'] = peopledir
     site['people'].catalog = karltesting.DummyCatalog({})
     context = testing.DummyModel()
     site['obj'] = context
     adapter = self._makeOne(context)
     num, docids, resolver = adapter()
     self.assertEqual(num, 0)
     self.assertEqual(list(docids), [])
示例#13
0
 def test_confirmed(self):
     request = testing.DummyRequest({'confirm':'1'})
     context = testing.DummyModel(title='oldtitle')
     parent = DummyParent()
     parent['thename'] = context
     parent.catalog = karltesting.DummyCatalog({})
     parent.users = karltesting.DummyUsers({})
     parent['profiles'] = testing.DummyModel()
     karltesting.registerDummyRenderer('templates/delete_resource.pt')
     self._register()
     karltesting.registerDummySecurityPolicy('userid')
     response = self._callFUT(context, request)
     self.assertEqual(parent.deleted, 'thename')
     self.assertEqual(response.location, 'http://example.com/')
示例#14
0
    def test_no_filters(self):
        site = testing.DummyModel()
        from karl.models.interfaces import ISite
        from zope.interface import directlyProvides
        directlyProvides(site, ISite)
        site['people'] = testing.DummyModel()
        site['people'].catalog = karltesting.DummyCatalog()
        index = DummyFieldIndex({'A': None, 'M': None})
        site['people'].catalog['lastnamestartswith'] = index

        report = testing.DummyModel()
        site['report'] = report
        obj = self._makeOne(report)
        active = obj.get_active_letters()
        self.assertEqual(active, set(['A', 'M']))
示例#15
0
 def test_wo_groups(self):
     self._register()
     context = testing.DummyModel()
     profiles = context['profiles'] = testing.DummyModel()
     profiles[None] = testing.DummyModel()
     context.catalog = karltesting.DummyCatalog({1: '/foo'})
     foo = testing.DummyModel()
     karltesting.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')
示例#16
0
文件: test_tags.py 项目: lslaz1/karl
    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'
        karltesting.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)
示例#17
0
文件: test_tags.py 项目: lslaz1/karl
    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'
        karltesting.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(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'], '2 people')
        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']), 0)
示例#18
0
 def test_unfound_model(self):
     from pyramid.interfaces import IDebugLogger
     class DummyLogger:
         def warn(self, msg):
             self.msg = msg
     logger = DummyLogger()
     karltesting.registerUtility(logger, IDebugLogger)
     a = testing.DummyModel()
     b = testing.DummyModel()
     karltesting.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')
示例#19
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')
     karltesting.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
示例#20
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
     karltesting.registerAdapter(DummySearchAdapter, Interface,
                                 ICatalogSearch)
     karltesting.registerAdapter(DummyAdapter, (Interface, Interface),
                                 IGridEntryInfo)
     f = testing.DummyModel()
     karltesting.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)
示例#21
0
 def test_w_groups(self):
     self._register()
     karltesting.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 = karltesting.DummyCatalog({1: '/foo'})
     foo = testing.DummyModel()
     karltesting.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')
示例#22
0
文件: test_tags.py 项目: lslaz1/karl
    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'
        karltesting.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'], '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(result['related']), 0)
示例#23
0
文件: test_tags.py 项目: lslaz1/karl
    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'
        karltesting.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'])