def test_gets_by_target_and_ref(self): # commit self.clear_comments(CommitLineComment, TARGET_ID, FROM_SHA) c1 = CommitLineComment.add(TARGET_ID, FROM_SHA, TO_SHA, OLD_PATH, NEW_PATH, FROM_OID, TO_OID, 20, 30, AUTHOR, CONTENT1) c2 = CommitLineComment.add(TARGET_ID, FROM_SHA, TO_SHA, OLD_PATH, NEW_PATH, FROM_OID, TO_OID, 20, 30, AUTHOR, CONTENT1) c3 = CommitLineComment.add(TARGET_ID, FROM_SHA, TO_SHA, OLD_PATH, NEW_PATH, FROM_OID, TO_OID, 20, 30, AUTHOR, CONTENT1) cs = CommitLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA) assert len(cs) == 3 self.clear_comments(PullLineComment, TARGET_ID, FROM_SHA) # pull PullLineComment.add(TARGET_ID, FROM_SHA, TO_SHA, OLD_PATH, NEW_PATH, FROM_OID, TO_OID, 20, 30, AUTHOR, CONTENT1) PullLineComment.add(TARGET_ID, FROM_SHA, TO_SHA, OLD_PATH, NEW_PATH, FROM_OID, TO_OID, 20, 30, AUTHOR, CONTENT1) cs = PullLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA) assert len(cs) == 2
def create(self, request): user = request.user if not user: return dict(r=1) project = CodeDoubanProject.get_by_name(self.proj_name) project_id = project.id from_sha = request.get_form_var('from_sha') assert from_sha, "comment from_sha cannot be empty" old_path = request.get_form_var('old_path') assert old_path, "comment old_path cannot be empty" new_path = request.get_form_var('new_path') assert new_path, "comment new path cannot be empty" # position = request.get_form_var('position') # assert position, "comment position cannot be empty" from_oid = request.get_form_var('from_oid') assert from_oid, "comment from_oid cannot be empty" to_oid = request.get_form_var('to_oid') assert to_oid, "comment to_oid cannot be empty" old = request.get_form_var('old_no') old = int(old) if old.isdigit() else LINECOMMENT_INDEX_EMPTY new = request.get_form_var('new_no') new = int(new) if new.isdigit() else LINECOMMENT_INDEX_EMPTY content = request.get_form_var('content', '') # FIXME: commit_author is None commit_author = request.get_form_var('commit_author') if not content.strip(): return {'error': 'Content is empty!'} comment = CommitLineComment.add(project_id, from_sha, '', old_path, new_path, from_oid, to_oid, old, new, user.name, content) dispatch('comment', data={ 'comment': comment, 'commit_author': commit_author, 'is_line_comment': True, }) # TODO: 目前只是回写一个链接,可以多传点信息支持直接回写到pr linecomment # for commit linecomments rewrite to pr dispatch('comment_actions', data={ 'type': 'commit_linecomment', 'comment': comment, 'commit_author': commit_author, }) comment_uid = comment.uid return dict(r=0, html=st('/commit_linecomment.html', **locals()))
def test_update_comment(self): # commit c1 = CommitLineComment.add(TARGET_ID, FROM_SHA, TO_SHA, OLD_PATH, NEW_PATH, FROM_OID, TO_OID, 20, 30, AUTHOR, CONTENT1) assert c1.content == CONTENT1 c1.update(CONTENT2) c1 = CommitLineComment.get(c1.id) assert c1.content == CONTENT2 # pull c2 = PullLineComment.add(TARGET_ID, FROM_SHA, TO_SHA, OLD_PATH, NEW_PATH, FROM_OID, TO_OID, 20, 30, AUTHOR, CONTENT2) assert c2.content == CONTENT2 c2.update(CONTENT_ZH) c2 = CommitLineComment.get(c2.id) assert c2.content == CONTENT_ZH
def test_delete_comment(self): # commit c1 = CommitLineComment.add(TARGET_ID, FROM_SHA, TO_SHA, OLD_PATH, NEW_PATH, FROM_OID, TO_OID, 20, 30, AUTHOR, CONTENT1) cs = CommitLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA) assert len(cs) == 1 c1.delete() cs = CommitLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA) assert len(cs) == 0 # pull c2 = PullLineComment.add(TARGET_ID, FROM_SHA, TO_SHA, OLD_PATH, NEW_PATH, FROM_OID, TO_OID, 20, 30, AUTHOR, CONTENT1) cs = PullLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA) assert len(cs) == 1 c2.delete() cs = PullLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA) assert len(cs) == 0
def test_add_comment(self): # commit c1 = CommitLineComment.add(TARGET_ID, FROM_SHA, TO_SHA, OLD_PATH, NEW_PATH, FROM_OID, TO_OID, 20, 30, AUTHOR, CONTENT1) assert c1.target_id == TARGET_ID assert c1.target_type == LINECOMMENT_TYPE_COMMIT assert c1.from_sha == FROM_SHA assert c1.to_sha == TO_SHA assert c1.old_path == OLD_PATH assert c1.new_path == NEW_PATH assert c1.from_oid == FROM_OID assert c1.to_oid == TO_OID assert c1.old_linenum == 20 assert c1.new_linenum == 30 assert c1.linenum == (20, 30) assert c1.author == AUTHOR assert c1.content == CONTENT1 assert c1.position is None assert c1.paths # pull c2 = PullLineComment.add(TARGET_ID, FROM_SHA, TO_SHA, OLD_PATH, NEW_PATH, FROM_OID, TO_OID, 20, 30, AUTHOR, CONTENT2) assert c2.target_id == TARGET_ID assert c2.target_type == LINECOMMENT_TYPE_PULL assert c2.from_sha == FROM_SHA assert c2.to_sha == TO_SHA assert c2.old_path == OLD_PATH assert c2.new_path == NEW_PATH assert c2.from_oid == FROM_OID assert c2.to_oid == TO_OID assert c2.old_linenum == 20 assert c2.new_linenum == 30 assert c2.linenum == (20, 30) assert c2.author == AUTHOR assert c2.content == CONTENT2 assert c2.position is None assert c2.paths
def test_delete_comment(self): # commit self.clear_comments(CommitLineComment, TARGET_ID, FROM_SHA) c1 = CommitLineComment.add(TARGET_ID, FROM_SHA, TO_SHA, OLD_PATH, NEW_PATH, FROM_OID, TO_OID, 20, 30, AUTHOR, CONTENT1) cs = CommitLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA) assert len(cs) == 1 c1.delete() cs = CommitLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA) assert len(cs) == 0 # pull self.clear_comments(PullLineComment, TARGET_ID, FROM_SHA) c2 = PullLineComment.add(TARGET_ID, FROM_SHA, TO_SHA, OLD_PATH, NEW_PATH, FROM_OID, TO_OID, 20, 30, AUTHOR, CONTENT1) cs = PullLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA) assert len(cs) == 1 c2.delete() cs = PullLineComment.gets_by_target_and_ref(TARGET_ID, FROM_SHA) assert len(cs) == 0