Example #1
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)
Example #2
0
 def test_checkPermission_report_hit(self):
     from zope.interface import directlyProvides
     from karl.models.interfaces import IPeopleDirectory
     from karl.testing import DummyUsers
     from karl.testing import registerDummySecurityPolicy
     registerDummySecurityPolicy('phred', permissive=True)
     context = self._makeRoot()
     pd = context['people'] = self._makeContext()
     directlyProvides(pd, IPeopleDirectory)
     section = pd['section'] = self._makeContext()
     report = section['report'] = self._makeContext()
     users = context.users = DummyUsers()
     userinfo = users._by_id['phred'] = {}
     mailin = self._makeOne(context)
     info = {
         'author':
         'phred',
         'targets': [{
             'community': None,
             'tool': None,
             'report': 'section+report',
         }]
     }
     mailin.checkPermission(info)
     self.failIf('error' in info['targets'][0])
Example #3
0
 def test_jquery_list_my_communities_view(self):
     from zope.interface import Interface
     from karl.models.interfaces import ICommunityInfo
     context = testing.DummyModel()
     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 = ['Yi']
     request = testing.DummyRequest()
     karltesting.registerDummySecurityPolicy(
         'foo',
         groupids=[
         'group.community:yo:members',
         'group.community:yo:moderators',
         'group.community:yi:moderators',
         'group.community:yang:moderators'
         ]
         )
     karltesting.registerAdapter(DummyAdapterWithTitle, (Interface, Interface),
                             ICommunityInfo)
     result = self._callFUT(context, request)
     self.assertEqual(result['preferred'], ['Yi'])
     self.assertEqual(result['show_all'], True)
     self.assertEqual(len(result['my_communities']), 2)
Example #4
0
 def test_jquery_set_preferred_view(self):
     from zope.interface import Interface
     from karl.models.interfaces import ICommunityInfo
     context = testing.DummyModel()
     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']
     karltesting.registerDummySecurityPolicy(
         'foo',
         [
         'group.community:yo:members',
         'group.community:yo:moderators',
         'group.community:yi:moderators',
         ]
         )
     karltesting.registerAdapter(DummyAdapterWithTitle, (Interface, Interface),
                             ICommunityInfo)
     result = self._callFUT(context, request)
     self.assertEqual(result['my_communities'][0].context, yi)
 def test_w_overflow(self):
     from zope.interface import Interface
     from karl.models.interfaces import ICommunityInfo
     context = testing.DummyModel()
     profiles = context['profiles'] = testing.DummyModel()
     profiles['foo'] = testing.DummyModel()
     yo = testing.DummyModel()
     yo.title = 'Yo'
     yi = testing.DummyModel()
     yi.title = 'Yi'
     context['yo'] = yo
     context['yi'] = yi
     request = testing.DummyRequest()
     karltesting.registerDummySecurityPolicy(
         'foo',
         groupids=[
         'group.community:yo:members',
         'group.community:yo:moderators',
         'group.community:yi:moderators',
         'group.community:yang:moderators'
         ]
         )
     karltesting.registerAdapter(DummyAdapter, (Interface, Interface),
                             ICommunityInfo)
     result = self._callFUT(context, request)
     self.assertEqual(len(result), 2)
     self.assertEqual(result[0].context, yi)
Example #6
0
    def test_submit_form(self):
        from repoze.sendmail.interfaces import IMailDelivery
        karltesting.registerDummyRenderer("templates/join_community.pt")

        c = karltesting.DummyCommunity()
        c.moderator_names = set(["moderator1", "moderator2"])
        site = c.__parent__.__parent__
        profiles = site["profiles"] = testing.DummyModel()
        profiles["user"] = karltesting.DummyProfile()
        profiles["moderator1"] = karltesting.DummyProfile()
        profiles["moderator2"] = karltesting.DummyProfile()

        mailer = karltesting.DummyMailer()
        karltesting.registerUtility(mailer, IMailDelivery)

        karltesting.registerDummySecurityPolicy("user")
        request = testing.DummyRequest({
            "form.submitted": "1",
            "message": "Message text.",
        })
        karltesting.registerDummyRenderer(
            'karl.views:templates/email_join_community.pt')
        response = self._callFUT(c, request)

        self.assertEqual(response.location,
                         "http://example.com/communities/community/"
                         "?status_message=Your+request+has+been+sent+"
                         "to+the+moderators.")
        self.assertEqual(len(mailer), 1)
        msg = mailer.pop()
        self.assertEqual(msg.mto, ["*****@*****.**",
                                   "*****@*****.**"])
