Exemple #1
0
    def test_known_kind_no_text_term(self):
        from webob.multidict import MultiDict
        from karl.models.interfaces import IGroupSearchFactory
        from repoze.lemonade.testing import registerContentFactory
        from zope.interface import Interface

        content = DummyCommunityContent()

        def search_factory(*arg, **kw):
            return DummySearchFactory(content)

        search_factory.icon = "foo.jpg"
        search_factory.advanced_search = True
        karltesting.registerUtility(search_factory, IGroupSearchFactory, name="People")
        context = testing.DummyModel()
        context.catalog = {}
        context["profiles"] = profiles = testing.DummyModel()
        profiles["tweedle dee"] = testing.DummyModel(title="Tweedle Dee")
        request = testing.DummyRequest(params=MultiDict({"kind": "People"}))
        request.layout_manager = mock.Mock()
        from karl.models.interfaces import ICatalogSearch
        from karl.views.interfaces import IAdvancedSearchResultsDisplay

        registerContentFactory(DummyContent, IDummyContent)
        karltesting.registerAdapter(DummySearch, (Interface), ICatalogSearch)
        karltesting.registerAdapter(DummySearchResultsDisplay, (Interface, Interface), IAdvancedSearchResultsDisplay)
        result = self._callFUT(context, request)
        self.assertEqual(result["terms"], ["People"])
        self.assertEqual(len(result["results"]), 1)
Exemple #2
0
    def test_community_search(self):
        context = testing.DummyModel()
        context.title = "Citizens"
        context.catalog = {}
        context["profiles"] = profiles = testing.DummyModel()
        profiles["tweedle dee"] = testing.DummyModel(title="Tweedle Dee")
        from webob.multidict import MultiDict
        from karl.models.interfaces import ICommunity
        from zope.interface import directlyProvides

        directlyProvides(context, ICommunity)
        request = testing.DummyRequest(params=MultiDict({"body": "yo"}))
        request.layout_manager = mock.Mock()
        from zope.interface import Interface
        from karl.models.interfaces import ICatalogSearch
        from karl.views.interfaces import IAdvancedSearchResultsDisplay
        from repoze.lemonade.testing import registerContentFactory

        registerContentFactory(DummyContent, IDummyContent)
        karltesting.registerAdapter(DummySearch, (Interface), ICatalogSearch)
        karltesting.registerAdapter(DummySearchResultsDisplay, (Interface, Interface), IAdvancedSearchResultsDisplay)
        result = self._callFUT(context, request)
        self.assertEqual(result["community"], "Citizens")
        self.assertEqual(result["terms"], ["yo"])
        self.assertEqual(len(result["results"]), 1)
Exemple #3
0
    def test_handle_submit_full_path_filename(self):
        from schemaish.type import File as SchemaFile
        from karl.content.interfaces import ICommunityFile
        from repoze.lemonade.testing import registerContentFactory
        from repoze.bfg.formish import ValidationError
        self._register()
        self._registerLayoutProvider()

        testing.registerDummySecurityPolicy('userid')
        context = self._makeContext()
        context.catalog = DummyCatalog()
        fs = SchemaFile('abc', r"C:\Documents and Settings\My Tests\filename",
                        'x/foo')
        converted = {
            'file': fs,
            'title': 'a title',
            'sendalert': False,
            'security_state': 'public',
            'tags':['thetesttag'],
            }
        request = self._makeRequest()
        registerContentFactory(DummyCommunityFile, ICommunityFile)
        controller = self._makeOne(context, request)
        response = controller.handle_submit(converted)
        self.assertEqual(response.location, 'http://example.com/filename/')
        self.assertEqual(context['filename'].title, u'a title')
        self.assertEqual(context['filename'].creator, 'userid')
        self.assertEqual(context['filename'].stream, 'abc')
        self.assertEqual(context['filename'].mimetype, 'x/foo')
        self.assertEqual(context['filename'].filename, 'filename')

        # attempt a duplicate upload
        self.assertRaises(ValidationError, controller.handle_submit, converted)
Exemple #4
0
    def test_handle_submit_inactive_user(self):
        from repoze.lemonade.testing import registerContentFactory
        from karl.models.interfaces import IInvitation
        from karl.utilities.interfaces import IRandomId
        request = testing.DummyRequest()
        context = self._makeCommunity()
        self._registerMailer()
        registerCatalogSearch()
        profile = karltesting.DummyProfile(security_state='inactive')
        profile.__name__ = 'd'
        registerCatalogSearch(results={'[email protected]': [
            profile,
        ]})

        def nonrandom(size=6):
            return 'A' * size

        karltesting.registerUtility(nonrandom, IRandomId)
        registerContentFactory(DummyInvitation, IInvitation)
        controller = self._makeOne(context, request)
        converted = {
            'email_addresses': [u'*****@*****.**'],
            'text': u'some text',
        }
        karltesting.registerDummyRenderer(
            'karl.views:templates/email_add_existing.pt')
        from pyramid_formish import ValidationError
        self.assertRaises(ValidationError, controller.handle_submit, converted)
