Tests for name validation
This commit is contained in:
parent
7c92ab3aa6
commit
4d6855bcc0
3 changed files with 63 additions and 9 deletions
|
@ -38,7 +38,7 @@ CREATE INDEX COMMENT_CLAIM_INDEX ON COMMENT (LbryClaimId);
|
||||||
-- VIEWS
|
-- VIEWS
|
||||||
DROP VIEW IF EXISTS COMMENTS_ON_CLAIMS;
|
DROP VIEW IF EXISTS COMMENTS_ON_CLAIMS;
|
||||||
CREATE VIEW COMMENTS_ON_CLAIMS (comment_id, claim_id, timestamp, channel_name, channel_id, channel_uri, comment, parent_id) AS
|
CREATE VIEW COMMENTS_ON_CLAIMS (comment_id, claim_id, timestamp, channel_name, channel_id, channel_uri, comment, parent_id) AS
|
||||||
SELECT C.CommentId, C.LbryClaimId, C.Timestamp, CHAN.Name, CHAN.ClaimId, 'lbry://' || '@' || CHAN.Name || '#' || CHAN.ClaimId, C.Body, C.ParentId
|
SELECT C.CommentId, C.LbryClaimId, C.Timestamp, CHAN.Name, CHAN.ClaimId, 'lbry://' || CHAN.Name || '#' || CHAN.ClaimId, C.Body, C.ParentId
|
||||||
FROM CHANNEL AS CHAN
|
FROM CHANNEL AS CHAN
|
||||||
INNER JOIN COMMENT C on CHAN.ClaimId = C.ChannelId
|
INNER JOIN COMMENT C on CHAN.ClaimId = C.ChannelId
|
||||||
ORDER BY C.Timestamp;
|
ORDER BY C.Timestamp;
|
||||||
|
|
|
@ -91,13 +91,25 @@ class DatabaseConnection:
|
||||||
)
|
)
|
||||||
return comment_id
|
return comment_id
|
||||||
|
|
||||||
def create_comment(self, channel_name: str = None, channel_id: str = None, **kwargs) -> dict:
|
def create_comment(self, comment: str, claim_id: str, channel_name: str = None,
|
||||||
|
channel_id: str = None, **kwargs) -> dict:
|
||||||
|
|
||||||
if channel_id and channel_name:
|
if channel_id and channel_name:
|
||||||
|
validate_input(
|
||||||
|
comment=comment,
|
||||||
|
claim_id=claim_id,
|
||||||
|
channel_id=channel_id,
|
||||||
|
channel_name=channel_name,
|
||||||
|
)
|
||||||
self._insert_channel(channel_name, channel_id)
|
self._insert_channel(channel_name, channel_id)
|
||||||
else:
|
else:
|
||||||
channel_name, channel_id = anonymous['channel_name'], anonymous['channel_id']
|
channel_id=anonymous['channel_id']
|
||||||
validate_input(channel_id=channel_id, channel_name=channel_name, **kwargs)
|
comcast_id = self._insert_comment(
|
||||||
comcast_id = self._insert_comment(channel_id=channel_id, **kwargs)
|
comment=comment,
|
||||||
|
claim_id=claim_id,
|
||||||
|
channel_id=channel_id,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
curry = self.connection.execute(
|
curry = self.connection.execute(
|
||||||
'SELECT * FROM COMMENTS_ON_CLAIMS WHERE comment_id = ?', (comcast_id,)
|
'SELECT * FROM COMMENTS_ON_CLAIMS WHERE comment_id = ?', (comcast_id,)
|
||||||
)
|
)
|
||||||
|
|
|
@ -36,7 +36,7 @@ class TestCommentCreation(unittest.TestCase):
|
||||||
comment = self.db.create_comment(
|
comment = self.db.create_comment(
|
||||||
claim_id=self.claimId,
|
claim_id=self.claimId,
|
||||||
comment='This is a named comment',
|
comment='This is a named comment',
|
||||||
channel_name='username',
|
channel_name='@username',
|
||||||
channel_id='529357c3422c6046d3fec76be2358004ba22abcd',
|
channel_id='529357c3422c6046d3fec76be2358004ba22abcd',
|
||||||
)
|
)
|
||||||
self.assertIsNotNone(comment)
|
self.assertIsNotNone(comment)
|
||||||
|
@ -48,7 +48,7 @@ class TestCommentCreation(unittest.TestCase):
|
||||||
reply = self.db.create_comment(
|
reply = self.db.create_comment(
|
||||||
claim_id=self.claimId,
|
claim_id=self.claimId,
|
||||||
comment='This is a named response',
|
comment='This is a named response',
|
||||||
channel_name='another_username',
|
channel_name='@another_username',
|
||||||
channel_id='529357c3422c6046d3fec76be2358004ba224bcd',
|
channel_id='529357c3422c6046d3fec76be2358004ba224bcd',
|
||||||
parent_id=previous_id
|
parent_id=previous_id
|
||||||
)
|
)
|
||||||
|
@ -86,7 +86,7 @@ class TestCommentCreation(unittest.TestCase):
|
||||||
comment = self.db.create_comment(
|
comment = self.db.create_comment(
|
||||||
claim_id=self.claimId,
|
claim_id=self.claimId,
|
||||||
comment='I like big butts and i cannot lie',
|
comment='I like big butts and i cannot lie',
|
||||||
channel_name='sirmixalot',
|
channel_name='@sirmixalot',
|
||||||
channel_id='529357c3422c6046d3fec76be2358005ba22abcd',
|
channel_id='529357c3422c6046d3fec76be2358005ba22abcd',
|
||||||
sig='siggy'
|
sig='siggy'
|
||||||
)
|
)
|
||||||
|
@ -99,7 +99,7 @@ class TestCommentCreation(unittest.TestCase):
|
||||||
reply = self.db.create_comment(
|
reply = self.db.create_comment(
|
||||||
claim_id=self.claimId,
|
claim_id=self.claimId,
|
||||||
comment='This is a LBRY verified response',
|
comment='This is a LBRY verified response',
|
||||||
channel_name='LBRY',
|
channel_name='@LBRY',
|
||||||
channel_id='529357c3422c6046d3fec76be2358001ba224bcd',
|
channel_id='529357c3422c6046d3fec76be2358001ba224bcd',
|
||||||
parent_id=previous_id,
|
parent_id=previous_id,
|
||||||
sig='Cursive Font Goes Here'
|
sig='Cursive Font Goes Here'
|
||||||
|
@ -111,3 +111,45 @@ class TestCommentCreation(unittest.TestCase):
|
||||||
self.assertEqual(reply['parent_id'], comment['comment_id'])
|
self.assertEqual(reply['parent_id'], comment['comment_id'])
|
||||||
self.assertEqual(reply['claim_id'], comment['claim_id'])
|
self.assertEqual(reply['claim_id'], comment['claim_id'])
|
||||||
|
|
||||||
|
def testInvalidUsername(self):
|
||||||
|
self.assertRaises(
|
||||||
|
AssertionError,
|
||||||
|
self.db.create_comment,
|
||||||
|
claim_id=self.claimId,
|
||||||
|
channel_name='$#(@#$@#$',
|
||||||
|
channel_id='529357c3422c6046d3fec76be2358001ba224b23',
|
||||||
|
comment='this is an invalid username'
|
||||||
|
)
|
||||||
|
comment = self.db.create_comment(
|
||||||
|
claim_id=self.claimId,
|
||||||
|
channel_name='@' + 'a'*255,
|
||||||
|
channel_id='529357c3422c6046d3fec76be2358001ba224b23',
|
||||||
|
comment='this is a valid username'
|
||||||
|
)
|
||||||
|
self.assertIsNotNone(comment)
|
||||||
|
self.assertRaises(
|
||||||
|
AssertionError,
|
||||||
|
self.db.create_comment,
|
||||||
|
claim_id=self.claimId,
|
||||||
|
channel_name='@' + 'a'*256,
|
||||||
|
channel_id='529357c3422c6046d3fec76be2358001ba224b23',
|
||||||
|
comment='this username is too long'
|
||||||
|
)
|
||||||
|
comment = self.db.create_comment(
|
||||||
|
claim_id=self.claimId,
|
||||||
|
channel_name='',
|
||||||
|
channel_id='529357c3422c6046d3fec76be2358001ba224b23',
|
||||||
|
comment='this username will default to anonymous'
|
||||||
|
)
|
||||||
|
self.assertIsNotNone(comment)
|
||||||
|
self.assertEqual(comment['channel_name'], server.conf.anonymous['channel_name'])
|
||||||
|
self.assertEqual(comment['channel_id'], server.conf.anonymous['channel_id'])
|
||||||
|
self.assertRaises(
|
||||||
|
AssertionError,
|
||||||
|
self.db.create_comment,
|
||||||
|
claim_id=self.claimId,
|
||||||
|
channel_name='@',
|
||||||
|
channel_id='529357c3422c6046d3fec76be2358001ba224b23',
|
||||||
|
comment='this username is too short'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue