Пример #1
0
    def test_with_security_policy(self):
        from karl.content.interfaces import IBlogEntry
        from karl.content.interfaces import IBlog
        from zope.interface import alsoProvides
        context = DummyBlogEntry()
        context.sessions = DummySessions()
        context.__parent__.sessions = DummySessions()
        alsoProvides(context, IBlog)
        alsoProvides(context, IBlogEntry)
        request = testing.DummyRequest()
        request.environ['repoze.browserid'] = 1

        def dummy_byline_info(context, request):
            return context

        from zope.interface import Interface
        from karl.content.views.interfaces import IBylineInfo
        karl.testing.registerAdapter(dummy_byline_info, (Interface, Interface),
                                     IBylineInfo)
        self._register()
        karl.testing.registerDummySecurityPolicy(permissive=False)

        response = self._callFUT(context, request)

        self.assertEqual(response['comments'][0]['edit_url'], None)
Пример #2
0
 def _makeContext(self):
     from karl.testing import DummyCommunity
     community = DummyCommunity()
     community.__parent__.__parent__.sessions = DummySessions()
     context = community['testing'] = testing.DummyModel()
     context['profiles'] = testing.DummyModel()
     return context
Пример #3
0
    def test_comment_ordering(self):
        context = DummyBlogEntry()
        context.sessions = DummySessions()
        context['comments']['2'] = DummyComment(now=1233149510, text=u'before')
        from karl.models.interfaces import ISite
        from zope.interface import directlyProvides
        from karl.testing import DummyProfile
        directlyProvides(context, ISite)
        from karl.content.interfaces import IBlog
        from zope.interface import alsoProvides

        alsoProvides(context, IBlog)
        context['profiles'] = profiles = testing.DummyModel()
        profiles['dummy'] = DummyProfile(title='Dummy Profile')
        request = testing.DummyRequest()
        request.environ['repoze.browserid'] = 1

        def dummy_byline_info(context, request):
            return context

        from zope.interface import Interface
        from karl.content.views.interfaces import IBylineInfo
        karl.testing.registerAdapter(dummy_byline_info, (Interface, Interface),
                                     IBylineInfo)
        self._register()
        from karl.utilities.interfaces import IKarlDates
        karl.testing.registerUtility(dummy, IKarlDates)
        response = self._callFUT(context, request)
        self.assertEqual(len(response['comments']), 2)
        self.assertEqual('before', response['comments'][0]['text'])
        self.assertEqual('sometext', response['comments'][1]['text'])
Пример #4
0
 def setUp(self):
     cleanUp()
     context = testing.DummyModel(sessions=DummySessions())
     self.context = context
     request = testing.DummyRequest()
     request.environ['repoze.browserid'] = '1'
     self.request = request
Пример #5
0
    def test_no_security_policy(self):
        context = DummyBlogEntry()
        context.sessions = DummySessions()
        from karl.models.interfaces import ISite
        from zope.interface import directlyProvides
        from karl.testing import DummyProfile
        directlyProvides(context, ISite)
        from karl.content.interfaces import IBlog
        from zope.interface import alsoProvides

        alsoProvides(context, IBlog)
        context['profiles'] = profiles = testing.DummyModel()
        profiles['dummy'] = DummyProfile(title='Dummy Profile')
        request = testing.DummyRequest()
        request.environ['repoze.browserid'] = 1

        def dummy_byline_info(context, request):
            return context

        from zope.interface import Interface
        from karl.content.views.interfaces import IBylineInfo
        karl.testing.registerAdapter(dummy_byline_info, (Interface, Interface),
                                     IBylineInfo)
        self._register()
        from karl.utilities.interfaces import IKarlDates
        karl.testing.registerUtility(dummy, IKarlDates)
        response = self._callFUT(context, request)
        self.assertEqual(len(response['comments']), 1)
        c0 = response['comments'][0]
        self.assertEqual(c0['text'], 'sometext')

        self.assertEqual(d1, response['comments'][0]['date'])
        self.assertEqual(c0['author_name'], 'Dummy Profile')
        self.assertEqual(response['comments'][0]['edit_url'],
                         'http://example.com/blogentry/comments/1/edit.html')