Exemple #5
0
    def test_submitted_toobig(self):
        self._register()
        self._registerLayoutProvider()

        from repoze.bfg.formish import ValidationError

        def check_upload_size(*args):
            raise ValidationError(file='TEST VALIDATION ERROR')

        testing.registerDummySecurityPolicy('userid')
        context = self._makeContext()
        context.catalog = DummyCatalog()
        request = self._makeRequest()
        from schemaish.type import File as SchemaFile
        fs = SchemaFile('abc', 'filename', 'x/foo')
        converted = {
            'file': fs,
            'title': 'a title',
            'sendalert': False,
            'security_state': 'public',
            'tags':[],
            }
        from karl.content.interfaces import ICommunityFile
        from repoze.lemonade.testing import registerContentFactory
        registerContentFactory(DummyCommunityFile, ICommunityFile)
        controller = self._makeOne(context, request, check_upload_size)
        self.assertRaises(ValidationError, controller.handle_submit, converted)
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'])
 def test_handle_submit_already_in_community(self):
     from repoze.lemonade.testing import registerContentFactory
     from karl.models.interfaces import IInvitation
     from karl.utilities.interfaces import IRandomId
     request = testing.DummyRequest()
     context = self._makeCommunity()
     mailer = self._registerMailer()
     registerCatalogSearch()
     profile = karltesting.DummyProfile()
     profile.__name__ = 'a'
     registerCatalogSearch(results={'[email protected]': [profile,]})
     def nonrandom(size=6):
         return 'A' * size
     karltesting.registerUtility(nonrandom, IRandomId)
     registerContentFactory(DummyInvitation, IInvitation)
     controller = self._makeOne(context, request)
     converted = {
         'email_addresses': [u'*****@*****.**'],
         'text': u'some text',
         }
     response = controller.handle_submit(converted)
     self.assertEqual(response.location,
       'http://example.com/manage.html?status_message=One+user+already+member.'
                      )
     self.failIf('A'*6 in context)
     self.assertEqual(context.users.added_groups, [])
Exemple #8
0
    def test_no_creator(self):
        from webob.multidict import MultiDict
        context = testing.DummyModel()
        context.catalog = {}
        context['profiles'] = profiles = testing.DummyModel()
        request = testing.DummyRequest(params=MultiDict({'body': 'yo'}))
        request.layout_manager = mock.Mock()
        from zope.interface import Interface
        from karl.models.interfaces import ICatalogSearch
        from karl.views.interfaces import IAdvancedSearchResultsDisplay
        from repoze.lemonade.testing import registerContentFactory
        registerContentFactory(DummyContent, IDummyContent)

        class LocalDummyContent(testing.DummyModel):
            implements(IDummyContent)
            import datetime
            title = 'Dummy Content'
            modified = datetime.datetime(2010, 5, 12, 2, 42)

        class LocalDummySearch(DummySearch):
            content = LocalDummyContent()

        karltesting.registerAdapter(LocalDummySearch, (Interface),
                                    ICatalogSearch)
        karltesting.registerAdapter(DummySearchResultsDisplay,
                                    (Interface, Interface),
                                    IAdvancedSearchResultsDisplay)
        result = self._callFUT(context, request)
        self.assertEqual(result['terms'], ['yo'])
        self.assertEqual(len(result['results']), 1)
Exemple #9
0
    def test_with_tag_multiple_users(self):
        from zope.interface import directlyProvides
        from repoze.lemonade.testing import registerContentFactory
        context = testing.DummyModel()
        context.title = 'title'
        karltesting.registerModels({'/foo': context})
        directlyProvides(context, IDummyBlogEntry)
        registerContentFactory(testing.DummyModel, IDummyBlogEntry)
        tags = context.tags = DummyTags(users=('dummy', 'dummy2'))
        def _getRelated(tag, degree=1, community=None, user=None):
            assert tag == 'tag1'
            assert degree == 1
            assert community is None
            assert user is None
            return []
        tags.getRelatedTags = _getRelated
        context.catalog = karltesting.DummyCatalog({1:'/foo'})
        request = testing.DummyRequest()
        request.subpath = [u'tag1']

        result = self._callFUT(context, request)

        self.assertEqual(result['tag'], u'tag1')
        self.assertEqual(len(result['entries']), 1)
        entry = result['entries'][0]
        self.assertEqual(entry['description'], '')
        self.assertEqual(entry['title'], 'title')
        self.assertEqual(entry['href'], 'http://example.com/')
        self.assertEqual(entry['tagusers_count'], '2 people')
        self.assertEqual(entry['type'], 'Blog Entry')
        self.assertEqual(entry['tagusers_href'],
                         'http://example.com/tagusers.html?tag=tag1&docid=1')
        self.assertEqual(len(result['related']), 0)
Exemple #10
0
    def test_known_kind_no_text_term(self):
        from webob.multidict import MultiDict
        from karl.models.interfaces import IGroupSearchFactory
        from repoze.lemonade.testing import registerContentFactory
        from zope.interface import Interface
        content = DummyCommunityContent()

        def search_factory(*arg, **kw):
            return DummySearchFactory(content)

        search_factory.icon = 'foo.jpg'
        search_factory.advanced_search = True
        karltesting.registerUtility(search_factory,
                                    IGroupSearchFactory,
                                    name='People')
        context = testing.DummyModel()
        context.catalog = {}
        context['profiles'] = profiles = testing.DummyModel()
        profiles['tweedle dee'] = testing.DummyModel(title='Tweedle Dee')
        request = testing.DummyRequest(params=MultiDict({'kind': 'People'}))
        request.layout_manager = mock.Mock()
        from karl.models.interfaces import ICatalogSearch
        from karl.views.interfaces import IAdvancedSearchResultsDisplay
        registerContentFactory(DummyContent, IDummyContent)
        karltesting.registerAdapter(DummySearch, (Interface), ICatalogSearch)
        karltesting.registerAdapter(DummySearchResultsDisplay,
                                    (Interface, Interface),
                                    IAdvancedSearchResultsDisplay)
        result = self._callFUT(context, request)
        self.assertEqual(result['terms'], ['People'])
        self.assertEqual(len(result['results']), 1)
Exemple #11
0
    def setUp(self):
        cleanUp()
        testing.setUp(request=testing.DummyRequest())

        from repoze.lemonade.testing import registerContentFactory
        from karl.models.interfaces import IProfile

        def profile_factory(**kw):
            kw['security_state'] = 'active'
            return testing.DummyModel(**kw)

        registerContentFactory(profile_factory, IProfile)

        from karl.testing import DummyUsers
        self.root = root = testing.DummyModel()
        root.users = DummyUsers()
        root['profiles'] = testing.DummyModel()
        root['people'] = people = testing.DummyModel()
        people['categories'] = categories = testing.DummyModel()
        people.update_indexes = lambda: None
        categories['offices'] = testing.DummyModel()
        categories['entities'] = testing.DummyModel()
        categories['departments'] = testing.DummyModel()
        categories['boards'] = testing.DummyModel()

        from osi.sync import gsa_sync
        self._save_urllib2 = gsa_sync.urllib2
        self.urllib2 = gsa_sync.urllib2 = DummyUrllib2()
        gsa_sync.reindex_peopledirectory = lambda x: None
        gsa_sync.RETRY_SLEEP = 0

        from karl.testing import registerDummyMailer
        registerDummyMailer()
