當前位置: 首頁>>代碼示例>>Python>>正文


Python db.Notification類代碼示例

本文整理匯總了Python中rhodecode.model.db.Notification的典型用法代碼示例。如果您正苦於以下問題:Python Notification類的具體用法?Python Notification怎麽用?Python Notification使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Notification類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_create

    def test_create(self):
        self.log_user()
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = u'CommentOnRevision'

        params = {'text': text}
        response = self.app.post(url(controller='changeset', action='comment',
                                     repo_name=HG_REPO, revision=rev),
                                     params=params)
        # Test response...
        self.assertEqual(response.status, '302 Found')
        response.follow()

        response = self.app.get(url(controller='changeset', action='index',
                                repo_name=HG_REPO, revision=rev))
        # test DB
        self.assertEqual(ChangesetComment.query().count(), 1)
        response.mustcontain('''<div class="comments-number">%s comment '''
                             '''(0 inline)</div>''' % 1)

        self.assertEqual(Notification.query().count(), 1)
        self.assertEqual(ChangesetComment.query().count(), 1)

        notification = Notification.query().all()[0]

        ID = ChangesetComment.query().first().comment_id
        self.assertEqual(notification.type_,
                         Notification.TYPE_CHANGESET_COMMENT)
        sbj = (u'/vcs_test_hg/changeset/'
               '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % ID)
        print "%s vs %s" % (sbj, notification.subject)
        self.assertTrue(sbj in notification.subject)
開發者ID:adamscieszko,項目名稱:rhodecode,代碼行數:32,代碼來源:test_changeset_comments.py

示例2: test_create_notification

    def test_create_notification(self):
        self.assertEqual([], Notification.query().all())
        self.assertEqual([], UserNotification.query().all())

        usrs = [self.u1, self.u2]
        notification = NotificationModel().create(created_by=self.u1,
                                           subject=u'subj', body=u'hi there',
                                           recipients=usrs)
        Session().commit()
        u1 = User.get(self.u1)
        u2 = User.get(self.u2)
        u3 = User.get(self.u3)
        notifications = Notification.query().all()
        self.assertEqual(len(notifications), 1)

        self.assertEqual(notifications[0].recipients, [u1, u2])
        self.assertEqual(notification.notification_id,
                         notifications[0].notification_id)

        unotification = UserNotification.query()\
            .filter(UserNotification.notification == notification).all()

        self.assertEqual(len(unotification), len(usrs))
        self.assertEqual(set([x.user.user_id for x in unotification]),
                         set(usrs))
開發者ID:break123,項目名稱:rhodecode,代碼行數:25,代碼來源:test_notifications.py

示例3: test_create_inline

    def test_create_inline(self):
        self.log_user()
        rev = "27cd5cce30c96924232dffcd24178a07ffeb5dfc"
        text = u"CommentOnRevision"
        f_path = "vcs/web/simplevcs/views/repository.py"
        line = "n1"

        params = {"text": text, "f_path": f_path, "line": line}
        response = self.app.post(
            url(controller="changeset", action="comment", repo_name=HG_REPO, revision=rev), params=params
        )
        # Test response...
        self.assertEqual(response.status, "302 Found")
        response.follow()

        response = self.app.get(url(controller="changeset", action="index", repo_name=HG_REPO, revision=rev))
        # test DB
        self.assertEqual(ChangesetComment.query().count(), 1)
        response.mustcontain("""<div class="comments-number">0 comment(s)""" """ (%s inline)</div>""" % 1)
        response.mustcontain(
            """<div style="display:none" class="inline-comment-placeholder" """
            """path="vcs/web/simplevcs/views/repository.py" """
            """target_id="vcswebsimplevcsviewsrepositorypy">"""
        )

        self.assertEqual(Notification.query().count(), 1)
        self.assertEqual(ChangesetComment.query().count(), 1)

        notification = Notification.query().all()[0]
        ID = ChangesetComment.query().first().comment_id
        self.assertEqual(notification.type_, Notification.TYPE_CHANGESET_COMMENT)
        sbj = u"/vcs_test_hg/changeset/" "27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s" % ID
        print "%s vs %s" % (sbj, notification.subject)
        self.assertTrue(sbj in notification.subject)
開發者ID:seacoastboy,項目名稱:rhodecode,代碼行數:34,代碼來源:test_changeset_comments.py

示例4: test_create

    def test_create(self):
        self.log_user()
        rev = "27cd5cce30c96924232dffcd24178a07ffeb5dfc"
        text = u"CommentOnRevision"

        params = {"text": text}
        response = self.app.post(
            url(controller="changeset", action="comment", repo_name=HG_REPO, revision=rev), params=params
        )
        # Test response...
        self.assertEqual(response.status, "302 Found")
        response.follow()

        response = self.app.get(url(controller="changeset", action="index", repo_name=HG_REPO, revision=rev))
        # test DB
        self.assertEqual(ChangesetComment.query().count(), 1)
        self.assertTrue("""<div class="comments-number">%s """ """comment(s) (0 inline)</div>""" % 1 in response.body)

        self.assertEqual(Notification.query().count(), 1)
        self.assertEqual(ChangesetComment.query().count(), 1)

        notification = Notification.query().all()[0]

        ID = ChangesetComment.query().first().comment_id
        self.assertEqual(notification.type_, Notification.TYPE_CHANGESET_COMMENT)
        sbj = u"/vcs_test_hg/changeset/" "27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s" % ID
        print "%s vs %s" % (sbj, notification.subject)
        self.assertTrue(sbj in notification.subject)
開發者ID:seacoastboy,項目名稱:rhodecode,代碼行數:28,代碼來源:test_changeset_comments.py

示例5: test_notification_counter

    def test_notification_counter(self):
        self._clean_notifications()
        self.assertEqual([], Notification.query().all())
        self.assertEqual([], UserNotification.query().all())

        NotificationModel().create(created_by=self.u1,
                            subject=u'title', body=u'hi there_delete',
                            recipients=[self.u3, self.u1])
        Session().commit()

        self.assertEqual(NotificationModel()
                         .get_unread_cnt_for_user(self.u1), 1)
        self.assertEqual(NotificationModel()
                         .get_unread_cnt_for_user(self.u2), 0)
        self.assertEqual(NotificationModel()
                         .get_unread_cnt_for_user(self.u3), 1)

        notification = NotificationModel().create(created_by=self.u1,
                                           subject=u'title', body=u'hi there3',
                                    recipients=[self.u3, self.u1, self.u2])
        Session().commit()

        self.assertEqual(NotificationModel()
                         .get_unread_cnt_for_user(self.u1), 2)
        self.assertEqual(NotificationModel()
                         .get_unread_cnt_for_user(self.u2), 1)
        self.assertEqual(NotificationModel()
                         .get_unread_cnt_for_user(self.u3), 2)
開發者ID:break123,項目名稱:rhodecode,代碼行數:28,代碼來源:test_notifications.py

示例6: test_create_with_mention

    def test_create_with_mention(self):
        self.log_user()

        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = u'@test_regular check CommentOnRevision'

        params = {'text':text}
        response = self.app.post(url(controller='changeset', action='comment',
                                     repo_name=HG_REPO, revision=rev),
                                     params=params)
        # Test response...
        self.assertEqual(response.status, '302 Found')
        response.follow()

        response = self.app.get(url(controller='changeset', action='index',
                                repo_name=HG_REPO, revision=rev))
        # test DB
        self.assertEqual(ChangesetComment.query().count(), 1)
        response.mustcontain('''<div class="comments-number">%s '''
                             '''comment (0 inline)</div>''' % 1)

        self.assertEqual(Notification.query().count(), 2)
        users = [x.user.username for x in UserNotification.query().all()]

        # test_regular get's notification by @mention
        self.assertEqual(sorted(users), [u'test_admin', u'test_regular'])
開發者ID:adamscieszko,項目名稱:rhodecode,代碼行數:26,代碼來源:test_changeset_comments.py

示例7: setUp

    def setUp(self):
        for x in ChangesetComment.query().all():
            Session().delete(x)
        Session().commit()

        for x in Notification.query().all():
            Session().delete(x)
        Session().commit()
開發者ID:adamscieszko,項目名稱:rhodecode,代碼行數:8,代碼來源:test_changeset_comments.py

示例8: test_delete_association

    def test_delete_association(self):

        self.assertEqual([], Notification.query().all())
        self.assertEqual([], UserNotification.query().all())

        notification = NotificationModel().create(created_by=self.u1,
                                           subject=u'title', body=u'hi there3',
                                    recipients=[self.u3, self.u1, self.u2])
        Session().commit()

        unotification = UserNotification.query()\
                            .filter(UserNotification.notification ==
                                    notification)\
                            .filter(UserNotification.user_id == self.u3)\
                            .scalar()

        self.assertEqual(unotification.user_id, self.u3)

        NotificationModel().delete(self.u3,
                                   notification.notification_id)
        Session().commit()

        u3notification = UserNotification.query()\
                            .filter(UserNotification.notification ==
                                    notification)\
                            .filter(UserNotification.user_id == self.u3)\
                            .scalar()

        self.assertEqual(u3notification, None)

        # notification object is still there
        self.assertEqual(Notification.query().all(), [notification])

        #u1 and u2 still have assignments
        u1notification = UserNotification.query()\
                            .filter(UserNotification.notification ==
                                    notification)\
                            .filter(UserNotification.user_id == self.u1)\
                            .scalar()
        self.assertNotEqual(u1notification, None)
        u2notification = UserNotification.query()\
                            .filter(UserNotification.notification ==
                                    notification)\
                            .filter(UserNotification.user_id == self.u2)\
                            .scalar()
        self.assertNotEqual(u2notification, None)
開發者ID:break123,項目名稱:rhodecode,代碼行數:46,代碼來源:test_notifications.py

示例9: tearDown

    def tearDown(self):
        for x in ChangesetComment.query().all():
            self.Session.delete(x)
        self.Session.commit()

        for x in Notification.query().all():
            self.Session.delete(x)
        self.Session.commit()
開發者ID:seacoastboy,項目名稱:rhodecode,代碼行數:8,代碼來源:test_changeset_comments.py

示例10: __get_notification

 def __get_notification(self, notification):
     if isinstance(notification, Notification):
         return notification
     elif isinstance(notification, (int, long)):
         return Notification.get(notification)
     else:
         if notification:
             raise Exception('notification must be int, long or Instance'
                             ' of Notification got %s' % type(notification))
開發者ID:elfixit,項目名稱:rhodecode,代碼行數:9,代碼來源:notification.py

示例11: test_delete_notifications

    def test_delete_notifications(self):
        self.assertEqual([], Notification.query().all())
        self.assertEqual([], UserNotification.query().all())

        notification = NotificationModel().create(created_by=self.u1,
                                           subject=u'title', body=u'hi there3',
                                    recipients=[self.u3, self.u1, self.u2])
        Session().commit()
        notifications = Notification.query().all()
        self.assertTrue(notification in notifications)

        Notification.delete(notification.notification_id)
        Session().commit()

        notifications = Notification.query().all()
        self.assertFalse(notification in notifications)

        un = UserNotification.query().filter(UserNotification.notification
                                             == notification).all()
        self.assertEqual(un, [])
開發者ID:break123,項目名稱:rhodecode,代碼行數:20,代碼來源:test_notifications.py

示例12: test_create_inline

    def test_create_inline(self):
        self.log_user()
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = u'CommentOnRevision'
        f_path = 'vcs/web/simplevcs/views/repository.py'
        line = 'n1'

        params = {'text': text, 'f_path': f_path, 'line': line}
        response = self.app.post(url(controller='changeset', action='comment',
                                     repo_name=HG_REPO, revision=rev),
                                     params=params)
        # Test response...
        self.assertEqual(response.status, '302 Found')
        response.follow()

        response = self.app.get(url(controller='changeset', action='index',
                                repo_name=HG_REPO, revision=rev))
        #test DB
        self.assertEqual(ChangesetComment.query().count(), 1)
        response.mustcontain(
            '''<div class="comments-number">0 comments'''
            ''' (%s inline)</div>''' % 1
        )
        response.mustcontain(
            '''<div style="display:none" class="inline-comment-placeholder" '''
            '''path="vcs/web/simplevcs/views/repository.py" '''
            '''target_id="vcswebsimplevcsviewsrepositorypy">'''
        )

        self.assertEqual(Notification.query().count(), 1)
        self.assertEqual(ChangesetComment.query().count(), 1)

        notification = Notification.query().all()[0]
        ID = ChangesetComment.query().first().comment_id
        self.assertEqual(notification.type_,
                         Notification.TYPE_CHANGESET_COMMENT)
        sbj = (u'/vcs_test_hg/changeset/'
               '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % ID)
        print "%s vs %s" % (sbj, notification.subject)
        self.assertTrue(sbj in notification.subject)
開發者ID:adamscieszko,項目名稱:rhodecode,代碼行數:40,代碼來源:test_changeset_comments.py

示例13: test_user_notifications

    def test_user_notifications(self):
        self.assertEqual([], Notification.query().all())
        self.assertEqual([], UserNotification.query().all())

        notification1 = NotificationModel().create(created_by=self.u1,
                                            subject=u'subj', body=u'hi there1',
                                            recipients=[self.u3])
        Session().commit()
        notification2 = NotificationModel().create(created_by=self.u1,
                                            subject=u'subj', body=u'hi there2',
                                            recipients=[self.u3])
        Session().commit()
        u3 = Session().query(User).get(self.u3)

        self.assertEqual(sorted([x.notification for x in u3.notifications]),
                         sorted([notification2, notification1]))
開發者ID:break123,項目名稱:rhodecode,代碼行數:16,代碼來源:test_notifications.py

示例14: delete

    def delete(self, notification_id):
        """DELETE /_admin/notifications/id: Delete an existing item"""
        # Forms posted to this method should contain a hidden field:
        #    <input type="hidden" name="_method" value="DELETE" />
        # Or using helpers:
        #    h.form(url('notification', notification_id=ID),
        #           method='delete')
        # url('notification', notification_id=ID)

        try:
            no = Notification.get(notification_id)
            owner = lambda: (no.notifications_to_users.user.user_id == c.rhodecode_user.user_id)
            if h.HasPermissionAny("hg.admin", "repository.admin")() or owner:
                NotificationModel().delete(c.rhodecode_user.user_id, no)
                Session.commit()
                return "ok"
        except Exception:
            Session.rollback()
            log.error(traceback.format_exc())
        return "fail"
開發者ID:seacoastboy,項目名稱:rhodecode,代碼行數:20,代碼來源:notifications.py

示例15: update

 def update(self, notification_id):
     """PUT /_admin/notifications/id: Update an existing item"""
     # Forms posted to this method should contain a hidden field:
     #    <input type="hidden" name="_method" value="PUT" />
     # Or using helpers:
     #    h.form(url('notification', notification_id=ID),
     #           method='put')
     # url('notification', notification_id=ID)
     try:
         no = Notification.get(notification_id)
         owner = all(un.user.user_id == c.rhodecode_user.user_id
                     for un in no.notifications_to_users)
         if h.HasPermissionAny('hg.admin')() or owner:
                 NotificationModel().mark_read(c.rhodecode_user.user_id, no)
                 Session().commit()
                 return 'ok'
     except Exception:
         Session().rollback()
         log.error(traceback.format_exc())
     return 'fail'
開發者ID:adamscieszko,項目名稱:rhodecode,代碼行數:20,代碼來源:notifications.py


注:本文中的rhodecode.model.db.Notification類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。