Пример #6
0
 def test_handle_submit(self):
     from karl.models.interfaces import ISite
     from zope.interface import directlyProvides
     site = testing.DummyModel(sessions=DummySessions())
     directlyProvides(site, ISite)
     from karl.testing import DummyCatalog
     from karl.models.adapters import CatalogSearch
     from karl.models.interfaces import ICatalogSearch
     from zope.interface import Interface
     site.catalog = DummyCatalog()
     karl.testing.registerAdapter(CatalogSearch, (Interface), ICatalogSearch)
     context = self.context
     site['newsfolder'] = context
     tags = DummyTags()
     site.tags = tags
     controller = self._makeOne(context, self.request)
     from karl.content.views.newsitem import _now
     from karl.testing import DummyUpload
     attachment1 = DummyUpload(filename='test1.txt')
     attachment2 = DummyUpload(filename=r'C:\My Documents\Ha Ha\test2.txt')
     photo = DummyUpload(filename='test.jpg',
                         mimetype='image/jpeg',
                         data=dummy_photo)
     now = _now()
     converted = {
         'title': 'Foo',
         'text': 'text',
         'publication_date': now,
         'caption': 'caption',
         'tags': ['tag1', 'tag2'],
         'attachments': [attachment1, attachment2],
         'photo': photo
         }
     from karl.content.interfaces import INewsItem
     from karl.content.interfaces import ICommunityFile
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(DummyNewsItem, INewsItem)
     registerContentFactory(DummyFile, ICommunityFile)
     response = controller.handle_submit(converted)
     newsitem_url = 'http://example.com/newsfolder/foo/'
     self.assertEqual(response.location, newsitem_url)
     self.failUnless('foo' in context)
     newsitem = context['foo']
     self.assertEqual(newsitem.title, 'Foo')
     self.assertEqual(newsitem.text, 'text')
     self.assertEqual(newsitem.publication_date, now)
     self.assertEqual(newsitem.caption, 'caption')
     self.failUnless('attachments' in newsitem)
     attachments_folder = newsitem['attachments']
     self.failUnless('test1.txt' in attachments_folder)
     self.failUnless('test2.txt' in attachments_folder)
     self.assertEqual(attachments_folder['test1.txt'].filename,
                      'test1.txt')
     self.assertEqual(attachments_folder['test2.txt'].filename,
                      'test2.txt')
     self.failUnless('photo' in newsitem)
     self.assertEqual(newsitem['photo'].data, dummy_photo)
     self.assertEqual(site.tags._called_with[1]['tags'],
                      ['tag1', 'tag2'])
Пример #7
0
    def test_handle_submit(self):
        context = self.context

        # register dummy IPage content factory
        def factory(title, text, description, creator):
            page = DummyPage(title=title,
                             text=text,
                             description=description,
                             creator=creator)
            page['attachments'] = DummyModel()
            return page

        registerContentFactory(factory, IPage)

        # set up attachments
        from karl.content.interfaces import ICommunityFile
        from karl.testing import DummyFile
        registerContentFactory(DummyFile, ICommunityFile)
        from karl.testing import DummyUpload
        attachment1 = DummyUpload(filename='test1.txt')
        attachment2 = DummyUpload(filename=r"C:\My Documents\Ha Ha\test2.txt")

        # set up tags infrastructure
        from karl.testing import DummyCommunity
        from karl.testing import DummyTags
        community = DummyCommunity()
        site = community.__parent__.__parent__
        site.sessions = DummySessions()
        site.catalog = DummyCatalog()
        site.tags = DummyTags()
        community['pages'] = context

        # construct converted dict and call handle_submit
        converted = {
            'title': u'Page Title',
            'text': u'page text',
            'tags': [u'foo', u'bar'],
            'attachments': [attachment1, attachment2],
        }
        context.ordering = DummyOrdering()
        controller = self._makeOne(context, self.request)
        controller.handle_submit(converted)

        # make sure everything looks good
        # basic fields
        self.failUnless(u'page-title' in context)
        page = context['page-title']
        self.assertEqual(page.title, u'Page Title')
        self.assertEqual(page.text, u'page text')
        # attachments
        attachments_folder = page['attachments']
        self.failUnless('test1.txt' in attachments_folder)
        self.failUnless('test2.txt' in attachments_folder)
        self.assertEqual(attachments_folder['test1.txt'].filename, 'test1.txt')
        self.assertEqual(attachments_folder['test2.txt'].filename, 'test2.txt')
        # ordering
        self.assertEqual(context.ordering.names_added, ['page-title'])
        # tags
        self.assertEqual(site.tags._called_with[1]['tags'], [u'foo', u'bar'])