Exemple #12
0
 def test_known_since(self):
     from webob.multidict import MultiDict
     context = testing.DummyModel()
     context.catalog = {}
     context['profiles'] = profiles = testing.DummyModel()
     profiles['tweedle dee'] = testing.DummyModel(title='Tweedle Dee')
     request = testing.DummyRequest(params=MultiDict({
         'body': 'yo',
         'since': 'week'
     }))
     request.layout_manager = mock.Mock()
     from zope.interface import Interface
     from karl.content.interfaces import IBlogEntry
     from karl.models.interfaces import ICatalogSearch
     from karl.views.interfaces import IAdvancedSearchResultsDisplay
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(DummyContent, IDummyContent)
     registerContentFactory(DummyContent, IBlogEntry)
     karltesting.registerAdapter(DummySearch, (Interface), ICatalogSearch)
     karltesting.registerAdapter(DummySearchResultsDisplay,
                                 (Interface, Interface),
                                 IAdvancedSearchResultsDisplay)
     result = self._callFUT(context, request)
     self.assertEqual(result['terms'], ['yo', 'Past week'])
     self.assertEqual(len(result['results']), 1)
Exemple #13
0
 def test_community_search(self):
     context = testing.DummyModel()
     context.title = 'Citizens'
     context.catalog = {}
     context['profiles'] = profiles = testing.DummyModel()
     profiles['tweedle dee'] = testing.DummyModel(title='Tweedle Dee')
     from webob.multidict import MultiDict
     from karl.models.interfaces import ICommunity
     from zope.interface import directlyProvides
     directlyProvides(context, ICommunity)
     request = testing.DummyRequest(params=MultiDict({'body': 'yo'}))
     request.layout_manager = mock.Mock()
     from zope.interface import Interface
     from karl.models.interfaces import ICatalogSearch
     from karl.views.interfaces import IAdvancedSearchResultsDisplay
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(DummyContent, IDummyContent)
     karltesting.registerAdapter(DummySearch, (Interface), ICatalogSearch)
     karltesting.registerAdapter(DummySearchResultsDisplay,
                                 (Interface, Interface),
                                 IAdvancedSearchResultsDisplay)
     result = self._callFUT(context, request)
     self.assertEqual(result['community'], 'Citizens')
     self.assertEqual(result['terms'], ['yo'])
     self.assertEqual(len(result['results']), 1)
Exemple #14
0
    def test_handle_submit_already_in_karl(self):
        from repoze.lemonade.testing import registerContentFactory
        from karl.models.interfaces import IInvitation
        from karl.utilities.interfaces import IRandomId
        request = testing.DummyRequest()
        context = self._makeCommunity()
        self._registerMailer()
        registerCatalogSearch()
        profile = karltesting.DummyProfile(security_state='active')
        profile.__name__ = 'd'
        registerCatalogSearch(results={'[email protected]': [
            profile,
        ]})

        def nonrandom(size=6):
            return 'A' * size

        karltesting.registerUtility(nonrandom, IRandomId)
        registerContentFactory(DummyInvitation, IInvitation)
        controller = self._makeOne(context, request)
        converted = {
            'email_addresses': [u'*****@*****.**'],
            'text': u'some text',
        }
        karltesting.registerDummyRenderer(
            'karl.views:templates/email_add_existing.pt')
        response = controller.handle_submit(converted)
        self.assertEqual(
            response.location,
            'http://example.com/manage.html?status_message=One+existing+Karl+user+added+to+community.++'
        )
        self.failIf('A' * 6 in context)
        self.assertEqual(context.users.added_groups,
                         [('d', 'group:community:members')])
    def test_handle_submit_new_to_karl(self):
        from repoze.lemonade.testing import registerContentFactory
        from karl.models.interfaces import IInvitation
        from karl.utilities.interfaces import IRandomId
        request = testing.DummyRequest()
        context = self._makeCommunity()
        mailer = self._registerMailer()
        registerCatalogSearch()
        def nonrandom(size=6):
            return 'A' * size
        karltesting.registerUtility(nonrandom, IRandomId)
        registerContentFactory(DummyInvitation, IInvitation)
        controller = self._makeOne(context, request)
        converted = {
            'email_addresses': [u'*****@*****.**'],
            'text': u'some text',
            }

        karltesting.registerDummyRenderer(
            'karl.views:templates/email_invite_new.pt')
        response = controller.handle_submit(converted)
        self.assertEqual(response.location,
          'http://example.com/manage.html?status_message=One+user+invited.++'
                         )
        invitation = context['A'*6]
        self.assertEqual(invitation.email, '*****@*****.**')
        self.assertEqual(1, len(mailer))
        self.assertEqual(mailer[0].mto, [u"*****@*****.**",])
 def test_handle_submit_already_in_karl(self):
     from repoze.lemonade.testing import registerContentFactory
     from karl.models.interfaces import IInvitation
     from karl.utilities.interfaces import IRandomId
     request = testing.DummyRequest()
     context = self._makeCommunity()
     mailer = self._registerMailer()
     registerCatalogSearch()
     profile = karltesting.DummyProfile(security_state='active')
     profile.__name__ = 'd'
     registerCatalogSearch(results={'[email protected]': [profile,]})
     def nonrandom(size=6):
         return 'A' * size
     karltesting.registerUtility(nonrandom, IRandomId)
     registerContentFactory(DummyInvitation, IInvitation)
     controller = self._makeOne(context, request)
     converted = {
         'email_addresses': [u'*****@*****.**'],
         'text': u'some text',
         }
     karltesting.registerDummyRenderer(
         'karl.views:templates/email_add_existing.pt')
     response = controller.handle_submit(converted)
     self.assertEqual(response.location,
       'http://example.com/manage.html?status_message=One+existing+Karl+user+added+to+community.++'
                      )
     self.failIf('A'*6 in context)
     self.assertEqual(context.users.added_groups,
                      [('d', 'group:community:members')])
