Exemple #1
0
    def test_handle_submit(self):
        from karl.models.interfaces import IComment
        from karl.content.interfaces import ICommunityFile
        from repoze.lemonade.testing import registerContentFactory
        registerContentFactory(DummyComment, IComment)
        registerContentFactory(DummyFile, ICommunityFile)

        from karl.testing import DummyUpload
        attachment1 = DummyUpload(filename="test1.txt")
        attachment2 = DummyUpload(filename=r"C:\My Documents\Ha Ha\test2.txt")
        converted = {
            'add_comment': u'This is my comment',
            'attachments': [attachment1, attachment2],
            'sendalert': False
        }
        context = self.context
        controller = self._makeOne(context, self.request)
        response = controller.handle_submit(converted)
        location = ('http://example.com/communities/community/blog/foo/'
                    '?status_message=Comment%20added')
        self.assertEqual(response.location, location)
        self.failUnless(u'99' in context)
        comment = context[u'99']
        self.assertEqual(comment.title, 'Re: Dummy Blog Entry')
        self.assertEqual(comment.text, u'This is my comment')
        self.assertEqual(len(comment), 2)
        self.failUnless('test1.txt' in comment)
        self.failUnless('test2.txt' in comment)

        # try again w/ a workflow, and w/ sendalert == True
        del context[u'99']
        workflow = self._registerSecurityWorkflow()
        blogentry = context.__parent__
        blogentry.creator = 'b'
        blogentry.created = datetime.now()
        blogentry.text = u'Blog entry text'
        converted = {
            'add_comment': u'This is my OTHER comment',
            'attachments': [],
            'sendalert': True,
            'security_state': 'public'
        }
        karl.testing.registerDummyRenderer(
            'karl.content.views:templates/email_blog_comment_alert.pt')
        response = controller.handle_submit(converted)
        self.assertEqual(response.location, location)
        self.failUnless(u'99' in context)
        comment = context[u'99']
        self.assertEqual(len(comment), 0)
        mailer = self.mailer
        self.assertEqual(len(mailer), 3)
        recipients = [mail.mto[0] for mail in mailer]
        self.failUnless('*****@*****.**' in recipients)
        self.failUnless('*****@*****.**' in recipients)
        self.failUnless('*****@*****.**' in recipients)
        self.failUnless(comment in workflow.initialized)
        self.assertEqual(len(workflow.transitioned), 1)
        transition = workflow.transitioned[0]
        self.failUnless(transition['content'] is comment)
        self.assertEqual(transition['to_state'], 'public')
Exemple #2
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'])
Exemple #3
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'])
Exemple #4
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")
Exemple #5
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'])
Exemple #6
0
 def test_handle_submit(self):
     from karl.testing import DummyUpload
     attachment = DummyUpload(filename='newfile.txt')
     converted = {
         'title': u'New Title',
         'text': u'New page text.',
         'tags': [u'foo', u'bar'],
         'attachments': [attachment],
     }
     self._registerTags(self.parent)
     from karl.content.interfaces import ICommunityFile
     from karl.testing import DummyFile
     registerContentFactory(DummyFile, ICommunityFile)
     context = self.context
     controller = self._makeOne(context, self.request)
     response = controller.handle_submit(converted)
     self.failUnless('Page%20edited' in response.location)
     self.failUnless(
         response.location.startswith('http://example.com/child/'))
     self.assertEqual(context.title, u'New Title')
     self.assertEqual(context.text, u'New page text.')
     attachments_folder = context['attachments']
     self.failUnless('newfile.txt' in attachments_folder)
     self.failIf(len(attachments_folder) > 1)
     self.assertEqual(self.parent.tags._called_with[1]['tags'],
                      [u'foo', u'bar'])
Exemple #7
0
    def test_handle_submit(self):
        from karl.testing import DummyUpload
        context = testing.DummyModel(
            title='oldtitle',
            text='oldtext',
        )

        upload = DummyUpload(filename='test.txt')

        converted = {
            'title': 'newtitle',
            'text': 'newtext',
            'tags': [],
            'security_state': 'public',
            'attachments': [DummyUpload()],
        }
        from karl.content.interfaces import ICommunityFile
        from repoze.lemonade.testing import registerContentFactory

        def factory(**args):
            res = testing.DummyModel(**args)
            res.size = 10
            return res

        registerContentFactory(factory, ICommunityFile)
        context['attachments'] = testing.DummyModel()
        context.catalog = DummyCatalog()
        context.sessions = DummySessions()
        from karl.models.interfaces import IObjectModifiedEvent
        L = karl.testing.registerEventListener(
            (Interface, IObjectModifiedEvent))
        request = testing.DummyRequest()
        request.environ['repoze.browserid'] = '1'
        controller = self._makeOne(context, request)
        response = controller.handle_submit(converted)
        self.assertEqual(
            response.location,
            'http://example.com/?status_message=Forum+Topic+Edited')
        self.assertEqual(L[0], context)
        self.assertEqual(L[1].object, context)
        self.assertEqual(context.title, 'newtitle')
        self.assertEqual(context.text, 'newtext')
        self.assertEqual(len(context['attachments']), 1)
        self.assertEqual(context['attachments'].keys(), ['test.txt'])
        self.assertEqual(context['attachments']['test.txt'].mimetype,
                         'text/plain')