Пример #8
0
 def setUp(self):
     cleanUp()
     self._register()
     context = DummyNewsItem(sessions=DummySessions())
     context.title = 'Foo'
     self.context = context
     request = testing.DummyRequest()
     request.environ['repoze.browserid'] = '1'
     self.request = request
Пример #9
0
 def setUp(self):
     testing.cleanUp()
     request = testing.DummyRequest()
     request.environ['repoze.browserid'] = '1'
     self.request = request
     sessions = DummySessions()
     context = testing.DummyModel(sessions=sessions)
     self.context = context
     registerLayoutProvider()
Пример #10
0
 def setUp(self):
     cleanUp()
     self._register()
     context = testing.DummyModel(sessions=DummySessions())
     self.context = context
     request = testing.DummyRequest()
     request.layout_manager = mock.Mock()
     request.layout_manager.layout.head_data = dict(panel_data={})
     request.environ['repoze.browserid'] = '1'
     self.request = request
Пример #11
0
 def setUp(self):
     cleanUp()
     container = testing.DummyModel(sessions=DummySessions())
     container['intranets'] = testing.DummyModel()
     context = DummyCommunity('Intranet', 'description', 'text', 'creator')
     container['intranet'] = context
     self.context = context
     request = testing.DummyRequest()
     request.environ['repoze.browserid'] = '1'
     self.request = request
Пример #12
0
    def test_handle_submit(self):
        from karl.testing import registerSettings
        registerSettings()

        context = self.blog
        self.site.system_email_domain = 'example.com'
        tags = DummyTags()
        self.site.tags = tags
        from karl.testing import DummyCatalog
        self.site.catalog = DummyCatalog()
        self.site.sessions = DummySessions()
        from karl.testing import DummyUpload
        attachment1 = DummyUpload(filename="test1.txt")
        attachment2 = DummyUpload(filename=r"C:\My Documents\Ha Ha\test2.txt")
        converted = {
            'title': 'foo',
            'text': 'text',
            'tags': ['tag1', 'tag2'],
            'sendalert': True,
            'security_state': 'public',
            'attachments': [attachment1, attachment2],
        }
        self._register()
        from karl.content.interfaces import IBlogEntry
        from karl.content.interfaces import ICommunityFile
        from repoze.lemonade.testing import registerContentFactory
        registerContentFactory(DummyBlogEntry, IBlogEntry)
        registerContentFactory(DummyFile, ICommunityFile)
        request = self._makeRequest()
        controller = self._makeOne(context, request)
        karl.testing.registerDummyRenderer(
            'templates/email_blog_entry_alert.pt')
        response = controller.handle_submit(converted)
        self.assertEqual(response.location,
                         'http://example.com/communities/community/blog/foo/')
        self.assertEqual(3, len(self.mailer))
        recipients = reduce(lambda x, y: x + y, [x.mto for x in self.mailer])
        recipients.sort()
        self.assertEqual([
            "*****@*****.**",
            "*****@*****.**",
            "*****@*****.**",
        ], recipients)

        self.failUnless(context['foo']['attachments']['test1.txt'])
        self.failUnless(context['foo']['attachments']['test2.txt'])

        body = self.mailer[0].msg.get_payload(decode=True)
        self.assertEqual(body, '')

        attachment1 = context['foo']['attachments']['test1.txt']
        self.assertEqual(attachment1.filename, "test1.txt")

        attachment2 = context['foo']['attachments']['test2.txt']
        self.assertEqual(attachment2.filename, "test2.txt")
