コード例 #1
0
ファイル: tests.py プロジェクト: Astalaseven/lernanta
    def setUp(self):
        self.client = Client()
        self.locale = 'en'
        django_user = User(
            username=self.test_username,
            email=self.test_email,
        )
        self.user = create_profile(django_user)
        self.user.set_password(self.test_password)
        self.user.save()

        self.project = Project(name='Reply Project',
            short_description='This project is to test replies',
            long_description='No really, its good',
        )
        self.project.save()
        
        participation = Participation(project=self.project,
            user=self.user, organizing=True)
        participation.save()
        
        self.page = Page(author=self.user,
            project=self.project,
            title='task title',
            sub_header='Tagline',
            content='Content',
            index=2)
        self.page.save()

        self.comment = PageComment()
        self.comment.page_object = self.page
        self.comment.scope_object = self.project
        self.comment.author = self.user
        self.comment.content = "blah blah"
        self.comment.save()
コード例 #2
0
ファイル: models.py プロジェクト: Inkbug/lernanta
 def accept(self, as_organizer=False, reviewer=None):
     if not reviewer:
         reviewer = self.sign_up.author
     is_organizing = self.project.organizers().filter(
         user=self.author).exists()
     is_participating = self.project.participants().filter(
         user=self.author).exists()
     if not is_organizing and not is_participating:
         participation = Participation(project=self.project,
             user=self.author, organizing=as_organizer)
         participation.save()
     accept_content = render_to_string(
         "signups/accept_sign_up_comment.html",
         {'as_organizer': as_organizer})
     accept_comment = PageComment(content=accept_content,
         author=reviewer, page_object=self, scope_object=self.project)
     accept_comment.save()
     self.accepted = True
     self.save()
コード例 #3
0
 def accept(self, as_organizer=False, reviewer=None):
     if not reviewer:
         reviewer = self.sign_up.author
     is_organizing = self.project.organizers().filter(
         user=self.author).exists()
     is_participating = self.project.participants().filter(
         user=self.author).exists()
     if not is_organizing and not is_participating:
         participation = Participation(project=self.project,
             user=self.author, organizing=as_organizer)
         participation.save()
     accept_content = render_to_string(
         "signups/accept_sign_up_comment.html",
         {'as_organizer': as_organizer})
     accept_comment = PageComment(content=accept_content,
         author=reviewer, page_object=self, scope_object=self.project)
     accept_comment.save()
     self.accepted = True
     self.save()
コード例 #4
0
def comment_page_callback(request, page_model, page_app_label, page_pk,
                          scope_model, scope_app_label, scope_pk):
    """ callback used when replying by email to an activity"""

    log.debug("replies.views.comment_page_callback")

    api_key = request.POST.get('api-key')
    if not api_key == settings.INTERNAL_API_KEY:
        log.error('Invalid API KEY used for internal API!')
        return http.HttpResponseForbidden()

    from_user = request.POST.get('from')
    reply_text = request.POST.get('text')
    reply_text = utils.extract_reply(reply_text)

    user = None
    try:
        user = UserProfile.objects.get(username=from_user)
    except UserProfile.DoesNotExist:
        log.error("Invalid user attempted reply: {0}".format(from_user))

    page_object = None
    try:
        page_ct_cls = ContentType.objects.get(
            model=page_model, app_label=page_app_label).model_class()
        page_object = page_ct_cls.objects.get(pk=page_pk)
    except:
        log.error("could not find page object")

    scope_object = None
    try:
        scope_ct_cls = ContentType.objects.get(
            model=scope_model, app_label=scope_app_label).model_class()
        scope_object = get_object_or_404(scope_ct_cls, pk=scope_pk)
    except:
        log.error("could not find scope object")

    if user and user.can_post() and page_object and page_object.can_comment(
            user.user) and scope_object and reply_text:
        comment = PageComment(content=reply_text)
        comment.page_object = page_object
        comment.scope_object = scope_object
        comment.author = user
        comment.sent_by_email = True
        comment.save()

    return http.HttpResponse(status=200)
コード例 #5
0
ファイル: tests.py プロジェクト: mkcode/lernanta
    def setUp(self):
        self.client = Client()
        self.locale = 'en'
        django_user = User(
            username=self.test_username,
            email=self.test_email,
        )
        self.user = create_profile(django_user)
        self.user.set_password(self.test_password)
        self.user.save()

        self.project = Project(
            name='Reply Project',
            short_description='This project is to test replies',
            long_description='No really, its good',
        )
        self.project.save()

        participation = Participation(project=self.project,
                                      user=self.user,
                                      organizing=True)
        participation.save()

        self.page = Page(author=self.user,
                         project=self.project,
                         title='task title',
                         sub_header='Tagline',
                         content='Content',
                         index=2)
        self.page.save()

        self.comment = PageComment()
        self.comment.page_object = self.page
        self.comment.scope_object = self.project
        self.comment.author = self.user
        self.comment.content = "blah blah"
        self.comment.save()
コード例 #6
0
ファイル: tests.py プロジェクト: mkcode/lernanta
    def test_repy(self):
        comment = PageComment()
        comment.page_object = self.page
        comment.scope_object = self.project
        comment.author = self.user
        comment.content = "blah blah"
        comment.save()

        self.client.login(username=self.test_username,
                          password=self.test_password)

        # post reply
        data = {'content': 'This is a reply'}
        reply_url = '/{0}/comments/{1}/reply/'.format(self.locale, comment.id)
        response = self.client.post(reply_url, data)

        comments = PageComment.objects.all()
        self.assertEquals(comments.count(), 2)
