def test06DeleteComments(self): # make sure that the comment was created comm = create_comment(comment='Comment #1', claim_id=self.claimId, channel_id='1' * 40, channel_name='@Doge123', signature='a' * 128, signing_ts='123') comments = comment_list(self.claimId) match = [ x for x in comments['items'] if x['comment_id'] == comm['comment_id'] ] self.assertTrue(len(match) > 0) deleted = delete_comment(comm['comment_id']) self.assertTrue(deleted) # make sure that we can't find the comment here comments = comment_list(self.claimId) match = [ x for x in comments['items'] if x['comment_id'] == comm['comment_id'] ] self.assertFalse(match) self.assertRaises( ValueError, delete_comment, comment_id=comm['comment_id'], )
def testHiddenCommentLists(self): claim_id = 'a' * 40 comm1 = create_comment('Comment #1', claim_id, channel_id='1' * 40, channel_name='@Doge123', signature='a' * 128, signing_ts='123') comm2 = create_comment('Comment #2', claim_id, channel_id='1' * 40, channel_name='@Doge123', signature='b' * 128, signing_ts='123') comm3 = create_comment('Comment #3', claim_id, channel_id='1' * 40, channel_name='@Doge123', signature='c' * 128, signing_ts='123') comments = [comm1, comm2, comm3] listed_comments = comment_list(claim_id) self.assertEqual(len(comments), listed_comments['total_items']) self.assertFalse(listed_comments['has_hidden_comments']) set_hidden_flag([comm2['comment_id']]) hidden = comment_list(claim_id, exclude_mode='hidden') self.assertTrue(hidden['has_hidden_comments']) self.assertGreater(len(hidden['items']), 0) visible = comment_list(claim_id, exclude_mode='visible') self.assertFalse(visible['has_hidden_comments']) self.assertNotEqual(listed_comments['items'], visible['items']) # make sure the hidden comment is the one we marked as hidden hidden_comment = hidden['items'][0] self.assertEqual(hidden_comment['comment_id'], comm2['comment_id']) hidden_ids = [c['comment_id'] for c in hidden['items']] visible_ids = [c['comment_id'] for c in visible['items']] composite_ids = hidden_ids + visible_ids listed_comments = comment_list(claim_id) all_ids = [c['comment_id'] for c in listed_comments['items']] composite_ids.sort() all_ids.sort() self.assertEqual(composite_ids, all_ids)
def handle_get_claim_comments(app: web.Application, claim_id: str, parent_id: str = None, page: int = 1, page_size: int = 50, top_level: bool = False) -> dict: return comment_list(claim_id=claim_id, parent_id=parent_id, page=page, page_size=page_size, top_level=top_level)
def handle_get_claim_hidden_comments( app: web.Application, claim_id: str, hidden: bool, page: int = 1, page_size: int = 50, ) -> dict: exclude = 'hidden' if hidden else 'visible' return comment_list(claim_id=claim_id, exclude_mode=exclude, page=page, page_size=page_size)
def testLists(self): for claim_id in self.claim_ids: with self.subTest(claim_id=claim_id): comments = comment_list(claim_id) self.assertIsNotNone(comments) self.assertGreater(comments['page_size'], 0) self.assertIn('has_hidden_comments', comments) self.assertFalse(comments['has_hidden_comments']) top_comments = comment_list(claim_id, top_level=True, page=1, page_size=50) self.assertIsNotNone(top_comments) self.assertEqual(top_comments['page_size'], 50) self.assertEqual(top_comments['page'], 1) self.assertGreaterEqual(top_comments['total_pages'], 0) self.assertGreaterEqual(top_comments['total_items'], 0) comment_ids = comment_list(claim_id, page_size=50, page=1) with self.subTest(comment_ids=comment_ids): self.assertIsNotNone(comment_ids) self.assertLessEqual(len(comment_ids), 50) matching_comments = (comment_ids) self.assertIsNotNone(matching_comments) self.assertEqual(len(matching_comments), len(comment_ids))
def handle_get_comment_ids(app: web.Application, claim_id: str, parent_id: str = None, page: int = 1, page_size: int = 50, flattened=False) -> dict: results = comment_list(claim_id=claim_id, parent_id=parent_id, top_level=(parent_id is None), page=page, page_size=page_size, select_fields=['comment_id', 'parent_id']) if flattened: results.update({ 'items': [item['comment_id'] for item in results['items']], 'replies': [(item['comment_id'], item.get('parent_id')) for item in results['items']] }) return results
def handle_get_comments_by_id(app: web.Application, comment_ids: typing.Union[list, tuple]) -> dict: expression = Comment.comment_id.in_(comment_ids) return comment_list(expressions=expression, page_size=len(comment_ids))