Exemple #1
0
    def test_dict_operations(self):
        # test dict operations and acquisition wrapping

        # Create a conversation. In this case we doesn't assign it to an
        # object, as we just want to check the Conversation object API.
        conversation = IConversation(self.portal.doc1)

        # Add a comment. Note: in real life, we always create comments via the
        # factory to allow different factories to be swapped in

        comment1 = createObject('plone.Comment')
        comment1.text = 'Comment text'

        new_id1 = conversation.addComment(comment1)

        comment2 = createObject('plone.Comment')
        comment2.text = 'Comment text'

        new_id2 = conversation.addComment(comment2)

        # check if get returns a comment object, and None if the key
        # can not be found
        self.assertTrue(IComment.providedBy(conversation.get(new_id1)))
        self.assertTrue(IComment.providedBy(conversation.get(new_id2)))
        self.assertEqual(conversation.get(123), None)

        # check if keys return the ids of all comments
        self.assertEqual(len(conversation.keys()), 2)
        self.assertTrue(new_id1 in conversation.keys())
        self.assertTrue(new_id2 in conversation.keys())
        self.assertFalse(123 in conversation.keys())

        # check if items returns (key, comment object) pairs
        self.assertEqual(len(conversation.items()), 2)
        self.assertTrue((new_id1, comment1) in conversation.items())
        self.assertTrue((new_id2, comment2) in conversation.items())

        # check if values returns the two comment objects
        self.assertEqual(len(conversation.values()), 2)
        self.assertTrue(comment1 in conversation.values())
        self.assertTrue(comment2 in conversation.values())

        # check if comment ids are in iterkeys
        self.assertTrue(new_id1 in conversation.iterkeys())
        self.assertTrue(new_id2 in conversation.iterkeys())
        self.assertFalse(123 in conversation.iterkeys())

        # check if comment objects are in itervalues
        self.assertTrue(comment1 in conversation.itervalues())
        self.assertTrue(comment2 in conversation.itervalues())

        # check if iteritems returns (key, comment object) pairs
        self.assertTrue((new_id1, comment1) in conversation.iteritems())
        self.assertTrue((new_id2, comment2) in conversation.iteritems())
    def test_dict_operations(self):
        # test dict operations and acquisition wrapping

        # Create a conversation. In this case we doesn't assign it to an
        # object, as we just want to check the Conversation object API.
        conversation = IConversation(self.portal.doc1)

        # Add a comment. Note: in real life, we always create comments via the
        # factory to allow different factories to be swapped in

        comment1 = createObject('plone.Comment')
        comment1.text = 'Comment text'

        new_id1 = conversation.addComment(comment1)

        comment2 = createObject('plone.Comment')
        comment2.text = 'Comment text'

        new_id2 = conversation.addComment(comment2)

        # check if get returns a comment object, and None if the key
        # can not be found
        self.assertTrue(IComment.providedBy(conversation.get(new_id1)))
        self.assertTrue(IComment.providedBy(conversation.get(new_id2)))
        self.assertEqual(conversation.get(123), None)

        # check if keys return the ids of all comments
        self.assertEqual(len(conversation.keys()), 2)
        self.assertTrue(new_id1 in conversation.keys())
        self.assertTrue(new_id2 in conversation.keys())
        self.assertFalse(123 in conversation.keys())

        # check if items returns (key, comment object) pairs
        self.assertEqual(len(conversation.items()), 2)
        self.assertTrue((new_id1, comment1) in conversation.items())
        self.assertTrue((new_id2, comment2) in conversation.items())

        # check if values returns the two comment objects
        self.assertEqual(len(conversation.values()), 2)
        self.assertTrue(comment1 in conversation.values())
        self.assertTrue(comment2 in conversation.values())

        # check if comment ids are in iterkeys
        self.assertTrue(new_id1 in conversation.iterkeys())
        self.assertTrue(new_id2 in conversation.iterkeys())
        self.assertFalse(123 in conversation.iterkeys())

        # check if comment objects are in itervalues
        self.assertTrue(comment1 in conversation.itervalues())
        self.assertTrue(comment2 in conversation.itervalues())

        # check if iteritems returns (key, comment object) pairs
        self.assertTrue((new_id1, comment1) in conversation.iteritems())
        self.assertTrue((new_id2, comment2) in conversation.iteritems())
 def conversations(self):
     conversations = []
     for conversation_id in self.context.objectIds():
         conv = self.context[conversation_id]
         pad_conv = IConversation(self.context[conversation_id])
         # XXX: last_commenter should be in metadata
         comments = pad_conv.items()
         if comments:
             last_commenter = comments[-1:][0][1].author_name
         else:
             last_commenter = ""
         conversations.append({
             'title': conv.title,
             'url': conv.absolute_url(),
             'total_comments': pad_conv.total_comments,
             'last_commenter': last_commenter,
             'last_comment_date': pad_conv.last_comment_date,
         })
     return conversations
