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 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 test01NamedComments(self): comment = create_comment( claim_id=self.claimId, comment='This is a named comment', channel_name='@username', channel_id='529357c3422c6046d3fec76be2358004ba22abcd', signature='22' * 64, signing_ts='aaa') self.assertIsNotNone(comment) self.assertNotIn('parent_in', comment) previous_id = comment['comment_id'] reply = create_comment( claim_id=self.claimId, comment='This is a named response', channel_name='@another_username', channel_id='529357c3422c6046d3fec76be2358004ba224bcd', parent_id=previous_id, signature='11' * 64, signing_ts='aaa') self.assertIsNotNone(reply) self.assertEqual(reply['parent_id'], comment['comment_id'])
def test03SignedComments(self): comment = create_comment( claim_id=self.claimId, comment='I like big butts and i cannot lie', channel_name='@sirmixalot', channel_id='529357c3422c6046d3fec76be2358005ba22abcd', signature='24' * 64, signing_ts='asdasd') self.assertIsNotNone(comment) self.assertIn('signing_ts', comment) previous_id = comment['comment_id'] reply = create_comment( claim_id=self.claimId, comment='This is a LBRY verified response', channel_name='@LBRY', channel_id='529357c3422c6046d3fec76be2358001ba224bcd', parent_id=previous_id, signature='12' * 64, signing_ts='sfdfdfds') self.assertIsNotNone(reply) self.assertEqual(reply['parent_id'], comment['comment_id']) self.assertIn('signing_ts', reply)
def test04UsernameVariations(self): self.assertRaises( ValueError, create_comment, claim_id=self.claimId, channel_name='$#(@#$@#$', channel_id='529357c3422c6046d3fec76be2358001ba224b23', comment='this is an invalid username', signature='1' * 128, signing_ts='123') valid_username = create_comment( claim_id=self.claimId, channel_name='@' + 'a' * 255, channel_id='529357c3422c6046d3fec76be2358001ba224b23', comment='this is a valid username', signature='1' * 128, signing_ts='123') self.assertIsNotNone(valid_username) self.assertRaises( ValueError, create_comment, claim_id=self.claimId, channel_name='@' + 'a' * 256, channel_id='529357c3422c6046d3fec76be2358001ba224b23', comment='this username is too long', signature='2' * 128, signing_ts='123') self.assertRaises( ValueError, create_comment, claim_id=self.claimId, channel_name='', channel_id='529357c3422c6046d3fec76be2358001ba224b23', comment='this username should not default to ANONYMOUS', signature='3' * 128, signing_ts='123') self.assertRaises( ValueError, create_comment, claim_id=self.claimId, channel_name='@', channel_id='529357c3422c6046d3fec76be2358001ba224b23', comment='this username is too short', signature='3' * 128, signing_ts='123')
def handle_create_comment(app, comment: str = None, claim_id: str = None, parent_id: str = None, channel_id: str = None, channel_name: str = None, signature: str = None, signing_ts: str = None) -> dict: with app['db'].atomic(): return create_comment(comment=comment, claim_id=claim_id, parent_id=parent_id, channel_id=channel_id, channel_name=channel_name, signature=signature, signing_ts=signing_ts)
def test05HideComments(self): comm = create_comment(comment='Comment #1', claim_id=self.claimId, channel_id='1' * 40, channel_name='@Doge123', signature='a' * 128, signing_ts='123') comment = get_comment(comm['comment_id']) self.assertFalse(comment['is_hidden']) success = set_hidden_flag([comm['comment_id']]) self.assertTrue(success) comment = get_comment(comm['comment_id']) self.assertTrue(comment['is_hidden']) success = set_hidden_flag([comm['comment_id']]) self.assertTrue(success) comment = get_comment(comm['comment_id']) self.assertTrue(comment['is_hidden'])