当前位置: 首页>>代码示例>>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;未经允许,请勿转载。