Exemple #4
0
 def conversations(self):
     conversations = []
     for conversation_id in self.context.objectIds():
         conv = self.context[conversation_id]
         pad_conv = IConversation(self.context[conversation_id])
         # XXX: last_commenter should be in metadata
         comments = pad_conv.items()
         if comments:
             last_commenter = comments[-1:][0][1].author_name
         else:
             last_commenter = ""
         conversations.append({
             'title':
             conv.title,
             'url':
             conv.absolute_url(),
             'total_comments':
             pad_conv.total_comments(),
             'last_commenter':
             last_commenter,
             'last_comment_date':
             pad_conv.last_comment_date,
         })
     return conversations
    def unmaintained_testFormat(self):
        expected_mail = {'Review Monograph': [u'''From: Recensio.net <fake>
To: Recensio.net <fake>
Bcc: [email protected]
Subject: Benachrichtigung über Kommentareingang

Sehr geehrte/r Tadeusz Kotłowski,

zu Ihrer Schrift
    Tadeusz Kotłowski: Test ReviewMonograph No 0: Dzieje państwa i społeczeństwa 1890–1945, 2008, 978-83-60448-39-7 (rezensiert von Стоичков, Христо)

erschien eine Rezension in der Zeitschrift
Zeitschrift 1, Summer, Issue 2. Diese Rezension wurde auf der Rezensionsplattform recensio.net publiziert.
Jack Commenter hat am ... diese Rezension bzw. Ihre Schrift kommentiert. Sie haben hier die Gelegenheit, den Kommentar zu lesen und ggf. darauf zu reagieren:

http://nohost/plone/sample-reviews/newspapera/summer/issue-2/ReviewMonograph...

Für Rückfragen steht Ihnen die recensio.net-Redaktion gern zur Verfügung: Recensio.net <fake>.

Mit freundlichen Grüßen,
Ihr recensio.net-Team''',
                                            u'''From: Recensio.net <fake>
To: [email protected]
Bcc: [email protected]
Subject: Benachrichtigung über Kommentareingang

Sehr geehrte/r Hugh Commenter,

Sie haben die Schrift bzw. die Internetressource
    Tadeusz Kotłowski: Test ReviewMonograph No 0: Dzieje państwa i społeczeństwa 1890–1945, 2008, 978-83-60448-39-7 (rezensiert von Стоичков, Христо) in Zeitschrift 1, Summer, Issue 2

auf recensio.net kommentiert. Jack Commenter hat am ... einen weiteren Kommentar abgegeben. Sie haben hier die Gelegenheit, diesen zu lesen und ggf. darauf zu reagieren:

http://nohost/plone/sample-reviews/newspapera/summer/issue-2/ReviewMonograph...

Für Rückfragen steht Ihnen die recensio.net-Redaktion gern zur Verfügung: Recensio.net <fake>.

Mit freundlichen Grüßen,
Ihr recensio.net-Team'''],
                         'Presentation Article Review': [u'''From: Recensio.net <fake>
To: [email protected]
Bcc: [email protected]
Subject: Benachrichtigung über Kommentareingang

Sehr geehrte/r Hugh Commenter,

Sie haben die Schrift bzw. die Internetressource
    Tadeusz Kotłowski: Test PresentationArticleReview No 0: Dzieje państwa i społeczeństwa 1890–1945, 2008,  (präsentiert von Стоичков, Христо)

auf recensio.net kommentiert. Jack Commenter hat am ... einen weiteren Kommentar abgegeben. Sie haben hier die Gelegenheit, diesen zu lesen und ggf. darauf zu reagieren:

http://nohost/plone/Members/fake_member/PresentationArticleReview...

Für Rückfragen steht Ihnen die recensio.net-Redaktion gern zur Verfügung: Recensio.net <fake>.

Mit freundlichen Grüßen,
Ihr recensio.net-Team''']}

        portal = self.layer['portal']
        reviews = [portal['sample-reviews']['newspapera']['summer']['issue-2'].objectValues()[0], 
            portal.Members['fake_member'].objectValues()[0]]

        request = self.layer['request']
        directlyProvides(request, IRecensioLayer)

        setRoles(portal, TEST_USER_ID, ['Manager'])
        login(portal, TEST_USER_NAME)
        alsoProvides(request, IDefaultBrowserLayer)

        membership_tool = getToolByName(portal, 'portal_membership')
        membership_tool.addMember('commenter', '12345', [], [], properties={'email': '*****@*****.**', 'preferred_language': 'de'})
        membership_tool.addMember('commenter2', '12345', [], [], properties={'email': '*****@*****.**', 'preferred_language': 'de'})

        for review in reviews:
            conversation = IConversation(aq_inner(review))
            comment = createObject('plone.Comment')
            comment.author_username = '******'
            comment.author_name = 'Jack Commenter'
            comment.author_email = '*****@*****.**'
            comment.text = 'Comment Text!'
            conversation.addComment(comment)
            comment2 = createObject('plone.Comment')
            comment2.author_username = '******'
            comment2.author_name = 'Hugh Commenter'
            comment2.author_email = '*****@*****.**'
            comment2.text = 'Second Comment Text!'
            conversation.addComment(comment2)

            mail_schema = IMailSchema(portal)
            mail_schema.email_from_address = 'fake'

            comment2 = conversation.items()[0][1]
            view = getMultiAdapter((comment2, request), name='notify_author_new_comment')
            class MockMailHost(object):
                sentMail = []
                def send(self, messageText, mto, mfrom, subject, charset):
                    self.sentMail.append(messageText)
            view.mailhost = MockMailHost()
            #view.ts = getToolByName(portal, 'translation_service')

            view()
            self.assertEquals(len(view.mailhost.sentMail), len(expected_mail[review.portal_type]))
            for i in range(len(view.mailhost.sentMail)):
                for lineno, (expected, real) in enumerate(
                                          zip(expected_mail[review.portal_type][i].split('\n'),
                                              view.mailhost.sentMail[i].split('\n'))):
                    self.assertTrue(compare(expected, real), ("Error in Line %i:\nExp:\n%s\nGot:\n%s" % (lineno, '<<<\n'.join(expected_mail[review.portal_type][i].split('\n')[max(0, lineno-2):lineno+3]), '<<<\n'.join(view.mailhost.sentMail[i].split('\n')[max(0, lineno-2):lineno+3]))).encode('ascii', 'ignore'))