Exemple #17
0
    def test_handle_submit(self):
        from repoze.lemonade.testing import registerContentFactory
        from karl.content.interfaces import IForum

        def factory(title, desc, creator):
            return testing.DummyModel(title=title,
                                      description=desc,
                                      creator=creator)

        registerContentFactory(factory, IForum)
        converted = {
            'title': 'title',
            'description': 'desc',
            'security_state': 'public'
        }

        context = testing.DummyModel()
        request = testing.DummyRequest()
        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'].description, 'desc')
        self.assertEqual(context['title'].creator, None)
        self.assertEqual(workflow.initialized, True)
Exemple #18
0
    def test_handle_submit_already_in_community(self):
        from repoze.lemonade.testing import registerContentFactory
        from karl.models.interfaces import IInvitation
        from karl.utilities.interfaces import IRandomId
        request = testing.DummyRequest()
        context = self._makeCommunity()
        self._registerMailer()
        registerCatalogSearch()
        profile = karltesting.DummyProfile()
        profile.__name__ = 'a'
        registerCatalogSearch(results={'[email protected]': [
            profile,
        ]})

        def nonrandom(size=6):
            return 'A' * size

        karltesting.registerUtility(nonrandom, IRandomId)
        registerContentFactory(DummyInvitation, IInvitation)
        controller = self._makeOne(context, request)
        converted = {
            'email_addresses': [u'*****@*****.**'],
            'text': u'some text',
        }
        response = controller.handle_submit(converted)
        self.assertEqual(
            response.location,
            'http://example.com/manage.html?status_message=One+user+already+member.'
        )
        self.failIf('A' * 6 in context)
        self.assertEqual(context.users.added_groups, [])
Exemple #19
0
    def test_upload_has_mimetype_instead_of_type(self):
        from cStringIO import StringIO
        from karl.content.interfaces import ICommunityFile
        from repoze.lemonade.testing import registerContentFactory
        karl.testing.registerDummySecurityPolicy("userid")

        def make_image(title, stream, mimetype, filename, creator):
            res = testing.DummyModel()
            res.title = title
            res.mimetype = mimetype
            res.data = stream.read()
            res.filename = filename
            res.creator = creator
            res.is_image = True
            return res

        registerContentFactory(make_image, ICommunityFile)

        context = testing.DummyModel()
        context.title = 'Howdy Doody'
        context.__name__ = 'howdydoody'
        dummy_upload = DummyUpload(StringIO(one_pixel_jpeg), 'image/jpeg')
        dummy_upload.mimetype = dummy_upload.type
        del dummy_upload.type

        form = {'photo': dummy_upload}
        self._callFUT(context, form)
        self.assertTrue('photo' in context)
        photo = context['photo']
        self.assertEqual(photo.title, 'Photo of Howdy Doody')
        self.assertEqual(photo.mimetype, 'image/jpeg')
        self.assertEqual(photo.data, one_pixel_jpeg)
        self.assertEqual(photo.filename, 'test.dat')
        self.assertEqual(photo.creator, 'userid')
Exemple #20
0
 def test_no_creator(self):
     from webob.multidict import MultiDict
     context = testing.DummyModel()
     context.catalog = {}
     context['profiles'] = testing.DummyModel()
     request = testing.DummyRequest(params=MultiDict({'body':'yo'}))
     from zope.interface import Interface
     from karl.models.interfaces import ICatalogSearch
     from karl.views.interfaces import IAdvancedSearchResultsDisplay
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(DummyContent, IDummyContent)
     class LocalDummyContent(testing.DummyModel):
         implements(IDummyContent)
         import datetime
         title = 'Dummy Content'
         modified = datetime.datetime(2010, 5, 12, 2, 42)
     class LocalDummySearch(DummySearch):
         content = LocalDummyContent()
     karltesting.registerAdapter(LocalDummySearch, (Interface),
                             ICatalogSearch)
     karltesting.registerAdapter(DummySearchResultsDisplay,
                             (Interface, Interface),
                             IAdvancedSearchResultsDisplay)
     result = self._callFUT(context, request)
     self.assertEqual(result['terms'], ['yo'])
     self.assertEqual(len(result['results']), 1)
Exemple #21
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 #22
0
    def test_upload_has_mimetype_instead_of_type(self):
        from cStringIO import StringIO
        from karl.content.interfaces import ICommunityFile
        from repoze.lemonade.testing import registerContentFactory
        karl.testing.registerDummySecurityPolicy("userid")
        def make_image(title, stream, mimetype, filename, creator):
            res = testing.DummyModel()
            res.title = title
            res.mimetype = mimetype
            res.data = stream.read()
            res.filename = filename
            res.creator = creator
            res.is_image = True
            return res
        registerContentFactory(make_image, ICommunityFile)

        context = makeRoot()
        context.title = 'Howdy Doody'
        context.__name__ = 'howdydoody'
        context.size = 1000
        dummy_upload = DummyUpload(StringIO(one_pixel_jpeg), 'image/jpeg')
        dummy_upload.mimetype = dummy_upload.type
        del dummy_upload.type

        form = {'photo': dummy_upload}
        self._callFUT(context, form)
        self.assertTrue('photo' in context)
        photo = context['photo']
        self.assertEqual(photo.title, 'Photo of Howdy Doody')
        self.assertEqual(photo.mimetype, 'image/jpeg')
        self.assertEqual(photo.data, one_pixel_jpeg)
        self.assertEqual(photo.filename, 'test.dat')
        self.assertEqual(photo.creator, 'userid')