コード例 #7
0
ファイル: tests.py プロジェクト: mkcode/lernanta
    def test_comment_reply_api_key(self):
        comment = PageComment()
        comment.page_object = self.page
        comment.scope_object = self.project
        comment.author = self.user
        comment.content = "blah blah"
        comment.save()

        data = {
            u'api-key': 'notthecorrectkey',
            u'from': self.test_username,
            u'text': u'Some stealthy reply that won\'t make it in!\n',
        }

        response = self.client.post(
            '/{0}/comments/{1}/email_reply/'.format(self.locale, comment.id),
            data)
        self.assertEqual(response.status_code, 403)
コード例 #8
0
ファイル: tests.py プロジェクト: Acidburn0zzz/lernanta
    def test_comment_reply_api_key(self):
        comment = PageComment()
        comment.page_object = self.page
        comment.scope_object = self.project
        comment.author = self.user
        comment.content = "blah blah"
        comment.save()
        
        data = {
            u'api-key': 'notthecorrectkey',
            u'from': self.test_username,
            u'text': u'Some stealthy reply that won\'t make it in!\n',
        }

        response = self.client.post('/{0}/comments/{1}/email_reply/'.format(self.locale, comment.id), data)
        self.assertEqual(response.status_code, 403)
コード例 #9
0
ファイル: tests.py プロジェクト: josmas/lernanta
    def test_comment_reply_api_key(self):
        comment = PageComment()
        comment.page_object = self.page
        comment.scope_object = self.project
        comment.author = self.user
        comment.content = "blah blah"
        comment.save()

        data = {
            u"api-key": "notthecorrectkey",
            u"from": u"*****@*****.**",
            u"text": u"Some stealthy reply that won't make it in!\n",
        }

        response = self.client.post("/{0}/comments/{1}/email_reply/".format(self.locale, comment.id), data)
        self.assertEqual(response.status_code, 403)
コード例 #10
0
ファイル: tests.py プロジェクト: Acidburn0zzz/lernanta
    def test_repy(self):
        comment = PageComment()
        comment.page_object = self.page
        comment.scope_object = self.project
        comment.author = self.user
        comment.content = "blah blah"
        comment.save()

        self.client.login(username=self.test_username, password=self.test_password)

        # post reply
        data = { 'content': 'This is a reply' }
        reply_url = '/{0}/comments/{1}/reply/'.format(self.locale, comment.id)
        response = self.client.post(reply_url, data)
            
        comments = PageComment.objects.all()
        self.assertEquals(comments.count(), 2)
コード例 #11
0
ファイル: tests.py プロジェクト: josmas/lernanta
    def test_reply_by_email(self):
        # post a comment
        comment = PageComment()
        comment.page_object = self.page
        comment.scope_object = self.project
        comment.author = self.user
        comment.content = "blah blah"
        comment.save()

        data = {u"api-key": settings.INTERNAL_API_KEY, u"from": u"*****@*****.**", u"text": u"Maybe this time\n"}

        comment_count = PageComment.objects.filter(sent_by_email=True).count()
        response = self.client.post("/{0}/comments/{1}/email_reply/".format(self.locale, comment.id), data)
        self.assertEqual(response.status_code, 200)

        comments = PageComment.objects.filter(sent_by_email=True)
        self.assertEquals(comments.count(), comment_count + 1)
コード例 #12
0
ファイル: views.py プロジェクト: aespaldi/lernanta
def comment_page_callback(request, page_model, page_app_label, page_pk,
        scope_model, scope_app_label, scope_pk):
    """ callback used when replying by email to an activity"""

    log.debug("replies.views.comment_page_callback")

    api_key = request.POST.get('api-key')
    if not api_key == settings.INTERNAL_API_KEY:
        log.error('Invalid API KEY used for internal API!')
        return http.HttpResponseForbidden()
    
    from_user = request.POST.get('from')
    reply_text = request.POST.get('text')
    reply_text = utils.extract_reply(reply_text)

    user = None
    try:
        user = UserProfile.objects.get(username=from_user)
    except UserProfile.DoesNotExist:
        log.error("Invalid user attempted reply: {0}".format(from_user))

    page_object = None
    try:
        page_ct_cls = ContentType.objects.get(model=page_model,
        app_label=page_app_label).model_class()
        page_object = page_ct_cls.objects.get(pk=page_pk)
    except:
        log.error("could not find page object")

    scope_object = None
    try:
        scope_ct_cls = ContentType.objects.get(model=scope_model,
            app_label=scope_app_label).model_class()
        scope_object = get_object_or_404(scope_ct_cls, pk=scope_pk)
    except:
        log.error("could not find scope object")

    if user and page_object and page_object.can_comment(user.user) and scope_object and reply_text:
        comment = PageComment(content=reply_text)
        comment.page_object = page_object
        comment.scope_object = scope_object
        comment.author = user
        comment.sent_by_email = True
        comment.save()

    return http.HttpResponse(status=200)
コード例 #13
0
ファイル: tests.py プロジェクト: mkcode/lernanta
    def test_reply_by_email(self):
        # post a comment
        comment = PageComment()
        comment.page_object = self.page
        comment.scope_object = self.project
        comment.author = self.user
        comment.content = "blah blah"
        comment.save()

        data = {
            u'api-key': settings.INTERNAL_API_KEY,
            u'from': self.test_username,
            u'text': u'Maybe this time\n',
        }

        comment_count = PageComment.objects.filter(sent_by_email=True).count()
        response = self.client.post(
            '/{0}/comments/{1}/email_reply/'.format(self.locale, comment.id),
            data)
        self.assertEqual(response.status_code, 200)

        comments = PageComment.objects.filter(sent_by_email=True)
        self.assertEquals(comments.count(), comment_count + 1)
