def test_gets_by_proj_and_ref(self): cid1 = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT) comment.add(T_PROJ_ID, T_REF_2, T_AUTHOR, T_CONTENT) cid2 = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT2) cmnts = comment.gets_by_proj_and_ref(T_PROJ_ID, T_REF, order='desc')[:2] assert cmnts == [cid2, cid1]
def test_gets_by_proj_and_ref(self): cid1 = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT) comment.add(T_PROJ_ID, T_REF_2, T_AUTHOR, T_CONTENT) cid2 = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT2) cmnts = comment.gets_by_proj_and_ref( T_PROJ_ID, T_REF, order='desc')[:2] assert cmnts == [cid2, cid1]
def test_delete_comment(self): cid = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT) assert comment.get(cid) ok = comment.delete(cid) assert ok assert not comment.get(cid) assert not comment.delete(cid), "Cannot delete twice same comment"
def test_gets_with_proj_with_order(self): all_cmnts = [comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT) for i in range(30)] assert len(all_cmnts) == 30 assert comment.gets_by_proj_and_ref( T_PROJ_ID, T_REF, order='desc')[:30] == list(reversed(all_cmnts)) assert comment.gets_by_proj_and_ref( T_PROJ_ID, T_REF, start=10, limit=5, order='desc') == all_cmnts[15:20][::-1] # noqa
def test_gets_with_order(self): all_cmnts = [ comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT) for i in range(30) ] assert len(all_cmnts) == 30 assert comment.gets_by_ref(T_REF, order='desc')[:30] == list( reversed(all_cmnts))
def test_gets_with_order(self): all_cmnts = [comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT) for i in range(30)] assert len(all_cmnts) == 30 assert comment.gets_by_ref( T_REF, order='desc') == list(reversed(all_cmnts)) assert comment.gets_by_ref(T_REF, start=10) == all_cmnts[10:] assert comment.gets_by_ref( T_REF, start=10, limit=5) == all_cmnts[10:15]
def test_gets_with_proj_with_order(self): all_cmnts = [ comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT) for i in range(30) ] assert len(all_cmnts) == 30 assert comment.gets_by_proj_and_ref(T_PROJ_ID, T_REF, order='desc')[:30] == list( reversed(all_cmnts)) assert comment.gets_by_proj_and_ref( T_PROJ_ID, T_REF, start=10, limit=5, order='desc') == all_cmnts[15:20][::-1] # noqa
def test_latest_comments(self): cid1 = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT) cid2 = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT2) latest = comment.latest() assert latest == [cid1, cid2]
def test_get_comment(self): cid = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT) com = comment.get(cid) assert com[1] == T_PROJ_ID assert com[2] == T_REF
def test_get_unexisting_comment(self): cid = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT) com = comment.get(cid + 1) assert com is None
def test_chinese_comment(self): T_CONTENT_ZH = u'test is 牛B' cid = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT_ZH) com = comment.get(cid) assert com[4] == T_CONTENT_ZH
def test_add_comment(self): cid1 = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT) assert cid1 cid2 = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT) assert cid2 assert cid1 != cid2
def _add(self, project_id=T_PROJ_ID, ref=T_REF, author=T_AUTHOR, content=T_CONTENT): return cC.get(comment.add(project_id, ref, author, content))
def test_gets_by_project_id(self): cid1 = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT) comment.add(T_PROJ_ID_2, T_REF, T_AUTHOR, T_CONTENT) cid2 = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT2) cmnts = comment.gets_by_project(T_PROJ_ID) assert cmnts == [cid1, cid2]
def test_modify_comment(self): cid = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT) comment.update(cid, {'content': 'new content'}) assert comment.get(cid)[4] == 'new content'
def test_chinese_comment(self): T_CONTENT_ZH = 'test is 牛B' cid = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT_ZH) com = comment.get(cid) assert com[4] == T_CONTENT_ZH
def test_gets_by_ref(self): cid1 = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT) comment.add(T_PROJ_ID, T_REF_2, T_AUTHOR, T_CONTENT) cid2 = comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT2) cmnts = comment.gets_by_ref(T_REF) assert cmnts == [cid1, cid2]
def test_gets_with_order(self): all_cmnts = [comment.add(T_PROJ_ID, T_REF, T_AUTHOR, T_CONTENT) for i in range(30)] assert len(all_cmnts) == 30 assert comment.gets_by_ref( T_REF, order='desc')[:30] == list(reversed(all_cmnts))