Exemple #23
0
    def test_handle_submit_new_to_karl(self):
        from repoze.lemonade.testing import registerContentFactory
        from karl.models.interfaces import IInvitation
        from karl.utilities.interfaces import IRandomId
        request = testing.DummyRequest()
        context = self._makeCommunity()
        mailer = self._registerMailer()
        registerCatalogSearch()

        def nonrandom(size=6):
            return 'A' * size

        karltesting.registerUtility(nonrandom, IRandomId)
        registerContentFactory(DummyInvitation, IInvitation)
        controller = self._makeOne(context, request)
        converted = {
            'email_addresses': [u'*****@*****.**'],
            'text': u'some text',
        }

        karltesting.registerDummyRenderer(
            'karl.views:templates/email_invite_new.pt')
        response = controller.handle_submit(converted)
        self.assertEqual(
            response.location,
            'http://example.com/manage.html?status_message=One+user+invited.++'
        )
        invitation = context['A' * 6]
        self.assertEqual(invitation.email, '*****@*****.**')
        self.assertEqual(1, len(mailer))
        self.assertEqual(mailer[0].mto, [
            u"*****@*****.**",
        ])
Exemple #24
0
    def test_with_tag_multiple_users(self):
        from zope.interface import directlyProvides
        from repoze.lemonade.testing import registerContentFactory
        context = testing.DummyModel()
        context.title = 'title'
        karltesting.registerModels({'/foo': context})
        directlyProvides(context, IDummyBlogEntry)
        registerContentFactory(testing.DummyModel, IDummyBlogEntry)
        tags = context.tags = DummyTags(users=('dummy', 'dummy2'))

        def _getRelated(tag, degree=1, community=None, user=None):
            assert tag == 'tag1'
            assert degree == 1
            assert community is None
            assert user is None
            return []

        tags.getRelatedTags = _getRelated
        context.catalog = karltesting.DummyCatalog({1: '/foo'})
        request = testing.DummyRequest()
        request.subpath = [u'tag1']

        result = self._callFUT(context, request)

        self.assertEqual(result['tag'], u'tag1')
        self.assertEqual(len(result['entries']), 1)
        entry = result['entries'][0]
        self.assertEqual(entry['description'], '')
        self.assertEqual(entry['title'], 'title')
        self.assertEqual(entry['href'], 'http://example.com/')
        self.assertEqual(entry['tagusers_count'], '2 people')
        self.assertEqual(entry['type'], 'Blog Entry')
        self.assertEqual(entry['tagusers_href'],
                         'http://example.com/tagusers.html?tag=tag1&docid=1')
        self.assertEqual(len(result['related']), 0)
Exemple #25
0
 def test_known_kind_no_text_term(self):
     from webob.multidict import MultiDict
     from karl.models.interfaces import IGroupSearchFactory
     from repoze.lemonade.testing import registerContentFactory
     from zope.interface import Interface
     content = DummyCommunityContent()
     def search_factory(*arg, **kw):
         return DummySearchFactory(content)
     search_factory.icon = 'foo.jpg'
     search_factory.advanced_search = True
     karltesting.registerUtility(
         search_factory, IGroupSearchFactory, name='People')
     context = testing.DummyModel()
     context.catalog = {}
     context['profiles'] = profiles = testing.DummyModel()
     profiles['tweedle dee'] = testing.DummyModel(title='Tweedle Dee')
     request = testing.DummyRequest(
         params=MultiDict({'kind':'People'}))
     from karl.models.interfaces import ICatalogSearch
     from karl.views.interfaces import IAdvancedSearchResultsDisplay
     registerContentFactory(DummyContent, IDummyContent)
     karltesting.registerAdapter(DummySearch, (Interface),
                             ICatalogSearch)
     karltesting.registerAdapter(DummySearchResultsDisplay,
                             (Interface, Interface),
                             IAdvancedSearchResultsDisplay)
     result = self._callFUT(context, request)
     self.assertEqual(result['terms'], ['People'])
     self.assertEqual(len(result['results']), 1)
Exemple #26
0
 def test_community_search(self):
     context = testing.DummyModel()
     context.title = 'Citizens'
     context.catalog = {}
     context['profiles'] = profiles = testing.DummyModel()
     profiles['tweedle dee'] = testing.DummyModel(title='Tweedle Dee')
     from webob.multidict import MultiDict
     from karl.models.interfaces import ICommunity
     from zope.interface import directlyProvides
     directlyProvides(context, ICommunity)
     request = testing.DummyRequest(params=MultiDict({'body':'yo'}))
     from zope.interface import Interface
     from karl.models.interfaces import ICatalogSearch
     from karl.views.interfaces import IAdvancedSearchResultsDisplay
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(DummyContent, IDummyContent)
     karltesting.registerAdapter(DummySearch, (Interface),
                             ICatalogSearch)
     karltesting.registerAdapter(DummySearchResultsDisplay,
                             (Interface, Interface),
                             IAdvancedSearchResultsDisplay)
     result = self._callFUT(context, request)
     self.assertEqual(result['community'], 'Citizens')
     self.assertEqual(result['terms'], ['yo'])
     self.assertEqual(len(result['results']), 1)
Exemple #27
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 #28
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()
     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.models.tests.test_image import one_pixel_jpeg as dummy_photo
     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.models.interfaces import IImageFile
     from karl.content.interfaces import ICommunityFile
     from karl.views.tests.test_file import DummyImageFile
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(DummyImageFile, IImageFile)
     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.jpg' in context)
     self.assertEqual(site.tags._called_with[1]['tags'],
                      ['tag1', 'tag2'])
Exemple #29
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 #30
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 #31
0
    def test_handle_submit(self):
        context = self.context

        # register dummy IPage content factory
        def factory(title, text, description, creator):
            page = DummyModel(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)
        response = 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'])
 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 #33
0
 def test_blog_entry(self):
     from karl.content.interfaces import IBlogEntry as ctype
     from zope.interface import directlyProvides
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(testing.DummyModel, ctype)
     context = testing.DummyModel()
     directlyProvides(context, ctype)
     self.assertEqual(self._callFUT(context), ('Blog Entry', 'blog.png'))