コード例 #14
0
ファイル: tests.py プロジェクト: Acidburn0zzz/lernanta
    def test_reply_by_email(self):
        # post a comment
        comment = PageComment()
        comment.page_object = self.page
        comment.scope_object = self.project
        comment.author = self.user
        comment.content = "blah blah"
        comment.save()
        
        data = {
            u'api-key': settings.INTERNAL_API_KEY,
            u'from': self.test_username,
            u'text': u'Maybe this time\n',
        }

        comment_count = PageComment.objects.filter(sent_by_email=True).count()
        response = self.client.post('/{0}/comments/{1}/email_reply/'.format(self.locale, comment.id), data)
        self.assertEqual(response.status_code, 200)

        comments = PageComment.objects.filter(sent_by_email=True)
        self.assertEquals(comments.count(), comment_count+1)
コード例 #15
0
ファイル: tests.py プロジェクト: mkcode/lernanta
class NotificationsTests(TestCase):

    test_username = '******'
    test_email = '*****@*****.**'
    test_password = '******'

    def setUp(self):
        self.client = Client()
        self.locale = 'en'
        django_user = User(
            username=self.test_username,
            email=self.test_email,
        )
        self.user = create_profile(django_user)
        self.user.set_password(self.test_password)
        self.user.save()

        self.project = Project(
            name='Reply Project',
            short_description='This project is to test replies',
            long_description='No really, its good',
        )
        self.project.save()

        participation = Participation(project=self.project,
                                      user=self.user,
                                      organizing=True)
        participation.save()

        self.page = Page(author=self.user,
                         project=self.project,
                         title='task title',
                         sub_header='Tagline',
                         content='Content',
                         index=2)
        self.page.save()

        self.comment = PageComment()
        self.comment.page_object = self.page
        self.comment.scope_object = self.project
        self.comment.author = self.user
        self.comment.content = "blah blah"
        self.comment.save()

    def test_send_notification(self):
        """ Test non replyable notification """

        #TODO use templates and context that doesn't rely on another app!
        subject_template = 'replies/emails/post_comment_subject.txt'
        body_template = 'replies/emails/post_comment.txt'
        context = {
            'comment': self.comment,
            'domain': 'example.org',
        }
        message_count = len(mail.outbox)
        send_notifications(self.user, subject_template, body_template, context)
        self.assertEqual(ResponseToken.objects.count(), 0)

        #TODO check that 1 email was sent
        #self.assertEqual(len(mail.outbox), message_count + 1)

    def test_notification_with_response(self):
        """ Test notification with possible response """
        subject_template = 'replies/emails/post_comment_subject.txt'
        body_template = 'replies/emails/post_comment.txt'
        context = {
            'comment': self.comment,
            'domain': 'example.org',
        }
        send_notifications(self.user, subject_template, body_template, context,
                           "/call/me/back")
        self.assertEqual(ResponseToken.objects.count(), 1)

    def test_respond_by_email_hook(self):
        """ Test that email hook works and returns status code 200 """
        data = {
            u'from': [u'Dirk Uys <*****@*****.**>'],
            u'attachments': [u'0'],
            u'to': [u'*****@*****.**'],
            u'text': [u'Maybe this time\n'],
            u'envelope': [
                u'{"to":["*****@*****.**"],"from":"*****@*****.**"}'
            ],
            u'headers': [
                u'Received: by 127.0.0.1 with SMTP id 7HNiGL0knF Thu, 21 Jun 2012 10:41:34 -0500 (CDT)\nReceived: from mail-ey0-f182.google.com (mail-ey0-f182.google.com [209.85.215.182]) by mx2.sendgrid.net (Postfix) with ESMTPS id 165E0179EA68 for <*****@*****.**>; Thu, 21 Jun 2012 10:41:33 -0500 (CDT)\nReceived: by eabm6 with SMTP id m6so287981eab.41 for <*****@*****.**>; Thu, 21 Jun 2012 08:41:31 -0700 (PDT)\nX-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type :x-gm-message-state; bh=U5LQcX1VeMMflboN7DWaD8mhHxEUMyxJKSioavl+PaY=; b=mod67Tg9pJkedv/ired6n89xAik5vPltmw+78esRAyAivlBnX845MVF1quPz3ApUCR 3D0a4knRfG1DXL7I5WHPUelHmT7vSurAtHPrW4ndJgyCoPjsd32rL9rIfrFpJGAWWd9+ DAO7gRMx0CtPNXL3UoOKtZTEMT1tF+Zt6UMPY+kZwP64lO4/k6dc6XYfGMYTEU2HUill CIftL/P7KjbcopBXpKF5YAJGHOazmw1QcRlTFaIW6ymW1uSZ5ieNUgZVQXIXw4/760O5 TJCZsh2qACfZ2PWWOfBV6bu0kjsab5TrsbBUdlu5uRoLeJxXqYzTroJ8+cbGPhrqZSGT 5XnA==\nMIME-Version: 1.0\nReceived: by 10.152.109.198 with SMTP id hu6mr26806411lab.21.1340293291509; Thu, 21 Jun 2012 08:41:31 -0700 (PDT)\nReceived: by 10.112.11.97 with HTTP; Thu, 21 Jun 2012 08:41:31 -0700 (PDT)\nDate: Thu, 21 Jun 2012 17:41:31 +0200\nMessage-ID: <CAAcFfF+a-WTypUHo2aPi_jjemNM8RRD3habXoFpopCOcFs=M0g@mail.gmail.com>\nSubject: test3\nFrom: Dirk Uys <*****@*****.**>\nTo: [email protected]\nContent-Type: multipart/alternative; boundary=bcaec54b49d689096204c2fd5911\nX-Gm-Message-State: ALoCoQnzUWK4n+vh7QKSKjeJhgRrSUiCswAUpJmKNuhvGunMWMyixYjwSRwhiFRrOv0DHlpBmkke\n'
            ],
            u'html': [u'Maybe this time<br>\n'],
            u'charsets': [
                u'{"to":"UTF-8","html":"ISO-8859-1","subject":"UTF-8","from":"UTF-8","text":"ISO-8859-1"}'
            ],
            u'dkim': [u'none'],
            u'SPF': [u'none'],
            u'subject': [u'test3']
        }
        response = self.client.post(
            '/{0}/notifications/response/'.format(self.locale), data)
        self.assertEqual(response.status_code, 200)

    def test_auto_reply(self):
        """ Test that email hook works and rejects auto responder replies """
        data = {
            u'from': [u'Dirk Uys <*****@*****.**>'],
            u'attachments': [u'0'],
            u'to': [u'*****@*****.**'],
            u'text': [u'Maybe this time\n'],
            u'envelope': [
                u'{"to":["*****@*****.**"],"from":"*****@*****.**"}'
            ],
            u'headers': [
                u'Received: by 127.0.0.1 with SMTP id 7HNiGL0knF Thu, 21 Jun 2012 10:41:34 -0500 (CDT)\nReceived: from mail-ey0-f182.google.com (mail-ey0-f182.google.com [209.85.215.182]) by mx2.sendgrid.net (Postfix) with ESMTPS id 165E0179EA68 for <*****@*****.**>; Thu, 21 Jun 2012 10:41:33 -0500 (CDT)\nReceived: by eabm6 with SMTP id m6so287981eab.41 for <*****@*****.**>; Thu, 21 Jun 2012 08:41:31 -0700 (PDT)\nX-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type :x-gm-message-state; bh=U5LQcX1VeMMflboN7DWaD8mhHxEUMyxJKSioavl+PaY=; b=mod67Tg9pJkedv/ired6n89xAik5vPltmw+78esRAyAivlBnX845MVF1quPz3ApUCR 3D0a4knRfG1DXL7I5WHPUelHmT7vSurAtHPrW4ndJgyCoPjsd32rL9rIfrFpJGAWWd9+ DAO7gRMx0CtPNXL3UoOKtZTEMT1tF+Zt6UMPY+kZwP64lO4/k6dc6XYfGMYTEU2HUill CIftL/P7KjbcopBXpKF5YAJGHOazmw1QcRlTFaIW6ymW1uSZ5ieNUgZVQXIXw4/760O5 TJCZsh2qACfZ2PWWOfBV6bu0kjsab5TrsbBUdlu5uRoLeJxXqYzTroJ8+cbGPhrqZSGT 5XnA==\nMIME-Version: 1.0\nReceived: by 10.152.109.198 with SMTP id hu6mr26806411lab.21.1340293291509; Thu, 21 Jun 2012 08:41:31 -0700 (PDT)\nReceived: by 10.112.11.97 with HTTP; Thu, 21 Jun 2012 08:41:31 -0700 (PDT)\nDate: Thu, 21 Jun 2012 17:41:31 +0200\nMessage-ID: <CAAcFfF+a-WTypUHo2aPi_jjemNM8RRD3habXoFpopCOcFs=M0g@mail.gmail.com>\nSubject: test3\nFrom: Dirk Uys <*****@*****.**>\nTo: [email protected]\nContent-Type: multipart/alternative; boundary=bcaec54b49d689096204c2fd5911\nX-Autorespond: dont\nX-Gm-Message-State: ALoCoQnzUWK4n+vh7QKSKjeJhgRrSUiCswAUpJmKNuhvGunMWMyixYjwSRwhiFRrOv0DHlpBmkke\n'
            ],
            u'html': [u'Maybe this time<br>\n'],
            u'charsets': [
                u'{"to":"UTF-8","html":"ISO-8859-1","subject":"UTF-8","from":"UTF-8","text":"ISO-8859-1"}'
            ],
            u'dkim': [u'none'],
            u'SPF': [u'none'],
            u'subject': [u'test3']
        }
        response = self.client.post(
            '/{0}/notifications/response/'.format(self.locale), data)
        self.assertEqual(response.status_code, 200)
        #X-Autoreply: yes
        #Auto-Submitted: auto-replied

    def test_reply_by_email(self):

        subject_template = 'replies/emails/post_comment_subject.txt'
        body_template = 'replies/emails/post_comment.txt'
        context = {
            'comment': self.comment,
            'domain': 'example.org',
        }
        callback_url = "/{0}/comments/{1}/email_reply/".format(
            self.locale, self.comment.id)
        send_notifications(self.user, subject_template, body_template, context,
                           callback_url)
        self.assertEqual(ResponseToken.objects.count(), 1)

        token = ResponseToken.objects.all()[0]

        data = {
            u'from': [u'Testing <*****@*****.**>'],
            u'to': [u'reply+{0}@reply.p2pu.org'.format(token.response_token)],
            u'text': [u'Maybe this time\n'],
        }

        #post_notification_response(token, '*****@*****.**', 'my response')

        response = self.client.post(
            '/{0}/notifications/response/'.format(self.locale), data)
        self.assertEqual(response.status_code, 200)

        # i wish, the test db isn't running a server that can take the callback
        #comments = PageComment.objects.all()
        #self.assertEquals(comments.count(), 2)

    def test_notification_create(self):
        """ Test sending a notification using the API """

        notification_data = {
            'api-key': settings.INTERNAL_API_KEY,
            'user': self.user.username,
            'subject': 'notification',
            'text': 'Some notification text.\nAnd some more',
            'callback_url': 'http://mentor.p2pu.org/message/43234',
            'from': self.user.username,
        }

        json_data = json.dumps(notification_data)
        response = self.client.post(
            '/{0}/notifications/notification/'.format(self.locale), json_data,
            "text/json")
        self.assertEqual(response.status_code, 200)