Exemple #8
0
    def test_handle_submit(self):
        from karl.testing import DummyUpload
        from repoze.lemonade.testing import registerContentFactory
        from karl.content.interfaces import IForumTopic
        from karl.content.interfaces import ICommunityFile

        def factory(title, text, creator):
            topic = testing.DummyModel(title=title, text=text, creator=creator)
            topic['comments'] = testing.DummyModel()
            topic['attachments'] = testing.DummyModel()
            topic.get_attachments = lambda: None
            return topic

        registerContentFactory(factory, IForumTopic)
        registerContentFactory(DummyFile, ICommunityFile)

        attachment1 = DummyUpload(filename="test1.txt")
        attachment2 = DummyUpload(filename=r"C:\My Documents\Ha Ha\test2.txt")

        converted = {
            'title': 'title',
            'text': 'abc',
            'tags': 'thetesttag',
            'security_state': 'public',
            'attachments': [attachment1, attachment2],
        }

        context = self._makeContext()
        context.catalog = DummyCatalog()
        request = testing.DummyRequest()
        request.environ['repoze.browserid'] = '1'
        workflow = self._registerDummyWorkflow()
        controller = self._makeOne(context, request)
        response = controller.handle_submit(converted)
        self.assertEqual(response.location, 'http://example.com/title/')
        self.assertEqual(context['title'].title, 'title')
        self.assertEqual(context['title'].text, 'abc')
        self.assertEqual(context['title'].creator, None)
        self.assertEqual(workflow.initialized, True)
        self.assertEqual(len(context['title']['attachments']), 2)
Exemple #9
0
    def test_handle_submit(self):
        from karl.models.interfaces import IComment
        from karl.content.interfaces import ICommunityFile
        from repoze.lemonade.testing import registerContentFactory
        registerContentFactory(DummyComment, IComment)
        registerContentFactory(DummyFile, ICommunityFile)

        from karl.testing import DummyUpload
        attachment1 = DummyUpload(filename="test1.txt")
        attachment2 = DummyUpload(filename=r"C:\My Documents\Ha Ha\test2.txt")
        converted = {'add_comment': u'This is my comment',
                     'attachments': [attachment1, attachment2],
                     'sendalert': False}
        context = self.context
        controller = self._makeOne(context, self.request)
        response = controller.handle_submit(converted)
        location = ('http://example.com/communities/community/blog/foo/'
                    'comments/99/')
        self.assertEqual(response.location, location)
        self.assertEqual(context.title, 'Re: foo')
        self.assertEqual(context.text, u'This is my comment')
        self.assertEqual(len(context), 2)
        self.failUnless('test1.txt' in context)
        self.failUnless('test2.txt' in context)

        # try again w/ a workflow, and delete an attachment
        blogentry = context.__parent__
        workflow = self._registerSecurityWorkflow()
        blogentry.text = u'Blog entry text'
        attachment1 = DummyUpload(None, None)
        attachment1.file = None
        attachment1.metadata = {}
        attachment2 = DummyUpload(None, None)
        attachment2.file = None
        attachment2.metadata = {'default': 'test2.txt',
                                'remove': True,
                                'name': ''}
        converted = {'add_comment': u'This is my OTHER comment',
                     'attachments': [attachment1, attachment2],
                     'security_state': 'public'}
        response = controller.handle_submit(converted)
        self.assertEqual(response.location, location)
        self.assertEqual(len(context), 1)
        self.failUnless('test1.txt' in context)
        self.failIf('test2.txt' in context)
        self.assertEqual(len(workflow.transitioned), 1)
        transition = workflow.transitioned[0]
        self.failUnless(transition['content'] is context)
        self.assertEqual(transition['to_state'], 'public')
Exemple #10
0
    def test_handle_submit(self):
        from karl.models.interfaces import IComment
        from karl.content.interfaces import ICommunityFile
        from repoze.lemonade.testing import registerContentFactory
        registerContentFactory(DummyComment, IComment)
        registerContentFactory(DummyFile, ICommunityFile)

        from karl.testing import DummyUpload
        attachment1 = DummyUpload(filename="test1.txt")
        attachment2 = DummyUpload(filename=r"C:\My Documents\Ha Ha\test2.txt")
        converted = {'add_comment': u'This is my comment',
                     'attachments': [attachment1, attachment2],
                     'sendalert': False}
        context = self.context
        controller = self._makeOne(context, self.request)
        response = controller.handle_submit(converted)
        location = ('http://example.com/communities/community/blog/foo/'
                    'comments/99/')
        self.assertEqual(response.location, location)
        self.assertEqual(context.title, 'Re: foo')
        self.assertEqual(context.text, u'This is my comment')
        self.assertEqual(len(context), 2)
        self.failUnless('test1.txt' in context)
        self.failUnless('test2.txt' in context)

        # try again w/ a workflow, and delete an attachment
        blogentry = context.__parent__
        workflow = self._registerSecurityWorkflow()
        blogentry.text = u'Blog entry text'
        attachment1 = DummyUpload(None, None)
        attachment1.file = None
        attachment1.metadata = {}
        attachment2 = DummyUpload(None, None)
        attachment2.file = None
        attachment2.metadata = {'default': 'test2.txt',
                                'remove': True,
                                'name': ''}
        converted = {'add_comment': u'This is my OTHER comment',
                     'attachments': [attachment1, attachment2],
                     'security_state': 'public'}
        response = controller.handle_submit(converted)
        self.assertEqual(response.location, location)
        self.assertEqual(len(context), 1)
        self.failUnless('test1.txt' in context)
        self.failIf('test2.txt' in context)
        self.assertEqual(len(workflow.transitioned), 1)
        transition = workflow.transitioned[0]
        self.failUnless(transition['content'] is context)
        self.assertEqual(transition['to_state'], 'public')