Exemple #34
0
 def test_wiki_page(self):
     from karl.content.interfaces import IWikiPage as ctype
     from zope.interface import directlyProvides
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(testing.DummyModel, ctype)
     context = testing.DummyModel()
     directlyProvides(context, ctype)
     self.assertEqual(self._callFUT(context), ('Wiki Page', 'wiki.png'))
Exemple #35
0
 def test_blog_entry(self):
     from karl.content.interfaces import IBlogEntry as ctype
     from zope.interface import directlyProvides
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(testing.DummyModel, ctype)
     context = testing.DummyModel()
     directlyProvides(context, ctype)
     self.assertEqual(self._callFUT(context), ('Blog Entry', 'blog.png'))
Exemple #36
0
 def test_community(self):
     from karl.models.interfaces import ICommunity as ctype
     from zope.interface import directlyProvides
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(testing.DummyModel, ctype)
     context = testing.DummyModel()
     directlyProvides(context, ctype)
     self.assertEqual(self._callFUT(context), ('Community', 'building.png'))
Exemple #37
0
 def setUp(self):
     self.config = setUp()
     from adhocracy.core.models.references import child_factory
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(child_factory, self._target_marker_interface)
     from adhocracy.core.models.references import Child
     self.config.registry.registerAdapter(Child)
     self.graph = get_graph()
Exemple #38
0
 def test_calendar_event(self):
     from karl.content.interfaces import ICalendarEvent as ctype
     from zope.interface import directlyProvides
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(testing.DummyModel, ctype)
     context = testing.DummyModel()
     directlyProvides(context, ctype)
     self.assertEqual(self._callFUT(context),
                      ('Event', 'calendar-select.png'))
Exemple #39
0
 def test_news_item(self):
     from karl.content.interfaces import INewsItem as ctype
     from zope.interface import directlyProvides
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(testing.DummyModel, ctype)
     context = testing.DummyModel()
     directlyProvides(context, ctype)
     self.assertEqual(self._callFUT(context),
                      ('News Item', 'newspaper.png'))
Exemple #40
0
 def test_calendar_event(self):
     from karl.content.interfaces import ICalendarEvent as ctype
     from zope.interface import directlyProvides
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(testing.DummyModel, ctype)
     context = testing.DummyModel()
     directlyProvides(context, ctype)
     self.assertEqual(self._callFUT(context),
                      ('Event', 'calendar-select.png'))
Exemple #41
0
 def test_file(self):
     from karl.content.interfaces import ICommunityFile as ctype
     from zope.interface import directlyProvides
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(testing.DummyModel, ctype)
     context = testing.DummyModel()
     directlyProvides(context, ctype)
     self.assertEqual(self._callFUT(context),
                      ('File', 'blue-document-text.png'))
 def setUp(self):
     self.config = setUp()
     from adhocracy.core.models.adhocracyroot import adhocracyroot_factory
     registerContentFactory(adhocracyroot_factory, \
                            self._target_marker_interface)
     from adhocracy.core.models.adhocracyroot\
             import AdhocracyRootLocationAware
     self.config.registry.registerAdapter(AdhocracyRootLocationAware)
     self.graph = get_graph()
Exemple #43
0
 def test_wiki_page(self):
     from karl.content.interfaces import IWikiPage as ctype
     from zope.interface import directlyProvides
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(testing.DummyModel, ctype)
     context = testing.DummyModel()
     directlyProvides(context, ctype)
     self.assertEqual(self._callFUT(context),
                      ('Wiki Page', 'wiki.png'))
Exemple #44
0
 def test_news_item(self):
     from karl.content.interfaces import INewsItem as ctype
     from zope.interface import directlyProvides
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(testing.DummyModel, ctype)
     context = testing.DummyModel()
     directlyProvides(context, ctype)
     self.assertEqual(self._callFUT(context),
                      ('News Item', 'newspaper.png'))
Exemple #45
0
 def test_file(self):
     from karl.content.interfaces import ICommunityFile as ctype
     from zope.interface import directlyProvides
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(testing.DummyModel, ctype)
     context = testing.DummyModel()
     directlyProvides(context, ctype)
     self.assertEqual(self._callFUT(context),
                      ('File', 'blue-document-text.png'))
Exemple #46
0
 def test_community(self):
     from karl.models.interfaces import ICommunity as ctype
     from zope.interface import directlyProvides
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(testing.DummyModel, ctype)
     context = testing.DummyModel()
     directlyProvides(context, ctype)
     self.assertEqual(self._callFUT(context),
                      ('Community', 'building.png'))
 def setUp(self):
     self.config = setUp()
     from adhocracy.core.models.adhocracyroot import adhocracyroot_factory
     registerContentFactory(adhocracyroot_factory, \
                            self._target_marker_interface)
     from adhocracy.core.models.adhocracyroot\
             import AdhocracyRootLocationAware
     self.config.registry.registerAdapter(AdhocracyRootLocationAware)
     self.graph = get_graph()
Exemple #48
0
    def test_handle_submit_success(self):
        registerContentFactory(oitesting.DummyProfile, IProfile)
        class DummyWhoPlugin(object):
            def remember(self, environ, identity):
                self.identity = identity
                return []
        plugin = DummyWhoPlugin()
        whoplugins = {'auth_tkt':plugin}
        self.request.environ['repoze.who.plugins'] = whoplugins
        community = self.context
        community.members_group_name = 'community:members'
        context = testing.DummyModel()
        community['invite'] = context
        community.title = 'Community'
        community.description = 'Community'
        community.sessions = DummySessions()
        context.email = '*****@*****.**'
        self.context = context
        
        controller = self._makeOne()
        self.request.POST = MultiDict([
                ('__start__', u'account:mapping'),
                ('username', u'username'),
                ('__start__', u'password:mapping'),
                ('value', u'safe'),
                ('confirm', u'safe'),
                ('__end__', u'password:mapping'),
                ('__end__', u'account:mapping'),
                ('__start__', u'details:mapping'),
                ('first_name', u'Joe'),
                ('last_name', u'Marks'),
                ('country', u'ZW'),
                ('__start__', u'date_of_birth:mapping'),
                ('year', u''),
                ('month', u''),
                ('day', u''),
                ('__end__', u'date_of_birth:mapping'),
                ('gender', u''),
                ('__end__', u'details:mapping'),
                ('__start__', u'terms:mapping'),
                ('terms_of_use', u'true'),
                ('__end__', u'terms:mapping'),
                ('join up', u'join up')
                ])
        
        response = controller()

        self.assertEqual(response.location,
                         'http://example.com/?status_message=Welcome%21')
        self.assertEqual(community.users.added,
                         ('username', 'username', 'safe', ['community:members']))
        self.assertEqual(plugin.identity, {'repoze.who.userid':'username'})
        profiles = community['profiles']
        self.failUnless('username' in profiles)
        self.assertEqual(profiles['username'].security_state, 'active')
        self.failIf('invite' in community)
        self.assertEqual(len(self.mailer), 1)