Example #7
0
 def test_handle_submit_propchanges(self):
     karltesting.registerDummySecurityPolicy('user2')
     context = testing.DummyModel(title='oldtitle',
                                  description='oldescription',
                                  default_tool='overview',
                                  modified_by='user1')
     request = testing.DummyRequest()
     self._register()
     view = self._makeOne(context, request)
     converted = {
         'title': u'Thetitle yo',
         'description': 'thedescription',
         'text': 'thetext',
         'security_state': 'public',
         'sendalert_default': False,
         'default_tool': 'files',
         'tags': 'thetesttag',
         'tools': [],
     }
     view.handle_submit(converted)
     self.assertEqual(context.title, 'Thetitle yo')
     self.assertEqual(context.description, 'thedescription')
     self.assertEqual(context.text, 'thetext')
     self.assertEqual(context.modified_by, 'user2')
     self.assertEqual(context.sendalert_default, False)
 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'}, layout_manager=mock.Mock())
     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')
     add_portlet = request.layout_manager.layout.add_portlet
     self.assertEqual(add_portlet.call_count, 1)
     self.assertEqual(add_portlet.call_args[0][0], 'my_communities')
Example #9
0
 def test_handle_submit_sharingchange(self):
     from karl.testing import DummyCatalog
     karltesting.registerDummySecurityPolicy('userid')
     context = testing.DummyModel(title='oldtitle',
                                  description='oldescription',
                                  default_tool='overview')
     context.__acl__ = ['a']
     context.staff_acl = ['1']
     context.catalog = DummyCatalog()
     request = testing.DummyRequest()
     self._register()
     workflow = self._registerDummyWorkflow()
     view = self._makeOne(context, request)
     converted = {
         'title': u'Thetitle yo',
         'description': 'thedescription',
         'text': 'thetext',
         'security_state': 'public',
         'sendalert_default': False,
         'default_tool': 'files',
         'tags': 'thetesttag',
         'tools': [],
     }
     view.handle_submit(converted)
     self.assertEqual(workflow.transitioned[0]['to_state'], 'public')
 def test_jquery_set_preferred_view(self):
     from zope.interface import Interface
     from karl.models.interfaces import ICommunityInfo
     context = testing.DummyModel()
     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']
     karltesting.registerDummySecurityPolicy(
         'foo',
         [
         'group.community:yo:members',
         'group.community:yo:moderators',
         'group.community:yi:moderators',
         ]
         )
     karltesting.registerAdapter(DummyAdapterWithTitle, (Interface, Interface),
                             ICommunityInfo)
     result = self._callFUT(context, request)
     self.assertEqual(result['my_communities'][0].context, yi)
 def test_set_preferred_communities(self):
     from zope.interface import Interface
     from karl.models.interfaces import ICommunityInfo
     from karl.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()
     karltesting.registerDummySecurityPolicy(
         'foo',
         groupids=[
         'group.community:yo:members',
         'group.community:yo:moderators',
         'group.community:yi:moderators',
         'group.community:yang:moderators'
         ]
         )
     karltesting.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')
 def test_jquery_list_my_communities_view(self):
     from zope.interface import Interface
     from karl.models.interfaces import ICommunityInfo
     context = testing.DummyModel()
     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 = ['Yi']
     request = testing.DummyRequest()
     karltesting.registerDummySecurityPolicy(
         'foo',
         groupids=[
         'group.community:yo:members',
         'group.community:yo:moderators',
         'group.community:yi:moderators',
         'group.community:yang:moderators'
         ]
         )
     karltesting.registerAdapter(DummyAdapterWithTitle, (Interface, Interface),
                             ICommunityInfo)
     result = self._callFUT(context, request)
     self.assertEqual(result['preferred'], ['Yi'])
     self.assertEqual(result['show_all'], True)
     self.assertEqual(len(result['my_communities']), 2)