Пример #13
0
 def test_handle_submit(self):
     from karl.models.interfaces import ISite
     from zope.interface import directlyProvides
     site = testing.DummyModel(sessions=DummySessions())
     directlyProvides(site, ISite)
     from karl.testing import DummyCatalog
     from karl.models.adapters import CatalogSearch
     from karl.models.interfaces import ICatalogSearch
     from zope.interface import Interface
     site.catalog = DummyCatalog()
     karl.testing.registerAdapter(CatalogSearch, (Interface), ICatalogSearch)
     context = self.context
     site['newsitem'] = context
     tags = DummyTags()
     site.tags = tags
     controller = self._makeOne(context, self.request)
     from karl.content.views.newsitem import _now
     now = _now()
     simple = {
         'title': 'NewFoo',
         'text': 'text',
         'caption': 'caption',
         'publication_date': now
         }
     from karl.testing import DummyUpload
     attachment1 = DummyUpload(filename='test1.txt')
     attachment2 = DummyUpload(filename=r'C:\My Documents\Ha Ha\test2.txt')
     photo = DummyUpload(filename='test.jpg',
                         mimetype='image/jpeg',
                         data=dummy_photo)
     converted = {
         'tags': ['tag1', 'tag2'],
         'attachments': [attachment1, attachment2],
         'photo': photo,
         }
     converted.update(simple)
     from karl.content.interfaces import ICommunityFile
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(DummyFile, ICommunityFile)
     response = controller.handle_submit(converted)
     msg = "?status_message=News%20Item%20edited"
     self.assertEqual(response.location,
                      'http://example.com/newsitem/%s' % msg)
     for field, value in simple.items():
         self.assertEqual(getattr(context, field), value)
     attachments_folder = context['attachments']
     self.failUnless('test1.txt' in attachments_folder)
     self.failUnless('test2.txt' in attachments_folder)
     self.assertEqual(attachments_folder['test1.txt'].filename,
                      'test1.txt')
     self.assertEqual(attachments_folder['test2.txt'].filename,
                      'test2.txt')
     self.failUnless('photo' in context)
     self.assertEqual(site.tags._called_with[1]['tags'],
                      ['tag1', 'tag2'])
Пример #14
0
    def setUp(self):
        cleanUp()
        # Register mail utility
        from repoze.sendmail.interfaces import IMailDelivery
        from karl.testing import DummyMailer
        self.mailer = DummyMailer()
        karl.testing.registerUtility(self.mailer, IMailDelivery)

        # Register BlogCommentAlert adapter
        from karl.models.interfaces import IProfile
        from karl.models.interfaces import IComment
        from karl.content.views.adapters import BlogCommentAlert
        from karl.utilities.interfaces import IAlert
        from pyramid.interfaces import IRequest
        karl.testing.registerAdapter(BlogCommentAlert,
                                     (IComment, IProfile, IRequest), IAlert)

        # Register IShowSendAlert adapter
        self.show_sendalert = True
        from karl.content.views.interfaces import IShowSendalert

        class DummyShowSendalert(object):
            def __init__(myself, context, request):
                myself.show_sendalert = self.show_sendalert

        karl.testing.registerAdapter(DummyShowSendalert,
                                     (Interface, Interface), IShowSendalert)

        # Create dummy site skel
        from karl.testing import DummyCommunity
        from karl.testing import DummyProfile
        community = DummyCommunity()
        site = community.__parent__.__parent__
        site.sessions = DummySessions()
        profiles = testing.DummyModel()
        site["profiles"] = profiles
        profiles["a"] = DummyProfile()
        profiles["b"] = DummyProfile()
        profiles["c"] = DummyProfile()
        community.member_names = set([
            "b",
            "c",
        ])
        community.moderator_names = set([
            "a",
        ])
        blog = testing.DummyModel()
        community["blog"] = blog
        blogentry = blog["foo"] = DummyBlogEntry()
        self.context = blogentry["comments"]

        # Create dummy request
        request = testing.DummyRequest()
        request.environ['repoze.browserid'] = '1'
        self.request = request
Пример #15
0
 def setUp(self):
     cleanUp()
     self.parent = DummyModel(title='dummyparent', sessions=DummySessions())
     self.context = DummyModel(title='dummytitle', text='dummytext')
     self.context['attachments'] = DummyModel()
     self.parent['child'] = self.context
     self.parent.catalog = DummyCatalog()
     request = testing.DummyRequest()
     request.environ['repoze.browserid'] = '1'
     self.request = request
     registerLayoutProvider()
Пример #16
0
 def setUp(self):
     testing.cleanUp()
     from karl.models.interfaces import ISite
     site = testing.DummyModel(sessions=DummySessions())
     directlyProvides(site, ISite)
     self.context = site
     request = testing.DummyRequest()
     request.environ['repoze.browserid'] = '1'
     self.request = request
     karl.testing.registerDummyRenderer(
         'karl.views:forms/templates/snippets.pt')
Пример #17
0
 def setUp(self):
     cleanUp()
     self.sessions = sessions = DummySessions()
     context = DummyProfile(sessions=sessions)
     context.title = 'title'
     self.context = context
     request = testing.DummyRequest()
     request.environ['repoze.browserid'] = '1'
     self.request = request
     # this initializes the available groups
     karltesting.registerSettings()