コード例 #16
0
ファイル: tests.py プロジェクト: Astalaseven/lernanta
class NotificationsTests(TestCase):

    test_username = '******'
    test_email = '*****@*****.**'
    test_password = '******'

    def setUp(self):
        self.client = Client()
        self.locale = 'en'
        django_user = User(
            username=self.test_username,
            email=self.test_email,
        )
        self.user = create_profile(django_user)
        self.user.set_password(self.test_password)
        self.user.save()

        self.project = Project(name='Reply Project',
            short_description='This project is to test replies',
            long_description='No really, its good',
        )
        self.project.save()
        
        participation = Participation(project=self.project,
            user=self.user, organizing=True)
        participation.save()
        
        self.page = Page(author=self.user,
            project=self.project,
            title='task title',
            sub_header='Tagline',
            content='Content',
            index=2)
        self.page.save()

        self.comment = PageComment()
        self.comment.page_object = self.page
        self.comment.scope_object = self.project
        self.comment.author = self.user
        self.comment.content = "blah blah"
        self.comment.save()

    def test_send_notification(self):
        """ Test non replyable notification """

        #TODO use templates and context that doesn't rely on another app!
        subject_template = 'replies/emails/post_comment_subject.txt'
        body_template = 'replies/emails/post_comment.txt'
        context = {
            'comment': self.comment,
            'domain': 'example.org',
        }
        message_count = len(mail.outbox)
        send_notifications(self.user, subject_template, body_template, context)
        self.assertEqual(ResponseToken.objects.count(), 0)

        #TODO check that 1 email was sent
        #self.assertEqual(len(mail.outbox), message_count + 1)

    def test_notification_with_response(self):
        """ Test notification with possible response """
        subject_template = 'replies/emails/post_comment_subject.txt'
        body_template = 'replies/emails/post_comment.txt'
        context = {
            'comment': self.comment,
            'domain': 'example.org',
        }
        send_notifications(self.user, subject_template, body_template, context, "/call/me/back")
        self.assertEqual(ResponseToken.objects.count(), 1)

    def test_respond_by_email_hook(self):
        """ Test that email hook works and returns status code 200 """
        data = {
            u'from': [u'Dirk Uys <*****@*****.**>'],
            u'attachments': [u'0'],
            u'to': [u'*****@*****.**'],
            u'text': [u'Maybe this time\n'],
            u'envelope': [u'{"to":["*****@*****.**"],"from":"*****@*****.**"}'],
            u'headers': [
                u'Received: by 127.0.0.1 with SMTP id 7HNiGL0knF Thu, 21 Jun 2012 10:41:34 -0500 (CDT)\nReceived: from mail-ey0-f182.google.com (mail-ey0-f182.google.com [209.85.215.182]) by mx2.sendgrid.net (Postfix) with ESMTPS id 165E0179EA68 for <*****@*****.**>; Thu, 21 Jun 2012 10:41:33 -0500 (CDT)\nReceived: by eabm6 with SMTP id m6so287981eab.41 for <*****@*****.**>; Thu, 21 Jun 2012 08:41:31 -0700 (PDT)\nX-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type :x-gm-message-state; bh=U5LQcX1VeMMflboN7DWaD8mhHxEUMyxJKSioavl+PaY=; b=mod67Tg9pJkedv/ired6n89xAik5vPltmw+78esRAyAivlBnX845MVF1quPz3ApUCR 3D0a4knRfG1DXL7I5WHPUelHmT7vSurAtHPrW4ndJgyCoPjsd32rL9rIfrFpJGAWWd9+ DAO7gRMx0CtPNXL3UoOKtZTEMT1tF+Zt6UMPY+kZwP64lO4/k6dc6XYfGMYTEU2HUill CIftL/P7KjbcopBXpKF5YAJGHOazmw1QcRlTFaIW6ymW1uSZ5ieNUgZVQXIXw4/760O5 TJCZsh2qACfZ2PWWOfBV6bu0kjsab5TrsbBUdlu5uRoLeJxXqYzTroJ8+cbGPhrqZSGT 5XnA==\nMIME-Version: 1.0\nReceived: by 10.152.109.198 with SMTP id hu6mr26806411lab.21.1340293291509; Thu, 21 Jun 2012 08:41:31 -0700 (PDT)\nReceived: by 10.112.11.97 with HTTP; Thu, 21 Jun 2012 08:41:31 -0700 (PDT)\nDate: Thu, 21 Jun 2012 17:41:31 +0200\nMessage-ID: <CAAcFfF+a-WTypUHo2aPi_jjemNM8RRD3habXoFpopCOcFs=M0g@mail.gmail.com>\nSubject: test3\nFrom: Dirk Uys <*****@*****.**>\nTo: [email protected]\nContent-Type: multipart/alternative; boundary=bcaec54b49d689096204c2fd5911\nX-Gm-Message-State: ALoCoQnzUWK4n+vh7QKSKjeJhgRrSUiCswAUpJmKNuhvGunMWMyixYjwSRwhiFRrOv0DHlpBmkke\n'],
            u'html': [u'Maybe this time<br>\n'],
            u'charsets': [u'{"to":"UTF-8","html":"ISO-8859-1","subject":"UTF-8","from":"UTF-8","text":"ISO-8859-1"}'],
            u'dkim': [u'none'],
            u'SPF': [u'none'],
            u'subject': [u'test3']
        }
        response = self.client.post('/{0}/notifications/response/'.format(self.locale), data)
        self.assertEqual(response.status_code, 200)

    def test_auto_reply(self):
        """ Test that email hook works and rejects auto responder replies """
        data = {
            u'from': [u'Dirk Uys <*****@*****.**>'],
            u'attachments': [u'0'],
            u'to': [u'*****@*****.**'],
            u'text': [u'Maybe this time\n'],
            u'envelope': [u'{"to":["*****@*****.**"],"from":"*****@*****.**"}'],
            u'headers': [
                u'Received: by 127.0.0.1 with SMTP id 7HNiGL0knF Thu, 21 Jun 2012 10:41:34 -0500 (CDT)\nReceived: from mail-ey0-f182.google.com (mail-ey0-f182.google.com [209.85.215.182]) by mx2.sendgrid.net (Postfix) with ESMTPS id 165E0179EA68 for <*****@*****.**>; Thu, 21 Jun 2012 10:41:33 -0500 (CDT)\nReceived: by eabm6 with SMTP id m6so287981eab.41 for <*****@*****.**>; Thu, 21 Jun 2012 08:41:31 -0700 (PDT)\nX-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type :x-gm-message-state; bh=U5LQcX1VeMMflboN7DWaD8mhHxEUMyxJKSioavl+PaY=; b=mod67Tg9pJkedv/ired6n89xAik5vPltmw+78esRAyAivlBnX845MVF1quPz3ApUCR 3D0a4knRfG1DXL7I5WHPUelHmT7vSurAtHPrW4ndJgyCoPjsd32rL9rIfrFpJGAWWd9+ DAO7gRMx0CtPNXL3UoOKtZTEMT1tF+Zt6UMPY+kZwP64lO4/k6dc6XYfGMYTEU2HUill CIftL/P7KjbcopBXpKF5YAJGHOazmw1QcRlTFaIW6ymW1uSZ5ieNUgZVQXIXw4/760O5 TJCZsh2qACfZ2PWWOfBV6bu0kjsab5TrsbBUdlu5uRoLeJxXqYzTroJ8+cbGPhrqZSGT 5XnA==\nMIME-Version: 1.0\nReceived: by 10.152.109.198 with SMTP id hu6mr26806411lab.21.1340293291509; Thu, 21 Jun 2012 08:41:31 -0700 (PDT)\nReceived: by 10.112.11.97 with HTTP; Thu, 21 Jun 2012 08:41:31 -0700 (PDT)\nDate: Thu, 21 Jun 2012 17:41:31 +0200\nMessage-ID: <CAAcFfF+a-WTypUHo2aPi_jjemNM8RRD3habXoFpopCOcFs=M0g@mail.gmail.com>\nSubject: test3\nFrom: Dirk Uys <*****@*****.**>\nTo: [email protected]\nContent-Type: multipart/alternative; boundary=bcaec54b49d689096204c2fd5911\nX-Autorespond: dont\nX-Gm-Message-State: ALoCoQnzUWK4n+vh7QKSKjeJhgRrSUiCswAUpJmKNuhvGunMWMyixYjwSRwhiFRrOv0DHlpBmkke\n'],
            u'html': [u'Maybe this time<br>\n'],
            u'charsets': [u'{"to":"UTF-8","html":"ISO-8859-1","subject":"UTF-8","from":"UTF-8","text":"ISO-8859-1"}'],
            u'dkim': [u'none'],
            u'SPF': [u'none'],
            u'subject': [u'test3']
        }
        response = self.client.post('/{0}/notifications/response/'.format(self.locale), data)
        self.assertEqual(response.status_code, 200)
        #X-Autoreply: yes
        #Auto-Submitted: auto-replied


    def test_reply_by_email(self):

        subject_template = 'replies/emails/post_comment_subject.txt'
        body_template = 'replies/emails/post_comment.txt'
        context = {
            'comment': self.comment,
            'domain': 'example.org',
        }
        callback_url = "/{0}/comments/{1}/email_reply/".format(self.locale, self.comment.id)
        send_notifications(
            self.user, subject_template, body_template, context, callback_url
        )
        self.assertEqual(ResponseToken.objects.count(), 1)

        token = ResponseToken.objects.all()[0]
        
        data = {
            u'from': [u'Testing <*****@*****.**>'],
            u'to': [u'reply+{0}@reply.p2pu.org'.format(token.response_token)],
            u'text': [u'Maybe this time\n'],
        }

        #post_notification_response(token, '*****@*****.**', 'my response') 

        response = self.client.post('/{0}/notifications/response/'.format(self.locale), data)
        self.assertEqual(response.status_code, 200)

        # i wish, the test db isn't running a server that can take the callback
        #comments = PageComment.objects.all()
        #self.assertEquals(comments.count(), 2)

    def test_notification_create(self):
        """ Test sending a notification using the API """

        notification_data = {
            'api-key': settings.INTERNAL_API_KEY,
            'user': self.user.username,
            'subject': 'notification',
            'text': 'Some notification text.\nAnd some more',
            'callback_url': 'http://mentor.p2pu.org/message/43234',
            'from': self.user.username,
        }

        json_data = json.dumps(notification_data)
        response = self.client.post(
            '/{0}/notifications/notification/'.format(self.locale), 
            json_data,
            "text/json"
        )
        self.assertEqual(response.status_code, 200)
