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))
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">''' ''' 1 comment (0 inline, 1 general)''' ) 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)
def test_create(self): self.log_user() rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc' text = u'CommentOnRevision' params = {'text': text, '_authentication_token': self.authentication_token()} response = self.app.post(url(controller='changeset', action='comment', repo_name=HG_REPO, revision=rev), params=params, extra_environ={'HTTP_X_PARTIAL_XHR': '1'}) # Test response... self.assertEqual(response.status, '200 OK') 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">''' ''' 1 comment (0 inline, 1 general)''' ) 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'/%s/changeset/' '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % (HG_REPO, ID)) print "%s vs %s" % (sbj, notification.subject) self.assertTrue(sbj in notification.subject)
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 remove_all_notifications(): Notification.query().delete() # Because query().delete() does not (by default) trigger cascades. # http://docs.sqlalchemy.org/en/rel_0_7/orm/collections.html#passive-deletes UserNotification.query().delete() Session().commit()
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, '_authentication_token': self.authentication_token() } response = self.app.post(url(controller='changeset', action='comment', repo_name=HG_REPO, revision=rev), params=params, extra_environ={'HTTP_X_PARTIAL_XHR': '1'}) # Test response... assert response.status == '200 OK' response = self.app.get( url(controller='changeset', action='index', repo_name=HG_REPO, revision=rev)) #test DB assert ChangesetComment.query().count() == 1 response.mustcontain('''<div class="comments-number">''' ''' 1 comment (1 inline, 0 general)''') response.mustcontain( '''<div class="comments-list-chunk" ''' '''data-f_path="vcs/web/simplevcs/views/repository.py" ''' '''data-line_no="n1" data-target-id="vcswebsimplevcsviewsrepositorypy_n1">''' ) assert Notification.query().count() == 1 assert ChangesetComment.query().count() == 1 notification = Notification.query().all()[0] ID = ChangesetComment.query().first().comment_id assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT sbj = (u'/%s/changeset/' '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % (HG_REPO, ID)) print "%s vs %s" % (sbj, notification.subject) assert sbj in notification.subject
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)
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">''' ''' 1 comment (0 inline, 1 general)''' ) self.assertEqual(Notification.query().count(), 2) users = [x.user.username for x in UserNotification.query().all()] # test_regular gets notification by @mention self.assertEqual(sorted(users), [u'test_admin', u'test_regular'])
def setup_method(self, method): Session.remove() u1 = UserModel().create_or_update(username=u'u1', password=u'qweqwe', email=u'*****@*****.**', firstname=u'u1', lastname=u'u1') Session().commit() self.u1 = u1.user_id u2 = UserModel().create_or_update(username=u'u2', password=u'qweqwe', email=u'*****@*****.**', firstname=u'u2', lastname=u'u3') Session().commit() self.u2 = u2.user_id u3 = UserModel().create_or_update(username=u'u3', password=u'qweqwe', email=u'*****@*****.**', firstname=u'u3', lastname=u'u3') Session().commit() self.u3 = u3.user_id self.remove_all_notifications() assert [] == Notification.query().all() assert [] == UserNotification.query().all()
def test_create_with_mention(self): self.log_user() rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc' text = u'@test_regular check CommentOnRevision' params = {'text': text, '_authentication_token': self.authentication_token()} 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">''' ''' 1 comment (0 inline, 1 general)''' ) self.assertEqual(Notification.query().count(), 2) users = [x.user.username for x in UserNotification.query().all()] # test_regular gets notification by @mention self.assertEqual(sorted(users), [u'test_admin', u'test_regular'])
def test_create_notification(self): with test_context(self.app): usrs = [self.u1, self.u2] def send_email(recipients, subject, body='', html_body='', headers=None, author=None): assert recipients == ['*****@*****.**'] assert subject == 'Test Message' assert body == u"hi there" assert '>hi there<' in html_body assert author.username == 'u1' with mock.patch.object(kallithea.lib.celerylib.tasks, 'send_email', send_email): 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_create_with_mention(self): self.log_user() rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc' text = u'@%s check CommentOnRevision' % TEST_USER_REGULAR_LOGIN params = {'text': text, '_authentication_token': self.authentication_token()} response = self.app.post(url(controller='changeset', action='comment', repo_name=HG_REPO, revision=rev), params=params, extra_environ={'HTTP_X_PARTIAL_XHR': '1'}) # Test response... self.assertEqual(response.status, '200 OK') 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">''' ''' 1 comment (0 inline, 1 general)''' ) self.assertEqual(Notification.query().count(), 2) users = [x.user.username for x in UserNotification.query().all()] # test_regular gets notification by @mention self.assertEqual(sorted(users), [TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN])
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)
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)
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()
def test_delete_notifications(self): 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, [])
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)
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 not notification in notifications un = UserNotification.query().filter(UserNotification.notification == notification).all() assert un == []
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">''' ''' 1 comment (1 inline, 0 general)''' ) 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)
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, '_authentication_token': self.authentication_token()} 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">''' ''' 1 comment (1 inline, 0 general)''' ) 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)
def test_create(self): self.log_user() rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc' text = u'CommentOnRevision' params = { 'text': text, '_authentication_token': self.authentication_token() } response = self.app.post(url(controller='changeset', action='comment', repo_name=HG_REPO, revision=rev), params=params, extra_environ={'HTTP_X_PARTIAL_XHR': '1'}) # Test response... assert response.status == '200 OK' response = self.app.get( url(controller='changeset', action='index', repo_name=HG_REPO, revision=rev)) # test DB assert ChangesetComment.query().count() == 1 response.mustcontain('''<div class="comments-number">''' ''' 1 comment (0 inline, 1 general)''') assert Notification.query().count() == 1 assert ChangesetComment.query().count() == 1 notification = Notification.query().all()[0] ID = ChangesetComment.query().first().comment_id assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT sbj = (u'/%s/changeset/' '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % (HG_REPO, ID)) print "%s vs %s" % (sbj, notification.subject) assert sbj in notification.subject
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, [])
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, '_authentication_token': self.authentication_token()} response = self.app.post(url(controller='changeset', action='comment', repo_name=HG_REPO, revision=rev), params=params, extra_environ={'HTTP_X_PARTIAL_XHR': '1'}) # Test response... self.assertEqual(response.status, '200 OK') 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">''' ''' 1 comment (1 inline, 0 general)''' ) response.mustcontain( '''<div class="comments-list-chunk" ''' '''data-f_path="vcs/web/simplevcs/views/repository.py" ''' '''data-line_no="n1" data-target-id="vcswebsimplevcsviewsrepositorypy_n1">''' ) 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'/%s/changeset/' '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % (HG_REPO, ID)) print "%s vs %s" % (sbj, notification.subject) self.assertTrue(sbj in notification.subject)
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]))
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_create_with_mention(self): self.log_user() rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc' text = u'@%s check CommentOnRevision' % TEST_USER_REGULAR_LOGIN params = { 'text': text, '_authentication_token': self.authentication_token() } response = self.app.post(url(controller='changeset', action='comment', repo_name=HG_REPO, revision=rev), params=params, extra_environ={'HTTP_X_PARTIAL_XHR': '1'}) # Test response... assert response.status == '200 OK' response = self.app.get( url(controller='changeset', action='index', repo_name=HG_REPO, revision=rev)) # test DB assert ChangesetComment.query().count() == 1 response.mustcontain('''<div class="comments-number">''' ''' 1 comment (0 inline, 1 general)''') 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 setUp(self): remove_all_notifications() self.assertEqual([], Notification.query().all()) self.assertEqual([], UserNotification.query().all())
def setUp(self): remove_all_notifications() self.assertEqual(Notification.query().all(), [])
def tearDown(self): for n in Notification.query().all(): Session().delete(n) Session().commit() self.assertEqual(Notification.query().all(), [])
def _clean_notifications(self): for n in Notification.query().all(): Session().delete(n) Session().commit() self.assertEqual(Notification.query().all(), [])
def tearDown(self): for n in Notification.query().all(): inst = Notification.get(n.notification_id) Session().delete(inst) Session().commit()
def setup_method(self, method): self.remove_all_notifications() assert Notification.query().all() == []