Пример #18
0
 def test_handle_submit_attachment_is_None(self):
     """
     There seems to be some set of circumstances under which formish will
     return a None as a value in the attachments sequence.
     """
     from karl.models.interfaces import IObjectModifiedEvent
     from zope.interface import Interface
     from karl.models.interfaces import ITagQuery
     from karl.content.interfaces import IBlogEntry
     from repoze.lemonade.testing import registerContentFactory
     from karl.testing import DummyCatalog
     karl.testing.registerAdapter(DummyTagQuery, (Interface, Interface),
                                  ITagQuery)
     self._registerDummyWorkflow()
     context = DummyBlogEntry()
     context.sessions = DummySessions()
     context.__name__ = 'ablogentry'
     context.catalog = DummyCatalog()
     context['attachments'] = testing.DummyModel()
     from karl.models.interfaces import ISite
     from zope.interface import directlyProvides
     directlyProvides(context, ISite)
     converted = {
         'title': 'foo',
         'text': 'text',
         'security_state': 'public',
         'tags': 'thetesttag',
         'attachments': [None],
     }
     registerContentFactory(DummyBlogEntry, IBlogEntry)
     L = karl.testing.registerEventListener(
         (Interface, IObjectModifiedEvent))
     karl.testing.registerDummySecurityPolicy('testeditor')
     request = self._makeRequest()
     controller = self._makeOne(context, request)
     response = controller.handle_submit(converted)
     self.assertEqual(response.location, 'http://example.com/ablogentry/')
     self.assertEqual(len(L), 2)
     self.assertEqual(context.title, 'foo')
     self.assertEqual(context.text, 'text')
     self.assertEqual(context.modified_by, 'testeditor')
Пример #19
0
    def setUp(self):
        cleanUp()

        # Create dummy site skel
        from karl.testing import DummyCommunity
        community = DummyCommunity()
        site = community.__parent__.__parent__
        site.sessions = DummySessions()
        blog = testing.DummyModel()
        community["blog"] = blog
        blogentry = blog["foo"] = DummyBlogEntry()
        container = blogentry["comments"]
        comment = container["99"] = DummyComment('Re: foo', 'text',
                                                 'description', 'creator')
        self.context = comment

        # Create dummy request
        request = testing.DummyRequest()
        request.environ['repoze.browserid'] = '1'
        self.request = request
        registerLayoutProvider()
Пример #20
0
 def test_handle_submit(self):
     from schemaish.type import File as SchemaFile
     from karl.models.interfaces import IObjectModifiedEvent
     from zope.interface import Interface
     from karl.models.interfaces import ITagQuery
     from karl.content.interfaces import IBlogEntry
     from repoze.lemonade.testing import registerContentFactory
     from karl.testing import DummyCatalog
     karl.testing.registerAdapter(DummyTagQuery, (Interface, Interface),
                                  ITagQuery)
     self._registerDummyWorkflow()
     context = DummyBlogEntry()
     context.sessions = DummySessions()
     context.__name__ = 'ablogentry'
     context.catalog = DummyCatalog()
     context['attachments'] = testing.DummyModel()
     from karl.models.interfaces import ISite
     from zope.interface import directlyProvides
     directlyProvides(context, ISite)
     converted = {
         'title': 'foo',
         'text': 'text',
         'security_state': 'public',
         'tags': 'thetesttag',
         'attachments': [SchemaFile(None, None, None)],
     }
     registerContentFactory(DummyBlogEntry, IBlogEntry)
     L = karl.testing.registerEventListener(
         (Interface, IObjectModifiedEvent))
     karl.testing.registerDummySecurityPolicy('testeditor')
     request = self._makeRequest()
     controller = self._makeOne(context, request)
     response = controller.handle_submit(converted)
     self.assertEqual(response.location, 'http://example.com/ablogentry/')
     self.assertEqual(len(L), 2)
     self.assertEqual(context.title, 'foo')
     self.assertEqual(context.text, 'text')
     self.assertEqual(context.modified_by, 'testeditor')
Пример #21
0
 def _makeContext(self):
     sessions = DummySessions()
     context = testing.DummyModel(sessions=sessions)
     context['profiles'] = testing.DummyModel()
     return context
Пример #22
0
 def _makeContext(self):
     sessions = DummySessions()
     context = testing.DummyModel(sessions=sessions)
     return context