コード例 #17
0
ファイル: content_tags.py プロジェクト: nikkar/lernanta
def task_toggle_completion(request, page, ignore_post_data=False):
    project = page.project
    total_count = Page.objects.filter(project__slug=project.slug, listed=True, deleted=False).count()
    ajax_data = {"upon_completion_redirect": page.project.get_absolute_url(), "total_count": total_count}
    progressbar_value = 0
    task_completion = None
    next_badge = None
    is_last_badge = True
    task_link_submit_form = None
    task_badge_apply_form = None
    badges_to_apply = list(page.badges_to_apply.order_by("id"))
    if request.user.is_authenticated():
        profile = request.user.get_profile()
        ajax_data["completed_count"] = PerUserTaskCompletion.objects.filter(
            page__project__slug=project.slug, page__deleted=False, unchecked_on__isnull=True, user=profile
        ).count()
        if total_count:
            progressbar_value = ajax_data["completed_count"] * 100 / total_count
        try:
            task_completion = PerUserTaskCompletion.objects.filter(user=profile, page=page, unchecked_on__isnull=True)[
                0
            ]
        except IndexError:
            pass
        if badges_to_apply and task_completion:
            next_badge, is_last_badge = page.get_next_badge_can_apply(profile)
            if not task_completion.url:
                if not ignore_post_data and request.method == "POST":
                    task_link_submit_form = TaskLinkSubmitForm(bool(next_badge), request.POST, instance=task_completion)
                    if task_link_submit_form.is_valid():
                        task_completion = task_link_submit_form.save()
                        if task_link_submit_form.cleaned_data["post_link"]:
                            link_comment_content = render_to_string(
                                "content/_post_link_comment.html", {"url": task_completion.url}
                            )
                            link_comment = PageComment(
                                content=link_comment_content,
                                author=profile,
                                page_object=page,
                                scope_object=page.project,
                            )
                            link_comment.save()
                            ajax_data["posted_link_comment_html"] = render_to_string(
                                "replies/_comment_threads.html",
                                {"comments": [link_comment], "is_challenge": True, "user": request.user},
                            ).strip()
                        if task_link_submit_form.cleaned_data.get("apply_for_badges", False) and next_badge:
                            task_badge_apply_form = TaskBadgeApplyForm(initial={"badge_slug": next_badge.slug})
                        task_link_submit_form = None
                else:
                    task_link_submit_form = TaskLinkSubmitForm(show_badge_apply_option=bool(next_badge))
            elif not ignore_post_data and next_badge and request.method == "POST":
                task_badge_apply_form = TaskBadgeApplyForm(request.POST)
                if task_badge_apply_form.is_valid():
                    try:
                        badge = page.badges_to_apply.get(slug=task_badge_apply_form.cleaned_data["badge_slug"])
                        submission = task_badge_apply_form.save(commit=False)
                        submission.url = task_completion.url
                        submission.badge = badge
                        submission.author = profile
                        submission.save()
                        next_badge, is_last_badge = page.get_next_badge_can_apply(profile)
                        if next_badge:
                            task_badge_apply_form = TaskBadgeApplyForm(initial={"badge_slug": next_badge.slug})
                        else:
                            task_badge_apply_form = None
                    except Badge.DoesNotExist:
                        task_badge_apply_form = None

        for badge in badges_to_apply:
            try:
                badge.awarded = Award.objects.filter(user=profile, badge=badge)[0]
            except IndexError:
                badge.awarded = False
            try:
                badge.applied = Submission.objects.filter(author=profile, badge=badge)[0]
            except IndexError:
                badge.applied = False
            elegible = badge.is_eligible(profile)
            badge.show_apply = not badge.awarded and not badge.applied and elegible

    ajax_data.update(
        {"stay_on_page": bool(task_link_submit_form or task_badge_apply_form), "progressbar_value": progressbar_value}
    )

    context = {
        "page": page,
        "request": request,
        "can_comment": page.can_comment(request.user),
        "next_page": page.get_next_page(),
        "task_completion": task_completion,
        "next_badge": next_badge,
        "is_last_badge": is_last_badge,
        "task_link_submit_form": task_link_submit_form,
        "task_badge_apply_form": task_badge_apply_form,
        "badges_to_apply": badges_to_apply,
        "ajax_data": ajax_data,
    }
    return context