Example #13
0
 def test_checkPermission_community_miss(self):
     from karl.testing import DummyUsers
     from karl.testing import registerDummySecurityPolicy
     registerDummySecurityPolicy('phred', permissive=False)
     context = self._makeRoot()
     communities = context['communities'] = self._makeContext()
     community = communities['testcommunity'] = self._makeContext()
     community['testtool'] = self._makeContext()
     users = context.users = DummyUsers()
     userinfo = users._by_id['phred'] = {}
     mailin = self._makeOne(context)
     info = {
         'author':
         'phred',
         'targets': [{
             'community': 'testcommunity',
             'tool': 'testtool',
             'report': None,
         }, {
             'error': 'Some other previous error',
         }],
     }
     mailin.checkPermission(info)
     self.assertEqual(info['targets'][0]['error'], 'Permission Denied')
     self.assertEqual(info['targets'][1]['error'],
                      'Some other previous error')
Example #14
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)
Example #15
0
    def test_submit_form(self):
        from repoze.sendmail.interfaces import IMailDelivery
        karltesting.registerDummyRenderer("templates/join_community.pt")

        c = karltesting.DummyCommunity()
        c.moderator_names = set(["moderator1", "moderator2"])
        site = c.__parent__.__parent__
        profiles = site["profiles"] = testing.DummyModel()
        profiles["user"] = karltesting.DummyProfile()
        profiles["moderator1"] = karltesting.DummyProfile()
        profiles["moderator2"] = karltesting.DummyProfile()

        mailer = karltesting.DummyMailer()
        karltesting.registerUtility(mailer, IMailDelivery)

        karltesting.registerDummySecurityPolicy("user")
        request = testing.DummyRequest({
            "form.submitted": "1",
            "message": "Message text.",
        })
        karltesting.registerDummyRenderer(
            'karl.views:templates/email_join_community.pt')
        response = self._callFUT(c, request)

        self.assertEqual(response.location,
                         "http://example.com/communities/community/"
                         "?status_message=Your+request+has+been+sent+"
                         "to+the+moderators.")
        self.assertEqual(len(mailer), 1)
        msg = mailer.pop()
        self.assertEqual(msg.mto, ["*****@*****.**",
                                   "*****@*****.**"])
Example #16
0
 def test_w_overflow(self):
     from zope.interface import Interface
     from karl.models.interfaces import ICommunityInfo
     context = testing.DummyModel()
     profiles = context['profiles'] = testing.DummyModel()
     profiles['foo'] = testing.DummyModel()
     yo = testing.DummyModel()
     yo.title = 'Yo'
     yi = testing.DummyModel()
     yi.title = 'Yi'
     context['yo'] = yo
     context['yi'] = yi
     request = testing.DummyRequest()
     karltesting.registerDummySecurityPolicy(
         'foo',
         groupids=[
         'group.community:yo:members',
         'group.community:yo:moderators',
         'group.community:yi:moderators',
         'group.community:yang:moderators'
         ]
         )
     karltesting.registerAdapter(DummyAdapter, (Interface, Interface),
                             ICommunityInfo)
     result = self._callFUT(context, request)
     self.assertEqual(len(result), 2)
     self.assertEqual(result[0].context, yi)
Example #17
0
 def test_set_preferred_communities(self):
     from zope.interface import Interface
     from karl.models.interfaces import ICommunityInfo
     from karl.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()
     karltesting.registerDummySecurityPolicy(
         'foo',
         groupids=[
         'group.community:yo:members',
         'group.community:yo:moderators',
         'group.community:yi:moderators',
         'group.community:yang:moderators'
         ]
         )
     karltesting.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')
