Exemplo n.º 1
0
 async def test04CreateAllReplies(self):
     claim_id = '1d8a5cc39ca02e55782d619e67131c0a20843be8'
     parent_comment = await self.post_comment(
         channel_name='@KevinWalterRabie',
         channel_id=fake.sha1(),
         comment='Hello everybody and welcome back to my chan nel',
         claim_id=claim_id,
         signing_ts='1234',
         signature='_' * 128)
     parent_id = parent_comment['result']['comment_id']
     test_all = create_test_comments(
         ('comment', 'channel_name', 'channel_id', 'signature',
          'parent_id'),
         parent_id=parent_id,
         comment=None,
         channel_name=None,
         channel_id=None,
         signature=None,
         claim_id=claim_id)
     for test in test_all:
         with self.subTest(test=test):
             if test['parent_id'] != parent_id:
                 continue
             else:
                 message = await self.post_comment(**test)
                 self.assertTrue('result' in message or 'error' in message)
                 if 'error' in message:
                     self.assertFalse(is_valid_base_comment(**test))
                 else:
                     self.assertTrue(is_valid_base_comment(**test))
Exemplo n.º 2
0
 async def test03CreateAllTestComments(self):
     test_all = create_test_comments(replace.keys(),
                                     **{k: None
                                        for k in replace.keys()})
     test_all.reverse()
     for test in test_all:
         nulls = 'null fields: ' + ', '.join(
             k for k, v in test.items() if not v)
         with self.subTest(test=nulls):
             message = await self.post_comment(**test)
             self.assertTrue('result' in message or 'error' in message)
             if 'error' in message:
                 self.assertFalse(is_valid_base_comment(**test,
                                                        strict=True))
             else:
                 self.assertTrue(is_valid_base_comment(**test, strict=True))
Exemplo n.º 3
0
 async def test02CreateNamedCommentsNoReply(self):
     named_test = create_test_comments(
         ('channel_name', 'channel_id', 'signature'),
         claim_id='1234567890123456789012345678901234567890',
         channel_name='@JamieFoxx',
         channel_id='1234567890' * 4,
         comment='blah blah blahbity blah',
         signature=None)
     for test in named_test:
         with self.subTest(test=test):
             message = await self.post_comment(**test)
             self.assertTrue('result' in message or 'error' in message)
             if 'error' in message:
                 self.assertFalse(is_valid_base_comment(**test))
             else:
                 self.assertTrue(is_valid_base_comment(**test))
Exemplo n.º 4
0
 async def test01CreateCommentNoReply(self):
     anonymous_test = create_test_comments(
         ('claim_id', 'channel_id', 'channel_name', 'comment'),
         comment=None,
         channel_name=None,
         channel_id=None,
         claim_id=None)
     for test in anonymous_test:
         with self.subTest(test='null fields: ' +
                           ', '.join(k for k, v in test.items() if not v)):
             message = await self.post_comment(**test)
             self.assertTrue('result' in message or 'error' in message)
             if 'error' in message:
                 self.assertFalse(is_valid_base_comment(**test))
             else:
                 self.assertTrue(is_valid_base_comment(**test))
Exemplo n.º 5
0
def create_comment(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:
    if not is_valid_base_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):
        raise ValueError('Invalid Parameters given for comment')

    channel, _ = Channel.get_or_create(name=channel_name, claim_id=channel_id)
    if parent_id and not claim_id:
        parent: Comment = Comment.get_by_id(parent_id)
        claim_id = parent.claim_id

    timestamp = int(time.time())
    comment_id = create_comment_id(comment, channel_id, timestamp)
    new_comment = Comment.create(claim_id=claim_id,
                                 comment_id=comment_id,
                                 comment=comment,
                                 parent=parent_id,
                                 channel=channel,
                                 signature=signature,
                                 signing_ts=signing_ts,
                                 timestamp=timestamp)
    return get_comment(new_comment.comment_id)
Exemplo n.º 6
0
async def create_comment(app, params):
    if is_valid_base_comment(**params):
        job = await app['comment_scheduler'].spawn(_create_comment(
            app, params))
        comment = await job.wait()
        if comment:
            await app['webhooks'].spawn(
                send_notification(app, 'CREATE', comment))
        return comment
    else:
        raise ValueError('base comment is invalid')