Пример #1
0
 def test_otherpage(self):
     self._register()
     context = DummyWikiPage(title='Other Page')
     context.__name__ = 'other_page'
     from karl.testing import DummyCommunity
     context.__parent__ = DummyCommunity()
     from karl.testing import DummyCatalog
     context.__parent__.catalog = DummyCatalog()
     request = testing.DummyRequest()
     from webob.multidict import MultiDict
     request.params = request.POST = MultiDict()
     response = self._callFUT(context, request)
     self.assertEqual(len(response['actions']), 0)
     self.assertEqual(
         response['backto'], {
             'href': 'http://example.com/communities/community/',
             'title': u'Dummy Communit\xe0',
         })
     self.assertEqual(
         response['head_data'],
         '<script type="text/javascript">\nwindow._karl_client_data = '
         '{"wikitoc": {"items": [{"name": "WIKIPAGE", "author": "", "tags": '
         '[], "modified": "2011-08-20T00:00:00", "author_name": "", '
         '"created": "2011-08-20T00:00:00", "title": "", "id": '
         '"id_WIKIPAGE", "profile_url": "http://example.com/"}]}};\n'
         '</script>')
Пример #2
0
    def test_handle_submit_titlechange(self):
        from karl.testing import DummyCatalog
        self._register()
        converted = {
            'text': 'text',
            'title': 'newtitle',
            'sendalert': True,
            'security_state': 'public',
            'tags': 'thetesttag',
        }
        context = testing.DummyModel(title='oldtitle')
        context.text = 'oldtext'

        def change_title(newtitle):
            context.title = newtitle

        context.change_title = change_title
        context.catalog = DummyCatalog()
        request = testing.DummyRequest()
        from karl.models.interfaces import IObjectModifiedEvent
        from zope.interface import Interface
        L = karl.testing.registerEventListener(
            (Interface, IObjectModifiedEvent))
        karl.testing.registerDummySecurityPolicy('testeditor')
        controller = self._makeOne(context, request)
        response = controller.handle_submit(converted)
        self.assertEqual(L[0], context)
        self.assertEqual(L[1].object, context)
        self.assertEqual(
            response.location,
            'http://example.com/?status_message=Wiki%20Page%20edited')
        self.assertEqual(context.text, 'text')
        self.assertEqual(context.modified_by, 'testeditor')
        self.assertEqual(context.title, 'newtitle')
Пример #3
0
 def test_force_reindex(self):
     from zope.interface import directlyProvides
     from karl.models.interfaces import IProfile
     from karl.testing import DummyCatalog
     xml = """
     <peopledirectory>
         <sections>
             <section name="everyone" title="Everyone">
                 <report name="everyone" title="Everyone">
                     <columns names="name email"/>
                 </report>
             </section>
         </sections>
     </peopledirectory>
     """
     elem = parse_xml(xml)
     site = testing.DummyModel(list_aliases={})
     peopledir = site['people'] = DummyPeopleDirectory()
     peopledir.catalog = DummyCatalog()
     profiles = site['profiles'] = testing.DummyModel()
     profile = profiles['dummy'] = testing.DummyModel()
     directlyProvides(profile, IProfile)
     self._callFUT(peopledir, elem, force_reindex=True)
     self.assertEqual(len(peopledir.catalog.indexed), 1)
     self.failUnless(peopledir.catalog.indexed[0] is profile)
Пример #4
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')
Пример #5
0
    def test_handle_submit(self):
        from pyramid.testing import DummyModel
        from karl.testing import DummyCatalog
        from karl.testing import DummyOrdering
        from karl.testing import DummyTags
        context = DummyModel(
            tags=DummyTags(),
            catalog=DummyCatalog(),
            ordering=DummyOrdering(),
        )
        converted = {
            'title': u'Ref Manual Title',
            'tags': [u'foo', u'bar'],
            'description': u'ref manual description',
        }
        controller = self._makeOne(context=context)
        self._registerFactory(controller)
        response = controller.handle_submit(converted)

        self.failUnless(u'ref-manual-title' in context)
        manual = context[u'ref-manual-title']
        self.assertEqual(manual.title, u'Ref Manual Title')
        self.assertEqual(manual.description, u'ref manual description')
        self.assertEqual(context.tags._called_with[1]['tags'],
                         [u'foo', u'bar'])
Пример #6
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'])
Пример #7
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'])
Пример #8
0
 def test_noncontent_object(self):
     from karl.testing import DummyCatalog
     model = testing.DummyModel()
     catalog = DummyCatalog()
     model.catalog = catalog
     self._callFUT(model, None)
     self.assertEqual(catalog.document_map.added, [])
     self.assertEqual(catalog.indexed, [])
