Changeset - a33d1337db05
[Not reviewed]
default
1 4 0
Thomas De Schampheleire - 7 years ago 2018-12-05 07:40:00
thomas.de_schampheleire@nokia.com
tests: remove tests of UI notifications

This commit is part of the removal of the UI notification feature from
Kallithea, which is not deemed useful in its current form. Only email
notifications are preserved.
5 files changed with 4 insertions and 378 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/base.py
Show inline comments
 
@@ -24,7 +24,7 @@ from tg import config
 
from webtest import TestApp
 

	
 
from kallithea import model
 
from kallithea.model.db import Notification, User, UserNotification
 
from kallithea.model.db import User
 
from kallithea.model.meta import Session
 
from kallithea.lib.utils2 import safe_str
 

	
 
@@ -149,15 +149,6 @@ class TestController(object):
 
        self.app = TestApp(testapp)
 
        return self.app
 

	
 
    def remove_all_notifications(self):
 
        # query().delete() does not (by default) trigger cascades
 
        # ( http://docs.sqlalchemy.org/en/rel_0_7/orm/collections.html#passive-deletes )
 
        # so delete the UserNotification first to ensure referential integrity.
 
        UserNotification.query().delete()
 

	
 
        Notification.query().delete()
 
        Session().commit()
 

	
 
    def log_user(self, username=TEST_USER_ADMIN_LOGIN,
 
                 password=TEST_USER_ADMIN_PASS):
 
        self._logged_username = username
kallithea/tests/functional/test_admin_notifications.py
Show inline comments
 
deleted file
kallithea/tests/functional/test_changeset_pullrequests_comments.py
Show inline comments
 
@@ -2,8 +2,7 @@ import re
 

	
 
from kallithea.tests.base import *
 
from kallithea.model.changeset_status import ChangesetStatusModel
 
from kallithea.model.db import ChangesetComment, Notification, \
 
    UserNotification
 
from kallithea.model.db import ChangesetComment
 
from kallithea.model.meta import Session
 

	
 

	
 