Exemple #6
0
    def __iter__(self):
        for item in self.previous:
            pathkey = self.pathkey(*list(item.keys()))[0]
            path = item[pathkey]
            obj = self.context.unrestrictedTraverse(
                str(path).lstrip("/"), None)
            # path doesn't exist
            if obj is None:
                yield item
                continue
            discussion = item.get("discussions", [])
            if not discussion:
                yield item
                continue

            id_map = {}
            conversation = IConversation(obj)

            # remove all comments to avoid duplication when override is disabled  # noqa
            if list(conversation.items()):
                comments_id = [x[0] for x in conversation.items()]
                for value in comments_id:
                    try:
                        del conversation[value]
                    except Exception:
                        logger.warning(
                            "WARNING: Discussion with id {0} not found".
                            format(  # noqa
                                value))
                        pass

            for comment in discussion:
                new_comment = CommentFactory()

                new_comment.text = comment.get("text")
                new_comment.creator = comment.get("creator")
                new_comment.author_name = comment.get("author_name")
                new_comment.author_username = comment.get("author_username")
                new_comment.author_email = comment.get("author_email")
                new_comment.in_reply_to = id_map.get(
                    comment.get("in_reply_to"), 0)
                new_comment.mime_type = comment.get("mime_type")
                new_comment._owner = comment.get("_owner")
                new_comment.__ac_local_roles__ = comment.get(
                    "__ac_local_roles__")
                new_comment.user_notification = comment.get(
                    "user_notification")
                new_comment.creation_date = DateTime(
                    comment.get("creation_date")).asdatetime()
                new_comment.modification_date = DateTime(
                    comment.get("modification_date")).asdatetime()

                conversation.addComment(new_comment)

                comment_wf = new_comment.workflow_history.data.get(
                    "comment_review_workflow")
                if comment_wf:
                    new_comment.workflow_history.data.get(
                        "comment_review_workflow")[  # noqa
                            0]["review_state"] = comment["status"]

                id_map.update(
                    {comment.get("comment_id"): int(new_comment.comment_id)})

                logger.info(("Added comment with id {0} to item {1}".format(
                    new_comment.comment_id, obj.absolute_url())))
            yield item