From 905e394c5fb2cd386a41b76252dfafb827b34e7a Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Wed, 16 Oct 2019 16:53:35 -0400 Subject: [PATCH 1/5] Explicitly sets IsHidden flag to 0 when inserting --- src/database/queries.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/database/queries.py b/src/database/queries.py index 7487b6a..7a12793 100644 --- a/src/database/queries.py +++ b/src/database/queries.py @@ -119,10 +119,19 @@ def insert_comment(conn: sqlite3.Connection, claim_id: str, comment: str, parent conn.execute( """ INSERT INTO COMMENT(CommentId, LbryClaimId, ChannelId, Body, ParentId, - Timestamp, Signature, SigningTs) - VALUES (?, ?, ?, ?, ?, ?, ?, ?) - """, - (comment_id, claim_id, channel_id, comment, parent_id, timestamp, signature, signing_ts) + Timestamp, Signature, SigningTs, IsHidden) + VALUES (:comment_id, :claim_id, :channel_id, :comment, :parent_id, + :timestamp, :signature, :signing_ts, 0) """, + { + 'comment_id': comment_id, + 'claim_id': claim_id, + 'channel_id': channel_id, + 'comment': comment, + 'parent_id': parent_id, + 'timestamp': timestamp, + 'signature': signature, + 'signing_ts': signing_ts + } ) logging.info('Inserted Comment into DB, `comment_id`: %s', comment_id) return comment_id -- 2.45.2 From e5cee12efea4bf1e46d4c64b3926a2a0a2abe9b7 Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Wed, 16 Oct 2019 17:00:21 -0400 Subject: [PATCH 2/5] Slight testing improvement --- test/test_server.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/test/test_server.py b/test/test_server.py index 0712ab4..72c794e 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -223,28 +223,34 @@ class ListCommentsTest(AsyncioTestCase): print('exit reached') os.remove(self.db_file) + async def create_lots_of_comments(self, n=23): + self.comment_list = [{key: self.replace[key]() for key in self.replace.keys()} for _ in range(23)] + for comment in self.comment_list: + comment['claim_id'] = self.claim_id + self.comment_ids = [(await self.post_comment(**comm))['result']['comment_id'] + for comm in self.comment_list] + async def asyncSetUp(self): await super().asyncSetUp() self.server = app.CommentDaemon(config, db_file=self.db_file) await self.server.start(self.host, self.port) self.addCleanup(self.server.stop) - if self.comment_ids is None: - self.comment_list = [{key: self.replace[key]() for key in self.replace.keys()} for _ in range(23)] - for comment in self.comment_list: - comment['claim_id'] = self.claim_id - self.comment_ids = [(await self.post_comment(**comm))['result']['comment_id'] - for comm in self.comment_list] async def testListComments(self): + await self.create_lots_of_comments() response_one = await jsonrpc_post( self.url, 'get_claim_comments', page_size=20, page=1, top_level=1, claim_id=self.claim_id ) self.assertIsNotNone(response_one) self.assertIn('result', response_one) response_one: dict = response_one['result'] - self.assertIs(type(response_one), dict) self.assertEqual(response_one['page_size'], len(response_one['items'])) self.assertIn('items', response_one) + + comments = response_one['items'] + hidden = list(filter(lambda c: c['is_hidden'], comments)) + self.assertEqual(hidden, []) + self.assertGreaterEqual(response_one['total_pages'], response_one['page']) last_page = response_one['total_pages'] response = await jsonrpc_post(self.url, 'get_claim_comments', page_size=20, -- 2.45.2 From 99532dda1bbf346bc0e25a6b07e9b9227c760954 Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Wed, 16 Oct 2019 17:01:20 -0400 Subject: [PATCH 3/5] Adds script to display comments and the name of the claim they're on --- scripts/display_comments_on_claims.py | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 scripts/display_comments_on_claims.py diff --git a/scripts/display_comments_on_claims.py b/scripts/display_comments_on_claims.py new file mode 100644 index 0000000..5d40365 --- /dev/null +++ b/scripts/display_comments_on_claims.py @@ -0,0 +1,29 @@ +import json + +if __name__ == '__main__': + with open('comments_on_claims.json', 'r') as fp: + claims = json.load(fp) + + for claim in claims.values(): + if claim: + print('\n' + claim['name']) + comment: dict = {} + for comment in claim['comments']: + output = f"\t{comment['channel_name']}: " + comment: str = comment['comment'] + slices = comment.split('\n') + for i, slice in enumerate(slices): + if len(slice) > 120: + if '\n' not in comment and len(comment) > 120: + parts = [] + for i in range(0, len(comment), 120): + + + + else: + output += comment.replace('\n', '\n\t\t') + output += '\n' + + print(output) + + print('_'*256 + '\n') -- 2.45.2 From f74e392cbebcbc217ce77516e8341244ccf6f836 Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Wed, 16 Oct 2019 17:03:00 -0400 Subject: [PATCH 4/5] Upgrade ecdsa to version 0.13.3 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index dc5a7e0..923e82a 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup( 'asyncio>=3.4.3', 'aiohttp==3.5.4', 'aiojobs==0.2.2', - 'ecdsa==0.13', + 'ecdsa>=0.13.3', 'cryptography==2.5', 'aiosqlite==0.10.0', 'PyNaCl>=1.3.0', -- 2.45.2 From 6bb8409f096fdba25c1ab825c05c11da581f570a Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Wed, 16 Oct 2019 17:08:02 -0400 Subject: [PATCH 5/5] Remove this script, it's not needed --- scripts/display_comments_on_claims.py | 29 --------------------------- 1 file changed, 29 deletions(-) delete mode 100644 scripts/display_comments_on_claims.py diff --git a/scripts/display_comments_on_claims.py b/scripts/display_comments_on_claims.py deleted file mode 100644 index 5d40365..0000000 --- a/scripts/display_comments_on_claims.py +++ /dev/null @@ -1,29 +0,0 @@ -import json - -if __name__ == '__main__': - with open('comments_on_claims.json', 'r') as fp: - claims = json.load(fp) - - for claim in claims.values(): - if claim: - print('\n' + claim['name']) - comment: dict = {} - for comment in claim['comments']: - output = f"\t{comment['channel_name']}: " - comment: str = comment['comment'] - slices = comment.split('\n') - for i, slice in enumerate(slices): - if len(slice) > 120: - if '\n' not in comment and len(comment) > 120: - parts = [] - for i in range(0, len(comment), 120): - - - - else: - output += comment.replace('\n', '\n\t\t') - output += '\n' - - print(output) - - print('_'*256 + '\n') -- 2.45.2