Exemple #49
0
    def test_calendar_search_layout(self):
        root = testing.DummyModel()
        root.catalog = {}
        root['profiles'] = profiles = testing.DummyModel()
        profiles['tweedle dee'] = testing.DummyModel(title='Tweedle Dee')
        from webob.multidict import MultiDict
        from karl.models.interfaces import ICommunity
        from zope.interface import directlyProvides

        root['communities'] = testing.DummyModel()
        community = root['communities']['default'] = testing.DummyModel(
            title='citizens')
        office = root['offices'] = testing.DummyModel(title='all rights')
        directlyProvides(community, ICommunity)
        directlyProvides(office, ICommunity)

        request = testing.DummyRequest(params=MultiDict({'body': 'yo'}))
        request.layout_manager = mock.Mock()
        from zope.interface import Interface
        from karl.models.interfaces import ICatalogSearch
        from karl.views.interfaces import IAdvancedSearchResultsDisplay
        from repoze.lemonade.testing import registerContentFactory
        registerContentFactory(DummyContent, IDummyContent)
        karltesting.registerAdapter(DummySearch, (Interface), ICatalogSearch)
        karltesting.registerAdapter(DummySearchResultsDisplay,
                                    (Interface, Interface),
                                    IAdvancedSearchResultsDisplay)

        import karl.views.api
        save_community = karl.views.api.TemplateAPI.community_layout
        save_generic = karl.views.api.TemplateAPI.generic_layout
        try:
            karl.views.api.TemplateAPI.community_layout = 'COMMUNITY'
            karl.views.api.TemplateAPI.generic_layout = 'GENERIC'

            # not on community
            result = self._callFUT(root, request)
            self.assertEqual(result['community'], None)
            self.assertEqual(result['old_layout'], 'GENERIC')
            self.assertEqual(result['show_search_knobs'], False)

            # normal community
            result = self._callFUT(community, request)
            self.assertEqual(result['community'], 'citizens')
            self.assertEqual(result['old_layout'], 'COMMUNITY')
            self.assertEqual(result['show_search_knobs'], False)

            # office (generic layout, ie, wide here)
            result = self._callFUT(office, request)
            self.assertEqual(result['community'], 'all rights')
            self.assertEqual(result['old_layout'], 'GENERIC')
            self.assertEqual(result['show_search_knobs'], False)

        finally:
            karl.views.api.TemplateAPI.community_layout = save_community
            karl.views.api.TemplateAPI.generic_layout = save_generic