Пример #9
0
 def test_no_profiles(self):
     from karl.testing import DummyCatalog
     site = testing.DummyModel()
     peopledir = testing.DummyModel()
     peopledir.catalog = DummyCatalog()
     site['people'] = peopledir
     profiles = testing.DummyModel()
     site['profiles'] = profiles
     self._callFUT(peopledir)
Пример #10
0
 def _makeContext(self):
     from pyramid.testing import DummyModel
     from karl.testing import DummyCatalog
     parent = DummyModel(title='dummyparent',
                         catalog=DummyCatalog())
     context = DummyModel(title='dummytitle',
                          description='dummydescription')
     parent['dummytitle'] = context
     return parent, context
Пример #11
0
    def test_content_object(self):
        from karl.testing import DummyCatalog
        model = testing.DummyModel()
        catalog = model.catalog = DummyCatalog()

        self._callFUT(model, [2, 4, 6])

        self.assertEqual(catalog.unindexed, [2, 4, 6])
        self.assertEqual(catalog.document_map.removed, [2, 4, 6])
Пример #12
0
 def test_content_object(self):
     from pyramid.traversal import resource_path
     from karl.testing import DummyCatalog
     model = testing.DummyModel()
     path = resource_path(model)
     catalog = DummyCatalog({1: path})
     model.catalog = catalog
     self._callFUT(model, None)
     self.assertEqual(catalog.reindexed, [model])
Пример #13
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")
Пример #14
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'])
Пример #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 test_content_object(self):
     model = testing.DummyModel()
     model['people'] = testing.DummyModel()
     from pyramid.traversal import resource_path
     path = resource_path(model)
     from karl.testing import DummyCatalog
     catalog = DummyCatalog({1: path})
     model['people'].catalog = catalog
     self._callFUT(model, None)
     self.assertEqual(catalog.unindexed, [1])
     self.assertEqual(catalog.indexed, [model])
Пример #17
0
    def setUp(self):
        cleanUp()

        self.parent = DummyModel(title='dummyparent')
        self.context = DummyModel(title='dummytitle', text='dummytext')
        self.context['attachments'] = DummyModel()
        self.parent['child'] = self.context
        self.parent.catalog = DummyCatalog()
        self.parent["profiles"] = DummyModel()
        users = self.parent.users = DummyUsers()
        users.add("userid", "userid", "password", [])
Пример #18
0
 def test_content_object_w_catalog_no_tags(self):
     from pyramid.traversal import resource_path
     from karl.testing import DummyCatalog
     model = testing.DummyModel()
     path = resource_path(model)
     catalog = model.catalog = DummyCatalog({1: path,
                                             2: '%s/foo' % path,
                                             3: '%s/bar' % path,
                                            })
     self._callFUT(model, None)
     self.assertEqual(catalog.unindexed, [1, 2, 3])
     self.assertEqual(catalog.document_map.removed, [1, 2, 3])
Пример #19
0
 def _makeContext(self):
     from pyramid.testing import DummyModel
     from karl.testing import DummyCatalog
     from karl.testing import DummyOrdering
     parent = DummyModel(title='dummyparent',
                         ordering=DummyOrdering(),
                         catalog=DummyCatalog())
     context = DummyModel(title='dummytitle',
                          text='dummytext',
                          ordering=DummyOrdering())
     context['attachments'] = DummyModel()
     parent['child'] = context
     return parent, context
Пример #20
0
 def test_content_object(self):
     from karl.testing import DummyCatalog
     from zope.interface import directlyProvides
     from repoze.lemonade.interfaces import IContent
     from pyramid.traversal import resource_path
     model = testing.DummyModel()
     path = resource_path(model)
     directlyProvides(model, IContent)
     catalog = DummyCatalog()
     model.catalog = catalog
     self._callFUT(model, None)
     self.assertEqual(catalog.document_map.added, [(None, path)])
     self.assertEqual(catalog.indexed, [model])
     self.assertEqual(model.docid, 1)
Пример #21
0
 def test_content_object_w_existing_docid(self):
     from karl.testing import DummyCatalog
     from zope.interface import directlyProvides
     from karl.models.interfaces import IProfile
     from pyramid.traversal import resource_path
     model = testing.DummyModel()
     model['people'] = testing.DummyModel()
     path = resource_path(model)
     directlyProvides(model, IProfile)
     catalog = DummyCatalog()
     model['people'].catalog = catalog
     model.docid = 123
     self._callFUT(model, None)
     self.assertEqual(catalog.document_map.added, [(123, path)])
     self.assertEqual(catalog.indexed, [model])