コード例 #18
0
ファイル: content_tags.py プロジェクト: brylie/lernanta
def task_toggle_completion(request, page, ignore_post_data=False):
    project = page.project
    total_count = Page.objects.filter(project__slug=project.slug, listed=True,
        deleted=False).count()
    ajax_data = {
        'upon_completion_redirect': page.project.get_absolute_url(),
        'total_count': total_count,
    }
    progressbar_value = 0
    task_completion = None
    next_badge = None
    is_last_badge = True
    task_link_submit_form = None
    task_badge_apply_form = None
    badges_to_apply = list(page.badges_to_apply.order_by('id'))
    if request.user.is_authenticated():
        profile = request.user.get_profile()
        ajax_data['completed_count'] = PerUserTaskCompletion.objects.filter(
            page__project__slug=project.slug, page__deleted=False,
            unchecked_on__isnull=True, user=profile).count()
        if total_count:
            progressbar_value = (ajax_data['completed_count'] * 100 / total_count)
        try:
            task_completion = PerUserTaskCompletion.objects.filter(
                user=profile, page=page, unchecked_on__isnull=True)[0]
        except IndexError:
            pass
        if badges_to_apply and task_completion:
            next_badge, is_last_badge = page.get_next_badge_can_apply(profile)
            if not task_completion.url:
                if not ignore_post_data and request.method == 'POST':
                    task_link_submit_form = TaskLinkSubmitForm(bool(next_badge), request.POST,
                        instance=task_completion)
                    if task_link_submit_form.is_valid():
                        task_completion = task_link_submit_form.save()
                        if task_link_submit_form.cleaned_data['post_link']:
                            link_comment_content = render_to_string(
                                "content/_post_link_comment.html",
                                {'url': task_completion.url})
                            link_comment = PageComment(content=link_comment_content,
                                author=profile, page_object=page, scope_object=page.project)
                            link_comment.save()
                            ajax_data['posted_link_comment_html'] = render_to_string(
                                'replies/_comment_threads.html', {'comments': [link_comment],
                                'is_challenge': True, 'user': request.user}).strip()
                        if task_link_submit_form.cleaned_data.get('apply_for_badges', False) and next_badge:
                            task_badge_apply_form = TaskBadgeApplyForm(
                                initial={'badge_slug': next_badge.slug})
                        task_link_submit_form = None
                else:
                    task_link_submit_form = TaskLinkSubmitForm(
                        show_badge_apply_option=bool(next_badge))
            elif not ignore_post_data and next_badge and request.method == 'POST':
                task_badge_apply_form = TaskBadgeApplyForm(request.POST)
                if task_badge_apply_form.is_valid():
                    try:
                        badge = page.badges_to_apply.get(slug=task_badge_apply_form.cleaned_data['badge_slug'])
                        submission = task_badge_apply_form.save(commit=False)
                        submission.url = task_completion.url
                        submission.badge = badge
                        submission.author = profile
                        submission.save()
                        next_badge, is_last_badge = page.get_next_badge_can_apply(profile)
                        if next_badge:
                            task_badge_apply_form = TaskBadgeApplyForm(
                                initial={'badge_slug': next_badge.slug})
                        else:
                            task_badge_apply_form = None
                    except Badge.DoesNotExist:
                        task_badge_apply_form = None

        for badge in badges_to_apply:
            try:
                badge.awarded = Award.objects.filter(user=profile,
                    badge=badge)[0]
            except IndexError:
                badge.awarded = False
            try:
                badge.applied = Submission.objects.filter(author=profile,
                    badge=badge)[0]
            except IndexError:
                badge.applied = False
            elegible = badge.is_eligible(request.user)
            badge.show_apply = (not badge.awarded and not badge.applied and elegible)

    ajax_data.update({
        'stay_on_page': bool(task_link_submit_form or task_badge_apply_form),
        'progressbar_value':  progressbar_value,
    })

    context = {
        'page': page,
        'request': request,
        'can_comment': page.can_comment(request.user),
        'next_page': page.get_next_page(),
        'task_completion': task_completion,
        'next_badge': next_badge,
        'is_last_badge': is_last_badge,
        'task_link_submit_form': task_link_submit_form,
        'task_badge_apply_form': task_badge_apply_form,
        'badges_to_apply': badges_to_apply,
        'ajax_data': ajax_data,
    }
    return context
