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)
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)
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)
def test_delete(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) comments = ChangesetComment.query().all() self.assertEqual(len(comments), 1) comment_id = comments[0].comment_id self.app.delete( url(controller='changeset', action='delete_comment', repo_name=HG_REPO, comment_id=comment_id)) comments = ChangesetComment.query().all() self.assertEqual(len(comments), 0) response = self.app.get( url(controller='changeset', action='index', repo_name=HG_REPO, revision=rev)) response.mustcontain('''<div class="comments-number">0 comments''' ''' (0 inline)</div>''')
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)
def test_create_with_mention(self, backend): self.log_user() commit_id = backend.repo.get_commit('300').raw_id text = u'@test_regular check CommentOnCommit' params = {'text': text, 'csrf_token': self.csrf_token} self.app.post(url(controller='changeset', action='comment', repo_name=backend.repo_name, revision=commit_id), params=params) response = self.app.get( url(controller='changeset', action='index', repo_name=backend.repo_name, revision=commit_id)) # test DB assert ChangesetComment.query().count() == 1 assert_comment_links(response, ChangesetComment.query().count(), 0) notification = Notification.query().one() assert len(notification.recipients) == 2 users = [x.username for x in notification.recipients] # test_regular gets notification by @mention assert sorted(users) == [u'test_admin', u'test_regular']
def test_delete(self, backend): self.log_user() commit_id = backend.repo.get_commit('300').raw_id text = u'CommentOnCommit' params = {'text': text, 'csrf_token': self.csrf_token} self.app.post(url(controller='changeset', action='comment', repo_name=backend.repo_name, revision=commit_id), params=params) comments = ChangesetComment.query().all() assert len(comments) == 1 comment_id = comments[0].comment_id self.app.post(url(controller='changeset', action='delete_comment', repo_name=backend.repo_name, comment_id=comment_id), params={ '_method': 'delete', 'csrf_token': self.csrf_token }) comments = ChangesetComment.query().all() assert len(comments) == 0 response = self.app.get( url(controller='changeset', action='index', repo_name=backend.repo_name, revision=commit_id)) assert_comment_links(response, 0, 0)
def test_delete(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) comments = ChangesetComment.query().all() self.assertEqual(len(comments), 1) comment_id = comments[0].comment_id self.app.delete(url(controller='changeset', action='delete_comment', repo_name=HG_REPO, comment_id=comment_id)) comments = ChangesetComment.query().all() self.assertEqual(len(comments), 0) response = self.app.get(url(controller='changeset', action='index', repo_name=HG_REPO, revision=rev)) response.mustcontain('''<div class="comments-number">0 comments''' ''' (0 inline)</div>''')
def test_create_inline(self, backend): self.log_user() commit_id = backend.repo.get_commit('300').raw_id text = u'CommentOnCommit' f_path = 'vcs/web/simplevcs/views/repository.py' line = 'n1' params = { 'text': text, 'f_path': f_path, 'line': line, 'csrf_token': self.csrf_token } self.app.post(url(controller='changeset', action='comment', repo_name=backend.repo_name, revision=commit_id), params=params) response = self.app.get( url(controller='changeset', action='index', repo_name=backend.repo_name, revision=commit_id)) # test DB assert ChangesetComment.query().count() == 1 assert_comment_links(response, 0, ChangesetComment.query().count()) response.mustcontain( '''class="inline-comment-placeholder" ''' '''path="vcs/web/simplevcs/views/repository.py" ''' '''target_id="vcswebsimplevcsviewsrepositorypy"''') assert Notification.query().count() == 1 assert ChangesetComment.query().count() == 1 notification = Notification.query().all()[0] comment = ChangesetComment.query().first() assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT assert comment.revision == commit_id sbj = 'commented on commit of {0}'.format(backend.repo_name) assert sbj in notification.subject lnk = (u'/{0}/changeset/{1}#comment-{2}'.format( backend.repo_name, commit_id, comment.comment_id)) assert lnk in notification.body assert 'on line n1' in notification.body
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'])
def get_comments(self, repo_id, revision=None, pull_request=None): """ Get's main comments based on revision or pull_request_id :param repo_id: :type repo_id: :param revision: :type revision: :param pull_request: :type pull_request: """ q = ChangesetComment.query()\ .filter(ChangesetComment.repo_id == repo_id)\ .filter(ChangesetComment.line_no == None)\ .filter(ChangesetComment.f_path == None) if revision: q = q.filter(ChangesetComment.revision == revision) elif pull_request: pull_request = self.__get_pull_request(pull_request) q = q.filter(ChangesetComment.pull_request == pull_request) else: raise Exception('Please specify revision or pull_request') q = q.order_by(ChangesetComment.created_on) return q.all()
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'])
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()
def cleanup(self): for x in ChangesetComment.query().all(): Session().delete(x) Session().commit() for x in Notification.query().all(): Session().delete(x) Session().commit()
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 setUp(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()
def prepare(self, request, pylonsapp): for x in ChangesetComment.query().all(): Session().delete(x) Session().commit() for x in Notification.query().all(): Session().delete(x) Session().commit() request.addfinalizer(self.cleanup)
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)
def get_all_comments(self, repo_id, revision=None, pull_request=None): q = ChangesetComment.query()\ .filter(ChangesetComment.repo_id == repo_id) if revision: q = q.filter(ChangesetComment.revision == revision) elif pull_request: pull_request = self.__get_pull_request(pull_request) q = q.filter(ChangesetComment.pull_request == pull_request) else: raise Exception('Please specify commit or pull_request') q = q.order_by(ChangesetComment.created_on) return q.all()
def test_delete(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 ) comments = ChangesetComment.query().all() self.assertEqual(len(comments), 1) comment_id = comments[0].comment_id self.app.delete(url(controller="changeset", action="delete_comment", repo_name=HG_REPO, comment_id=comment_id)) comments = ChangesetComment.query().all() self.assertEqual(len(comments), 0) response = self.app.get(url(controller="changeset", action="index", repo_name=HG_REPO, revision=rev)) self.assertTrue("""<div class="comments-number">0 comment(s)""" """ (0 inline)</div>""" in response.body)
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)
def test_create(self, backend): self.log_user() commit_id = backend.repo.get_commit('300').raw_id text = u'CommentOnCommit' params = {'text': text, 'csrf_token': self.csrf_token} self.app.post(url(controller='changeset', action='comment', repo_name=backend.repo_name, revision=commit_id), params=params) response = self.app.get( url(controller='changeset', action='index', repo_name=backend.repo_name, revision=commit_id)) # test DB assert ChangesetComment.query().count() == 1 assert_comment_links(response, ChangesetComment.query().count(), 0) assert Notification.query().count() == 1 assert ChangesetComment.query().count() == 1 notification = Notification.query().all()[0] comment_id = ChangesetComment.query().first().comment_id assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT sbj = 'commented on commit of {0}'.format(backend.repo_name) assert sbj in notification.subject lnk = (u'/{0}/changeset/{1}#comment-{2}'.format( backend.repo_name, commit_id, comment_id)) assert lnk in notification.body
def get_comments(self, repo_id, revision=None, pull_request=None): """ Get's main comments based on revision or pull_request_id :param repo_id: :param revision: :param pull_request: """ q = ChangesetComment.query()\ .filter(ChangesetComment.repo_id == repo_id)\ .filter(ChangesetComment.line_no == None)\ .filter(ChangesetComment.f_path == None) if revision: q = q.filter(ChangesetComment.revision == revision) elif pull_request: pull_request = self.__get_pull_request(pull_request) q = q.filter(ChangesetComment.pull_request == pull_request) else: raise Exception('Please specify revision or pull_request') q = q.order_by(ChangesetComment.created_on) return q.all()
def _link_comments_to_version(self, pull_request_version): """ Link all unlinked comments of this pull request to the given version. :param pull_request_version: The `PullRequestVersion` to which the comments shall be linked. """ pull_request = pull_request_version.pull_request comments = ChangesetComment.query().filter( # TODO: johbo: Should we query for the repo at all here? # Pending decision on how comments of PRs are to be related # to either the source repo, the target repo or no repo at all. ChangesetComment.repo_id == pull_request.target_repo.repo_id, ChangesetComment.pull_request == pull_request, ChangesetComment.pull_request_version == None) # TODO: johbo: Find out why this breaks if it is done in a bulk # operation. for comment in comments: comment.pull_request_version_id = ( pull_request_version.pull_request_version_id) Session().add(comment)
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) self.assertTrue("""<div class="comments-number">%s """ """comment(s) (0 inline)</div>""" % 1 in response.body) 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"])
def get_comments(self, repo_id, revision): return ChangesetComment.query()\ .filter(ChangesetComment.repo_id == repo_id)\ .filter(ChangesetComment.revision == revision)\ .filter(ChangesetComment.line_no == None)\ .filter(ChangesetComment.f_path == None).all()