@@ -14,8 +13,6 @@ class TestChangeSetCommentsController(Te
 
            Session().delete(x)
 
        Session().commit()
 

	
 
        self.remove_all_notifications()
 

	
 
    def test_create(self):
 
        self.log_user()
 
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
 
@@ -38,17 +35,6 @@ class TestChangeSetCommentsController(Te
 

	
 
        # test DB
 
        assert ChangesetComment.query().count() == 1
 
        assert Notification.query().count() == 1
 

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

	
 
        comment_id = ChangesetComment.query().first().comment_id
 
        assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT
 
        sbj = (u'/%s/changeset/'
 
               '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s'
 
               % (HG_REPO, comment_id))
 
        print "%s vs %s" % (sbj, notification.subject)
 
        assert sbj in notification.subject
 

	
 
    def test_create_inline(self):
 
        self.log_user()
 
@@ -79,16 +65,6 @@ class TestChangeSetCommentsController(Te
 

	
 
        # test DB
 
        assert ChangesetComment.query().count() == 1
 
        assert Notification.query().count() == 1
 

	
 
        notification = Notification.query().all()[0]
 
        comment_id = ChangesetComment.query().first().comment_id
 
        assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT
 
        sbj = (u'/%s/changeset/'
 
               '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s'
 
               % (HG_REPO, comment_id))
 
        print "%s vs %s" % (sbj, notification.subject)
 
        assert sbj in notification.subject
 

	
 
    def test_create_with_mention(self):
 
        self.log_user()
 
@@ -113,11 +89,6 @@ class TestChangeSetCommentsController(Te
 

	
 
        # test DB
 
        assert ChangesetComment.query().count() == 1
 
        assert Notification.query().count() == 2
 
        users = [x.user.username for x in UserNotification.query().all()]
 

	
 
        # test_regular gets notification by @mention
 
        assert sorted(users) == [TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN]
 

	
 
    def test_create_status_change(self):
 
        self.log_user()
 
@@ -142,17 +113,6 @@ class TestChangeSetCommentsController(Te
 

	
 
        # test DB
 
        assert ChangesetComment.query().count() == 1
 
        assert Notification.query().count() == 1
 

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

	
 
        comment_id = ChangesetComment.query().first().comment_id
 
        assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT
 
        sbj = (u'/%s/changeset/'
 
               '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s'
 
               % (HG_REPO, comment_id))
 
        print "%s vs %s" % (sbj, notification.subject)
 
        assert sbj in notification.subject
 

	
 
        # check status
 
        status = ChangesetStatusModel().get_status(repo=HG_REPO, revision=rev)
 
@@ -196,8 +156,6 @@ class TestPullrequestsCommentsController
 
            Session().delete(x)
 
        Session().commit()
 

	
 
        self.remove_all_notifications()
 

	
 
    def _create_pr(self):
 
        response = self.app.post(url(controller='pullrequests', action='create',
 
                                     repo_name=HG_REPO),
 
@@ -238,15 +196,6 @@ class TestPullrequestsCommentsController
 

	
 
        # test DB
 
        assert ChangesetComment.query().count() == 2
 
        assert Notification.query().count() == 1
 

	
 
        notification = Notification.query().all()[0]
 
        comment_id = ChangesetComment.query().order_by(ChangesetComment.comment_id.desc()).first().comment_id
 
        assert notification.type_ == Notification.TYPE_PULL_REQUEST_COMMENT
 
        sbj = (u'/%s/pull-request/%s/_/stable#comment-%s'
 
               % (HG_REPO, pr_id, comment_id))
 
        print "%s vs %s" % (sbj, notification.subject)
 
        assert sbj in notification.subject
 

	
 
    def test_create_inline(self):
 
        self.log_user()
 
@@ -277,15 +226,6 @@ class TestPullrequestsCommentsController
 

	
 
        # test DB
 
        assert ChangesetComment.query().count() == 2
 
        assert Notification.query().count() == 1
 

	
 
        notification = Notification.query().all()[0]
 
        comment_id = ChangesetComment.query().order_by(ChangesetComment.comment_id.desc()).first().comment_id
 
        assert notification.type_ == Notification.TYPE_PULL_REQUEST_COMMENT
 
        sbj = (u'/%s/pull-request/%s/_/stable#comment-%s'
 
               % (HG_REPO, pr_id, comment_id))
 
        print "%s vs %s" % (sbj, notification.subject)
 
        assert sbj in notification.subject
 

	
 
    def test_create_with_mention(self):
 
        self.log_user()
 
@@ -309,11 +249,6 @@ class TestPullrequestsCommentsController
 

	
 
        # test DB
 
        assert ChangesetComment.query().count() == 2
 
        assert Notification.query().count() == 2
 
        users = [x.user.username for x in UserNotification.query().all()]
 

	
 
        # test_regular gets notification by @mention
 
        assert sorted(users) == [TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN]
 

	
 
    def test_create_status_change(self):
 
        self.log_user()
 
@@ -341,15 +276,6 @@ class TestPullrequestsCommentsController
 

	
 
        # test DB
 
        assert ChangesetComment.query().count() == 2
 
        assert Notification.query().count() == 1
 

	
 
        notification = Notification.query().all()[0]
 
        comment_id = ChangesetComment.query().order_by(ChangesetComment.comment_id.desc()).first().comment_id
 
        assert notification.type_ == Notification.TYPE_PULL_REQUEST_COMMENT
 
        sbj = (u'/%s/pull-request/%s/_/stable#comment-%s'
 
               % (HG_REPO, pr_id, comment_id))
 
        print "%s vs %s" % (sbj, notification.subject)
 
        assert sbj in notification.subject
 

	
 
        # check status
 
        status = ChangesetStatusModel().get_status(repo=HG_REPO, pull_request=pr_id)
kallithea/tests/functional/test_login.py
Show inline comments
 
@@ -12,7 +12,7 @@ from kallithea.lib.auth import check_pas
 
from kallithea.lib import helpers as h
 
from kallithea.model.api_key import ApiKeyModel
 
from kallithea.model import validators
 
from kallithea.model.db import User, Notification
 
from kallithea.model.db import User
 
from kallithea.model.meta import Session
 
from kallithea.model.user import UserModel
 

	
 
@@ -22,9 +22,6 @@ fixture = Fixture()
 

	
 

	
 
class TestLoginController(TestController):
 
    def setup_method(self, method):
 
        self.remove_all_notifications()
 
        assert Notification.query().all() == []
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='login', action='index'))
kallithea/tests/models/test_notifications.py
Show inline comments
 
@@ -6,7 +6,7 @@ import routes.util
 

	
 
from kallithea.tests.base import *
 
from kallithea.lib import helpers as h
 
from kallithea.model.db import User, Notification, UserNotification
 
from kallithea.model.db import User, Notification
 
from kallithea.model.user import UserModel
 
from kallithea.model.meta import Session
 
from kallithea.model.notification import NotificationModel, EmailNotificationModel
 
@@ -42,10 +42,6 @@ class TestNotifications(TestController):
 
        Session().commit()
 
        self.u3 = u3.user_id
 

	
 
        self.remove_all_notifications()
 
        assert [] == Notification.query().all()
 
        assert [] == UserNotification.query().all()
 

	
 
    def test_create_notification(self):
 
        with test_context(self.app):
 
            usrs = [self.u1, self.u2]
 
@@ -60,118 +56,6 @@ class TestNotifications(TestController):
 
                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()
 
                assert len(notifications) == 1
 

	
 
                assert notifications[0].recipients == [u1, u2]
 
                assert notification.notification_id == notifications[0].notification_id
 

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

	
 
                assert len(unotification) == len(usrs)
 
                assert set([x.user_id for x in unotification]) == set(usrs)
 

	
 
    def test_user_notifications(self):
 
        with test_context(self.app):
 
            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)
 

	
 
            assert sorted([x.notification for x in u3.notifications]) == sorted([notification2, notification1])
 

	
 
    def test_delete_notifications(self):
 
        with test_context(self.app):
 
            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()
 
            assert notification in notifications
 

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

	
 
            notifications = Notification.query().all()
 
            assert notification not in notifications
 

	
 
            un = UserNotification.query().filter(UserNotification.notification
 
                                                 == notification).all()
 
            assert un == []
 

	
 
    def test_delete_association(self):
 
        with test_context(self.app):
 
            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()
 

	
 
            assert 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()
 

	
 
            assert u3notification == None
 

	
 
            # notification object is still there
 
            assert Notification.query().all() == [notification]
 

	
 
            # u1 and u2 still have assignments
 
            u1notification = UserNotification.query() \
 
                                .filter(UserNotification.notification ==
 
                                        notification) \
 
                                .filter(UserNotification.user_id == self.u1) \
 
                                .scalar()
 
            assert u1notification != None
 
            u2notification = UserNotification.query() \
 
                                .filter(UserNotification.notification ==
 
                                        notification) \
 
                                .filter(UserNotification.user_id == self.u2) \
 
                                .scalar()
 
            assert u2notification != None
 

	
 
    def test_notification_counter(self):
 
        with test_context(self.app):
 
            NotificationModel().create(created_by=self.u1,
 
                                subject=u'title', body=u'hi there_delete',
 
                                recipients=[self.u3, self.u1])
 
            Session().commit()
 

	
 
            assert NotificationModel().get_unread_cnt_for_user(self.u1) == 0
 
            assert NotificationModel().get_unread_cnt_for_user(self.u2) == 0
 
            assert 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()
 

	
 
            assert NotificationModel().get_unread_cnt_for_user(self.u1) == 0
 
            assert NotificationModel().get_unread_cnt_for_user(self.u2) == 1
 
            assert NotificationModel().get_unread_cnt_for_user(self.u3) == 2
 

	
 
    @mock.patch.object(h, 'canonical_url', (lambda arg, **kwargs: 'http://%s/?%s' % (arg, '&'.join('%s=%s' % (k, v) for (k, v) in sorted(kwargs.items())))))
 
    def test_dump_html_mails(self):
0 comments (0 inline, 0 general)