Example #18
0
    def test_is_not_moderator(self):
        context = self._makeCommunity()
        context.moderator_names = ['foo', 'bar']
        request = testing.DummyRequest()
        karltesting.registerDummySecurityPolicy('dummy')
        adapter = self._makeOne(context, request)

        self.assertEqual(adapter.moderator, False)
Example #19
0
    def test_is_member_via_group(self):
        context = self._makeCommunity()
        context.member_names = ['a_group', 'foo']
        request = testing.DummyRequest()
        karltesting.registerDummySecurityPolicy('dummy', ['a_group'])
        adapter = self._makeOne(context, request)

        self.assertEqual(adapter.member, True)
Example #20
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)
Example #21
0
 def test_no_cookie_affiliate_user(self):
     from pyramid.url import resource_url
     context = testing.DummyModel()
     request = testing.DummyRequest()
     karltesting.registerDummySecurityPolicy('user',
             ('groups.KarlAffiliate',))
     response = self._callFUT(context, request)
     self._checkResponse(
         response, resource_url(context, request, 'all_communities.html'))
Example #22
0
 def test_w_normal_values(self):
     karltesting.registerDummySecurityPolicy('userid')
     request = testing.DummyRequest()
     context = testing.DummyModel()
     context.catalog = DummyCatalog()
     tags = context.tags = DummyTags()
     self._callFUT(context, request, ['a', 'b'])
     self.assertEqual(tags.getTags_called_with, None)
     self.assertEqual(tags.updated, ('docid', 'userid', ['a', 'b']))
Example #23
0
 def test_w_normal_values(self):
     karltesting.registerDummySecurityPolicy('userid')
     request = testing.DummyRequest()
     context = testing.DummyModel()
     context.catalog = DummyCatalog()
     tags = context.tags = DummyTags()
     self._callFUT(context, request, ['a', 'b'])
     self.assertEqual(tags.getTags_called_with, None)
     self.assertEqual(tags.updated, ('docid', 'userid', ['a', 'b']))
 def test_no_cookie_affiliate_user(self):
     from pyramid.url import resource_url
     context = testing.DummyModel()
     request = testing.DummyRequest()
     karltesting.registerDummySecurityPolicy('user',
             ('groups.KarlAffiliate',))
     response = self._callFUT(context, request)
     self._checkResponse(
         response, resource_url(context, request, 'all_communities.html'))
Example #25
0
 def test_already_member(self):
     self._register()
     context = self._makeCommunity()
     context.member_names = set(("userid",))
     context["profiles"] = testing.DummyModel()
     request = testing.DummyRequest()
     karltesting.registerDummySecurityPolicy("userid")
     info = self._callFUT(context, request)
     self.assertEqual(
         info["actions"], [("Edit", "edit.html"), ("Delete", "delete.html"), ("Advanced", "advanced.html")]
     )
Example #26
0
 def test_show_form(self):
     c = karltesting.DummyCommunity()
     site = c.__parent__.__parent__
     profiles = site["profiles"] = testing.DummyModel()
     profiles["user"] = karltesting.DummyProfile()
     karltesting.registerDummySecurityPolicy("user")
     request = testing.DummyRequest()
     response = self._callFUT(c, request)
     self.assertEqual(response["profile"], profiles["user"])
     self.assertEqual(response["community"], c)
     self.assertEqual(response["post_url"], "http://example.com/communities/community/join.html")
Example #27
0
 def test_already_member(self):
     self._register()
     context = self._makeCommunity()
     context.member_names = set(('userid',))
     request = testing.DummyRequest()
     karltesting.registerDummySecurityPolicy('userid')
     info = self._callFUT(context, request)
     self.assertEqual(info['actions'],
                      [('Edit', 'edit.html'),
                       ('Delete', 'delete.html'),
                       ('Advanced', 'advanced.html'),
                      ])