コード例 #19
0
def task_toggle_completion(request, page, ignore_post_data=False):
    project = page.project
    total_count = Page.objects.filter(project__slug=project.slug,
                                      listed=True,
                                      deleted=False).count()
    ajax_data = {
        'upon_completion_redirect': page.project.get_absolute_url(),
        'total_count': total_count,
    }
    progressbar_value = 0
    task_completion = None
    next_badge = None
    is_last_badge = True
    task_link_submit_form = None
    task_badge_apply_form = None
    badges_to_apply = list(page.badges_to_apply.order_by('id'))
    if request.user.is_authenticated():
        profile = request.user.get_profile()
        ajax_data['completed_count'] = PerUserTaskCompletion.objects.filter(
            page__project__slug=project.slug,
            page__deleted=False,
            unchecked_on__isnull=True,
            user=profile).count()
        if total_count:
            progressbar_value = (ajax_data['completed_count'] * 100 /
                                 total_count)
        try:
            task_completion = PerUserTaskCompletion.objects.filter(
                user=profile, page=page, unchecked_on__isnull=True)[0]
        except IndexError:
            pass
        if badges_to_apply and task_completion:
            next_badge, is_last_badge = page.get_next_badge_can_apply(profile)
            if not task_completion.url:
                if not ignore_post_data and request.method == 'POST':
                    task_link_submit_form = TaskLinkSubmitForm(
                        bool(next_badge),
                        request.POST,
                        instance=task_completion)
                    if task_link_submit_form.is_valid():
                        task_completion = task_link_submit_form.save()
                        if task_link_submit_form.cleaned_data['post_link']:
                            link_comment_content = render_to_string(
                                "content/_post_link_comment.html",
                                {'url': task_completion.url})
                            link_comment = PageComment(
                                content=link_comment_content,
                                author=profile,
                                page_object=page,
                                scope_object=page.project)
                            link_comment.save()
                            ajax_data[
                                'posted_link_comment_html'] = render_to_string(
                                    'replies/_comment_threads.html', {
                                        'comments': [link_comment],
                                        'is_challenge': True,
                                        'user': request.user
                                    }).strip()
                        if task_link_submit_form.cleaned_data.get(
                                'apply_for_badges', False) and next_badge:
                            task_badge_apply_form = TaskBadgeApplyForm(
                                initial={'badge_slug': next_badge.slug})
                        task_link_submit_form = None
                else:
                    task_link_submit_form = TaskLinkSubmitForm(
                        show_badge_apply_option=bool(next_badge))
            elif not ignore_post_data and next_badge and request.method == 'POST':
                task_badge_apply_form = TaskBadgeApplyForm(request.POST)
                if task_badge_apply_form.is_valid():
                    try:
                        badge = page.badges_to_apply.get(
                            slug=task_badge_apply_form.
                            cleaned_data['badge_slug'])
                        submission = task_badge_apply_form.save(commit=False)
                        submission.url = task_completion.url
                        submission.badge = badge
                        submission.author = profile
                        submission.save()
                        next_badge, is_last_badge = page.get_next_badge_can_apply(
                            profile)
                        if next_badge:
                            task_badge_apply_form = TaskBadgeApplyForm(
                                initial={'badge_slug': next_badge.slug})
                        else:
                            task_badge_apply_form = None
                    except Badge.DoesNotExist:
                        task_badge_apply_form = None

        for badge in badges_to_apply:
            try:
                badge.awarded = Award.objects.filter(user=profile,
                                                     badge=badge)[0]
            except IndexError:
                badge.awarded = False
            try:
                badge.applied = Submission.objects.filter(author=profile,
                                                          badge=badge)[0]
            except IndexError:
                badge.applied = False
            elegible = badge.is_eligible(request.user)
            badge.show_apply = (not badge.awarded and not badge.applied
                                and elegible)

    ajax_data.update({
        'stay_on_page':
        bool(task_link_submit_form or task_badge_apply_form),
        'progressbar_value':
        progressbar_value,
    })

    context = {
        'page': page,
        'request': request,
        'can_comment': page.can_comment(request.user),
        'next_page': page.get_next_page(),
        'task_completion': task_completion,
        'next_badge': next_badge,
        'is_last_badge': is_last_badge,
        'task_link_submit_form': task_link_submit_form,
        'task_badge_apply_form': task_badge_apply_form,
        'badges_to_apply': badges_to_apply,
        'ajax_data': ajax_data,
    }
    return context