Пример #22
0
    def setUp(self):
        cleanUp()

        # When you see:
        #   AttributeError: 'NoneType' object has no attribute 'url'
        # ...it is often because you are pointed at the wrong .pt
        self.template_fn = 'templates/show_page.pt'

        self.parent = DummyModel(title='dummyparent')
        self.context = DummyModel(title='dummytitle', text='dummytext')
        self.context['attachments'] = DummyModel()
        self.parent['child'] = self.context
        self.parent.catalog = DummyCatalog()
        karl.testing.registerDummyRenderer(
            'karl.views:templates/formfields.pt')
Пример #23
0
 def test_content_object(self):
     model = testing.DummyModel()
     model['people'] = testing.DummyModel()
     from pyramid.traversal import resource_path
     path = resource_path(model)
     from karl.testing import DummyCatalog
     catalog = DummyCatalog({1: path})
     model['people'].catalog = catalog
     self._callFUT(model, None)
     # 1 is repeated here because the DummyCatalog returns the map
     # above as the query result and we unindex the results but we
     # also unindex '1' as a result of it being the object passed
     # in to unindex_profile
     self.assertEqual(catalog.unindexed, [1, 1])
     self.assertEqual(catalog.document_map.removed, [1, 1])
Пример #24
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')
Пример #25
0
    def test_content_object_w_catalog_w_tags(self):
        from pyramid.traversal import resource_path
        from karl.testing import DummyCatalog
        model = testing.DummyModel()
        path = resource_path(model)
        tags = model.tags = DummyTags()
        catalog = model.catalog = DummyCatalog({1: path,
                                                2: '%s/foo' % path,
                                                3: '%s/bar' % path,
                                               })
        self._callFUT(model, None)

        self.assertEqual(catalog.unindexed, [1, 2, 3])
        self.assertEqual(catalog.document_map.removed, [1, 2, 3])
        self.assertEqual(len(tags._delete_called_with), 3)
        self.assertEqual(tags._delete_called_with[0], (1, None, None))
        self.assertEqual(tags._delete_called_with[1], (2, None, None))
        self.assertEqual(tags._delete_called_with[2], (3, None, None))
Пример #26
0
    def test_with_new_profile(self):
        from karl.testing import DummyCatalog
        site = testing.DummyModel()
        peopledir = testing.DummyModel()
        peopledir.catalog = DummyCatalog()
        site['people'] = peopledir
        profiles = testing.DummyModel()
        site['profiles'] = profiles

        p1 = testing.DummyModel()
        from karl.models.interfaces import IProfile
        from zope.interface import directlyProvides
        directlyProvides(p1, IProfile)
        profiles['p1'] = p1

        self._callFUT(peopledir)
        self.assertEquals(peopledir.catalog.document_map.added,
                          [(None, '/profiles/p1')])
Пример #27
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')
Пример #28
0
 def test_frontpage(self):
     self._register()
     context = DummyWikiPage()
     context.__name__ = 'front_page'
     context.title = 'Page'
     from karl.testing import DummyCommunity
     context.__parent__ = DummyCommunity()
     from karl.testing import DummyCatalog
     context.__parent__.catalog = DummyCatalog()
     request = testing.DummyRequest()
     response = self._callFUT(context, request)
     self.assertEqual(len(response['actions']), 0)
     self.assertEqual(response['backto'], False)
     self.assertEqual(
         response['head_data'],
         '<script type="text/javascript">\nwindow._karl_client_data = '
         '{"wikitoc": {"items": [{"name": "WIKIPAGE", "author": "", "tags": '
         '[], "modified": "2011-08-20T00:00:00", "author_name": "", '
         '"created": "2011-08-20T00:00:00", "title": "", "id": '
         '"id_WIKIPAGE", "profile_url": "http://example.com/"}]}};\n'
         '</script>')
Пример #29
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)
Пример #30
0
 def test_handle_submit(self):
     converted = {
         'title': 'newtitle',
         'description': 'newdescription',
     }
     context = testing.DummyModel(title='oldtitle',
                                  description='olddescription')
     context.catalog = DummyCatalog()
     from karl.models.interfaces import IObjectModifiedEvent
     L = karl.testing.registerEventListener(
         (Interface, IObjectModifiedEvent))
     karl.testing.registerDummySecurityPolicy('testeditor')
     request = testing.DummyRequest()
     controller = self._makeOne(context, request)
     response = controller.handle_submit(converted)
     self.assertEqual(L[0], context)
     self.assertEqual(L[1].object, context)
     self.assertEqual(response.location,
                      'http://example.com/?status_message=Forum+Edited')
     self.assertEqual(context.title, 'newtitle')
     self.assertEqual(context.description, 'newdescription')
     self.assertEqual(context.modified_by, 'testeditor')