Example #28
0
 def test_show_form(self):
     c = karltesting.DummyCommunity()
     site = c.__parent__.__parent__
     profiles = site["profiles"] = testing.DummyModel()
     profiles["user"] = karltesting.DummyProfile()
     karltesting.registerDummySecurityPolicy("user")
     request = testing.DummyRequest()
     response = self._callFUT(c, request)
     self.assertEqual(response['profile'], profiles["user"])
     self.assertEqual(response['community'], c)
     self.assertEqual(response['post_url'],
                      "http://example.com/communities/community/join.html")
Example #29
0
    def test_w_string(self):
        karltesting.registerDummySecurityPolicy('userid')
        context = testing.DummyModel()
        context.catalog = DummyCatalog()
        tags = context.tags = DummyTags()
        request = testing.DummyRequest()

        self._callFUT(context, request, 'foo')

        self.assertEqual(tags.getTags_called_with,
                         (('docid',), ('userid',), None))
        self.assertEqual(tags.updated, ('docid', 'userid', ['foo']))
Example #30
0
    def test_no_existing_values(self):
        karltesting.registerDummySecurityPolicy('userid')
        context = testing.DummyModel()
        context.catalog = DummyCatalog()
        tags = context.tags = DummyTags()
        request = testing.DummyRequest()

        self._callFUT(context, request, ('foo', 'bar'))

        self.assertEqual(tags.getTags_called_with,
                         (('docid', ), ('userid', ), None))
        self.assertEqual(tags.updated, ('docid', 'userid', ['foo', 'bar']))
Example #31
0
 def test_show_form(self):
     c = karltesting.DummyCommunity()
     site = c.__parent__.__parent__
     profiles = site["profiles"] = testing.DummyModel()
     profiles["user"] = karltesting.DummyProfile()
     renderer = karltesting.registerDummyRenderer("templates/join_community.pt")
     karltesting.registerDummySecurityPolicy("user")
     request = testing.DummyRequest()
     karltesting.registerDummyRenderer("karl.views:templates/formfields.pt")
     self._callFUT(c, request)
     self.assertEqual(renderer.profile, profiles["user"])
     self.assertEqual(renderer.community, c)
     self.assertEqual(renderer.post_url, "http://example.com/communities/community/join.html")
Example #32
0
 def test_already_member(self):
     self._register()
     context = self._makeCommunity()
     context.member_names = set(('userid', ))
     context['profiles'] = testing.DummyModel()
     request = testing.DummyRequest()
     karltesting.registerDummySecurityPolicy('userid')
     info = self._callFUT(context, request)
     self.assertEqual(info['actions'], [
         ('Edit', 'edit.html'),
         ('Delete', 'delete.html'),
         ('Advanced', 'advanced.html'),
     ])
Example #33
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({})
     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/')
Example #34
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/')
Example #35
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/")
Example #36
0
 def setUp(self):
     from pyramid.testing import cleanUp
     config = cleanUp()
     config.add_static_view('static', 'karl.views:static')
     from zope.interface import Interface
     from karl.models.interfaces import ICommunityInfo
     from karl.models.interfaces import IGridEntryInfo
     karltesting.registerAdapter(DummyCommunityInfoAdapter,
                                 (Interface, Interface), ICommunityInfo)
     karltesting.registerAdapter(DummyGridInfoAdapter,
                                 (Interface, Interface), IGridEntryInfo)
     karltesting.registerDummySecurityPolicy(
         'userid', ('group.community:community1:member',
                    'group.community:community2:member',
                    'group.community:community3:member'))
Example #37
0
 def test_already_member(self):
     self._register()
     context = self._makeCommunity()
     context.member_names = set(('userid',))
     context['profiles'] = testing.DummyModel()
     request = testing.DummyRequest()
     request.layout_manager = mock.Mock()
     layout = request.layout_manager.layout
     layout.head_data = dict(panel_data={})
     karltesting.registerDummySecurityPolicy('userid')
     info = self._callFUT(context, request)
     self.assertEqual(info['actions'],
                      [('Edit', 'edit.html'),
                       ('Delete', 'delete.html'),
                       ('Advanced', 'advanced.html'),
                      ])