Exemple #50
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 #51
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)
        response = controller.handle_submit(converted)
        self.assertEqual(response.location,
                         'http://example.com/communities/community/blog/foo/')
        self.assertEqual(3, len(self.mailer))
        for x in self.mailer:
            self.assertEqual(x.mfrom, '*****@*****.**')
        recipients = reduce(lambda x,y: x+y, [x.mto for x in self.mailer])
        recipients.sort()
        self.assertEqual(["*****@*****.**", "*****@*****.**", "*****@*****.**",], recipients)

        blogentry_url = "http://example.com/communities/community/blog/foo/"

        attachments_url = "%sattachments" % blogentry_url
        self.failUnless(context['foo']['attachments']['test1.txt'])
        self.failUnless(context['foo']['attachments']['test2.txt'])

        from base64 import decodestring
        body = self.mailer[0].msg.get_payload(decode=True)
        self.failUnless("%s/test1.txt" % attachments_url in body)
        self.failUnless("%s/test2.txt" % attachments_url in 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 #52
0
    def test_calendar_search_layout(self):
        root = testing.DummyModel()
        root.catalog = {}
        root['profiles'] = profiles = testing.DummyModel()
        profiles['tweedle dee'] = testing.DummyModel(title='Tweedle Dee')
        from webob.multidict import MultiDict
        from karl.models.interfaces import ICommunity
        from zope.interface import directlyProvides

        root['communities'] = testing.DummyModel()
        community = root['communities']['default'] = testing.DummyModel(title='citizens')
        office = root['offices'] = testing.DummyModel(title='all rights')
        directlyProvides(community, ICommunity)
        directlyProvides(office, ICommunity)

        request = testing.DummyRequest(params=MultiDict({'body':'yo'}))
        request.layout_manager = mock.Mock()
        from zope.interface import Interface
        from karl.models.interfaces import ICatalogSearch
        from karl.views.interfaces import IAdvancedSearchResultsDisplay
        from repoze.lemonade.testing import registerContentFactory
        registerContentFactory(DummyContent, IDummyContent)
        karltesting.registerAdapter(DummySearch, (Interface),
                                ICatalogSearch)
        karltesting.registerAdapter(DummySearchResultsDisplay,
                                (Interface, Interface),
                                IAdvancedSearchResultsDisplay)

        import karl.views.api
        save_community = karl.views.api.TemplateAPI.community_layout
        save_generic = karl.views.api.TemplateAPI.generic_layout
        try:
            karl.views.api.TemplateAPI.community_layout = 'COMMUNITY'
            karl.views.api.TemplateAPI.generic_layout = 'GENERIC'

            # not on community
            result = self._callFUT(root, request)
            self.assertEqual(result['community'], None)
            self.assertEqual(result['old_layout'], 'GENERIC')
            self.assertEqual(result['show_search_knobs'], False)

            # normal community
            result = self._callFUT(community, request)
            self.assertEqual(result['community'], 'citizens')
            self.assertEqual(result['old_layout'], 'COMMUNITY')
            self.assertEqual(result['show_search_knobs'], False)

            # office (generic layout, ie, wide here)
            result = self._callFUT(office, request)
            self.assertEqual(result['community'], 'all rights')
            self.assertEqual(result['old_layout'], 'GENERIC')
            self.assertEqual(result['show_search_knobs'], False)

        finally:
            karl.views.api.TemplateAPI.community_layout = save_community
            karl.views.api.TemplateAPI.generic_layout = save_generic
 def test_handle_submit_success(self):
     from karl.models.interfaces import IProfile
     from repoze.lemonade.testing import registerContentFactory
     from repoze.sendmail.interfaces import IMailDelivery
     from repoze.workflow.testing import registerDummyWorkflow
     from karl.models.interfaces import ICommunity
     from zope.interface import directlyProvides
     workflow = registerDummyWorkflow('security')
     mailer = karltesting.DummyMailer()
     karltesting.registerUtility(mailer, IMailDelivery)
     registerContentFactory(DummyContent, IProfile)
     class DummyWhoPlugin(object):
         def remember(self, environ, identity):
             self.identity = identity
             return []
     request = self._makeRequest()
     community = testing.DummyModel()
     profiles = testing.DummyModel()
     community['profiles'] = profiles
     community.users = karltesting.DummyUsers()
     community.members_group_name = 'community:members'
     directlyProvides(community, ICommunity)
     context = self._makeContext()
     community['invite'] = context
     community.title = 'Community'
     community.description = 'Community'
     community.sessions = DummySessions()
     context.email = '*****@*****.**'
     controller = self._makeOne(context, request)
     converted = {'password':'******', 'password_confirm':'1',
                  'username':'******',
                  'firstname':'firstname', 'lastname':'lastname',
                  'phone':'phone', 'extension':'extension',
                  'department':'department', 'position':'position',
                  'organization':'organization', 'location':'location',
                  'country':'country', 'websites':['website'],
                  'languages':'languages', 'date_format':'en-US',
                  'biography':'bio',
                  }
     karltesting.registerDummyRenderer(
         'karl.views:templates/email_accept_invitation.pt')
     response = controller.handle_submit(converted)
     self.assertEqual(response.location,
                      'http://example.com/?status_message=Welcome%21')
     self.assertEqual(community.users.added,
                      ('username', 'username', '1', ['community:members']))
     profiles = community['profiles']
     self.failUnless('username' in profiles)
     self.assertEqual(workflow.initialized,[profiles['username']])
     profile = profiles['username']
     self.assertEqual('phone', profile.phone)
     self.assertEqual('firstname', profile.firstname)
     self.assertEqual('lastname', profile.lastname)
     self.assertEqual('bio', profile.biography)
     self.failIf('invite' in community)
     self.assertEqual(len(mailer), 1)
Exemple #54
0
    def setUp(self):
        cleanUp()

        self.root = root = testing.DummyModel()
        root.users = testing.DummyUsers()
        root['profiles'] = testing.DummyModel()

        from repoze.lemonade.testing import registerContentFactory
        from karl.models.interfaces import IProfile
        registerContentFactory(testing.DummyProfile, IProfile)
Exemple #55
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 #56
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 #57
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 #58
0
    def test_create(self):
        from repoze.lemonade.testing import registerContentFactory
        from zope.interface import Interface
        registerContentFactory(testing.DummyModel, Interface)
        adapter = self._make_one()
        adapter.create(self.profiles)

        self.failUnless('crossi' in self.profiles.keys())
        profile = self.profiles['crossi']

        self.assertEqual(profile.__name__, 'crossi')
        self.assertEqual(profile.firstname, 'User')
        self.assertEqual(profile.lastname, 'Two')
        self.assertEqual(profile.email, '*****@*****.**')
        self.assertEqual(profile.phone, '212-555-1212')
        self.assertEqual(profile.extension, '123')
        self.assertEqual(profile.department, 'Human Resources')
        self.assertEqual(profile.position,
                         'Responsable Bibliotheque Monique Calixte')
        self.assertEqual(profile.organization, 'Open Society Institute')
        self.assertEqual(profile.location, 'Port-au-Prince')
        self.assertEqual(profile.country, 'HT')
        self.assertEqual(profile.websites,
                         ('http://www.example.com/profile', ))
        self.assertEqual(profile.languages, 'Italian, English, Esperanto')
        self.assertEqual(profile.office, 'Fondation Connaissance et Liberte')
        self.assertEqual(profile.room_no, '1234')
        self.assertEqual(profile.biography,
                         'Was born, grew up, is still alive.')
        self.assertEqual(profile.home_path, 'offices/national-foundation')
        self.assertEqual(profile.categories['entities'], [
            'open-society-institute',
            'hardees',
        ])
        self.assertEqual(profile.categories['offices'], [
            'fondation-connaissance-et-liberte',
            'hand-creme',
        ])
        self.assertEqual(profile.categories['departments'], [
            'information-retrieval',
            'paper-chase',
        ])
        self.assertEqual(profile.categories['boards'], [
            '1-x-3',
        ])

        info = self.root.users.get_by_id('crossi')
        info.pop('password')
        self.assertEqual(
            info, {
                'id': 'crossi',
                'login': '******',
                'groups': set(['group.KarlStaff', 'group.AnotherGroup']),
            })
Exemple #59
0
 def test_with_filename(self):
     from karl.content.interfaces import ICommunityFile
     from StringIO import StringIO
     attachments = [ DummyFile(filename='abc', mimetype='text/plain',
                               file=StringIO('abc')) ]
     folder = testing.DummyModel()
     from repoze.lemonade.testing import registerContentFactory
     registerContentFactory(DummyFile, ICommunityFile)
     request = testing.DummyRequest()
     self._callFUT(attachments, folder, 'chris', request)
     self.failUnless('abc' in folder)