Example #38
0
 def test_makeCriteria_no_interfaces(self):
     from repoze.lemonade.interfaces import IContent
     from karl.testing import registerDummySecurityPolicy
     registerDummySecurityPolicy('fred', ['group:foo', 'group:bar'])
     request = testing.DummyRequest()
     context = testing.DummyModel()
     thing = self._makeOne(context, request, [], 'foo')
     criteria = thing._makeCriteria()
     self.assertEqual(criteria['texts'], 'foo')
     self.assertEqual(criteria['interfaces']['query'], [IContent])
     self.assertEqual(criteria['interfaces']['operator'], 'or')
     self.assertEqual(criteria['allowed']['query'], [
         'system.Everyone', 'system.Authenticated', 'fred', 'group:foo',
         'group:bar'
     ])
     self.assertEqual(criteria['allowed']['operator'], 'or')
Example #39
0
 def test_makeCriteria_no_interfaces(self):
     from repoze.lemonade.interfaces import IContent
     from karl.testing import registerDummySecurityPolicy
     registerDummySecurityPolicy('fred', ['group:foo', 'group:bar'])
     request = testing.DummyRequest()
     context = testing.DummyModel()
     thing = self._makeOne(context, request, [], 'foo')
     criteria = thing._makeCriteria()
     self.assertEqual(criteria['texts'], 'foo')
     self.assertEqual(criteria['interfaces']['query'], [IContent])
     self.assertEqual(criteria['interfaces']['operator'], 'or')
     self.assertEqual(criteria['allowed']['query'],
                      ['system.Everyone', 'system.Authenticated',
                       'fred', 'group:foo', 'group:bar']
                      )
     self.assertEqual(criteria['allowed']['operator'], 'or')
Example #40
0
 def setUp(self):
     from pyramid.testing import cleanUp
     config = cleanUp()
     config.add_static_view('static', 'karl.views:static')
     from zope.interface import Interface
     from karl.models.interfaces import ICommunityInfo
     from karl.models.interfaces import IGridEntryInfo
     karltesting.registerAdapter(DummyCommunityInfoAdapter,
                             (Interface, Interface),
                             ICommunityInfo)
     karltesting.registerAdapter(DummyGridInfoAdapter,
                             (Interface, Interface),
                             IGridEntryInfo)
     karltesting.registerDummySecurityPolicy('userid',
                                             ('group.community:community1:member',
                                              'group.community:community2:member',
                                              'group.community:community3:member'))
Example #41
0
 def test_makeCriteria(self):
     from karl.testing import registerDummySecurityPolicy
     registerDummySecurityPolicy('fred', ['group:foo', 'group:bar'])
     request = testing.DummyRequest()
     context = testing.DummyModel()
     from zope.interface import Interface
     thing = self._makeOne(context, request, [Interface], 'foo',
                           [Interface])
     criteria = thing._makeCriteria()
     self.assertEqual(criteria['texts'], 'foo')
     self.assertEqual(criteria['interfaces']['query'], [Interface])
     self.assertEqual(criteria['interfaces']['operator'], 'or')
     self.assertEqual(criteria['containment']['query'], [Interface])
     self.assertEqual(criteria['containment']['operator'], 'or')
     self.assertEqual(criteria['allowed']['query'],
                      ['system.Everyone', 'system.Authenticated',
                       'fred', 'group:foo', 'group:bar']
                      )
     self.assertEqual(criteria['allowed']['operator'], 'or')
Example #42
0
 def test_makeCriteria(self):
     from karl.testing import registerDummySecurityPolicy
     registerDummySecurityPolicy('fred', ['group:foo', 'group:bar'])
     request = testing.DummyRequest()
     context = testing.DummyModel()
     from zope.interface import Interface
     thing = self._makeOne(context, request, [Interface], 'foo',
                           [Interface])
     criteria = thing._makeCriteria()
     self.assertEqual(criteria['texts'], 'foo')
     self.assertEqual(criteria['interfaces']['query'], [Interface])
     self.assertEqual(criteria['interfaces']['operator'], 'or')
     self.assertEqual(criteria['containment']['query'], [Interface])
     self.assertEqual(criteria['containment']['operator'], 'or')
     self.assertEqual(criteria['allowed']['query'], [
         'system.Everyone', 'system.Authenticated', 'fred', 'group:foo',
         'group:bar'
     ])
     self.assertEqual(criteria['allowed']['operator'], 'or')
     self.assertFalse('path' in criteria)
Example #43
0
 def test_checkPermission_community_hit(self):
     from karl.testing import DummyUsers
     from karl.testing import registerDummySecurityPolicy
     registerDummySecurityPolicy('phred', permissive=True)
     context = self._makeRoot()
     communities = context['communities'] = self._makeContext()
     community = communities['testcommunity'] = self._makeContext()
     community['testtool'] = self._makeContext()
     users = context.users = DummyUsers()
     users._by_id['phred'] = {}
     mailin = self._makeOne(context)
     info = {'author': 'phred',
             'targets': [{
                 'community': 'testcommunity',
                 'tool': 'testtool',
                 'report': None,
             }]
             }
     mailin.checkPermission(info)
     self.failIf('error' in info['targets'][0])
Example #44
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')
Example #45
0
 def test_handle_submit_propchanges(self):
     karltesting.registerDummySecurityPolicy('user2')
     context = testing.DummyModel(
         title='oldtitle', description='oldescription',
         default_tool='overview', modified_by = 'user1')
     request = testing.DummyRequest()
     self._register()
     view = self._makeOne(context, request)
     converted = {'title':u'Thetitle yo',
                  'description':'thedescription',
                  'text':'thetext',
                  'security_state':'public',
                  'default_tool': 'files',
                  'tags': 'thetesttag',
                  'tools':[],
                   }
     view.handle_submit(converted)
     self.assertEqual(context.title, 'Thetitle yo')
     self.assertEqual(context.description, 'thedescription')
     self.assertEqual(context.text, 'thetext')
     self.assertEqual(context.modified_by, 'user2')
Example #46
0
 def test_checkPermission_community_hit(self):
     from karl.testing import DummyUsers
     from karl.testing import registerDummySecurityPolicy
     registerDummySecurityPolicy('phred', permissive=True)
     context = self._makeRoot()
     communities = context['communities'] = self._makeContext()
     community = communities['testcommunity'] = self._makeContext()
     community['testtool'] = self._makeContext()
     users = context.users = DummyUsers()
     userinfo = users._by_id['phred'] = {}
     mailin = self._makeOne(context)
     info = {
         'author':
         'phred',
         'targets': [{
             'community': 'testcommunity',
             'tool': 'testtool',
             'report': None,
         }]
     }
     mailin.checkPermission(info)
     self.failIf('error' in info['targets'][0])
Example #47
0
 def test_handle_submit_propchanges(self):
     karltesting.registerDummySecurityPolicy("user2")
     context = testing.DummyModel(
         title="oldtitle", description="oldescription", default_tool="overview", modified_by="user1"
     )
     request = testing.DummyRequest()
     self._register()
     view = self._makeOne(context, request)
     converted = {
         "title": u"Thetitle yo",
         "description": "thedescription",
         "text": "thetext",
         "security_state": "public",
         "default_tool": "files",
         "tags": "thetesttag",
         "tools": [],
     }
     view.handle_submit(converted)
     self.assertEqual(context.title, "Thetitle yo")
     self.assertEqual(context.description, "thedescription")
     self.assertEqual(context.text, "thetext")
     self.assertEqual(context.modified_by, "user2")
Example #48
0
    def test_crackHeaders_permission_denied(self):
        from karl.testing import registerDummySecurityPolicy
        registerDummySecurityPolicy('someuser', permissive=False)
        from karl.testing import DummyUsers
        context = self._makeRoot()
        context.users = DummyUsers()
        profile = self._makeContext()
        profile.__name__ = 'extant'
        by_email = {'*****@*****.**': profile}
        pf = context['profiles'] = self._makeContext()
        pf.getProfileByEmail = lambda email: by_email.get(email)
        cf = context['communities'] = self._makeContext()
        community = cf['testing'] = self._makeContext()
        tool = community['default'] = self._makeContext()
        mailin = self._makeOne(context)
        mailin.default_tool = 'default'
        message = DummyMessage()
        message.to = ('*****@*****.**', )
        message.from_ = ('*****@*****.**', )
        message.subject = 'subject'

        info = mailin.crackHeaders(message)
        self.assertEqual(info['targets'][0]['error'], 'Permission Denied')
Example #49
0
    def test_handle_submit_sharingchange(self):
        from karl.testing import DummyCatalog

        karltesting.registerDummySecurityPolicy("userid")
        context = testing.DummyModel(title="oldtitle", description="oldescription", default_tool="overview")
        context.__acl__ = ["a"]
        context.staff_acl = ["1"]
        context.catalog = DummyCatalog()
        request = testing.DummyRequest()
        self._register()
        workflow = self._registerDummyWorkflow()
        view = self._makeOne(context, request)
        converted = {
            "title": u"Thetitle yo",
            "description": "thedescription",
            "text": "thetext",
            "security_state": "public",
            "default_tool": "files",
            "tags": "thetesttag",
            "tools": [],
        }
        view.handle_submit(converted)
        self.assertEqual(workflow.transitioned[0]["to_state"], "public")
Example #50
0
    def test_crackHeaders_permission_denied(self):
        from karl.testing import registerDummySecurityPolicy
        registerDummySecurityPolicy('someuser', permissive=False)
        from karl.testing import DummyUsers
        context = self._makeRoot()
        context.users = DummyUsers()
        profile = self._makeContext()
        profile.__name__ = 'extant'
        by_email = {'*****@*****.**': profile}
        pf = context['profiles'] = self._makeContext()
        pf.getProfileByEmail = lambda email: by_email.get(email)
        cf = context['communities'] = self._makeContext()
        community = cf['testing'] = self._makeContext()
        community['default'] = self._makeContext()
        mailin = self._makeOne(context)
        mailin.default_tool = 'default'
        message = DummyMessage()
        message.to = ('*****@*****.**',)
        message.from_ = ('*****@*****.**',)
        message.subject = 'subject'

        info = mailin.crackHeaders(message)
        self.assertEqual(info['targets'][0]['error'], 'Permission Denied')
Example #51
0
 def test_handle_submit_sharingchange(self):
     from karl.testing import DummyCatalog
     karltesting.registerDummySecurityPolicy('userid')
     context = testing.DummyModel(
         title='oldtitle', description='oldescription',
         default_tool='overview')
     context.__acl__ = ['a']
     context.staff_acl = ['1']
     context.catalog = DummyCatalog()
     request = testing.DummyRequest()
     self._register()
     workflow = self._registerDummyWorkflow()
     view = self._makeOne(context, request)
     converted = {'title':u'Thetitle yo',
                  'description':'thedescription',
                  'text':'thetext',
                  'security_state':'public',
                  'default_tool': 'files',
                  'tags': 'thetesttag',
                  'tools':[],
                   }
     view.handle_submit(converted)
     self.assertEqual(workflow.transitioned[0]['to_state'], 'public')
Example #52
0
 def test_checkPermission_report_hit(self):
     from zope.interface import directlyProvides
     from karl.models.interfaces import IPeopleDirectory
     from karl.testing import DummyUsers
     from karl.testing import registerDummySecurityPolicy
     registerDummySecurityPolicy('phred', permissive=True)
     context = self._makeRoot()
     pd = context['people'] = self._makeContext()
     directlyProvides(pd, IPeopleDirectory)
     section = pd['section'] = self._makeContext()
     section['report'] = self._makeContext()
     users = context.users = DummyUsers()
     users._by_id['phred'] = {}
     mailin = self._makeOne(context)
     info = {'author': 'phred',
             'targets': [{
                 'community': None,
                 'tool': None,
                 'report': 'section+report',
             }]
             }
     mailin.checkPermission(info)
     self.failIf('error' in info['targets'][0])