Compatibility fix for older sqlite version + improvements #18

Merged
osilkin98 merged 5 commits from hidden_db_fix into master 2019-10-16 23:09:40 +02:00
3 changed files with 27 additions and 12 deletions

View file

@ -18,7 +18,7 @@ setup(
'asyncio>=3.4.3', 'asyncio>=3.4.3',
'aiohttp==3.5.4', 'aiohttp==3.5.4',
'aiojobs==0.2.2', 'aiojobs==0.2.2',
'ecdsa==0.13', 'ecdsa>=0.13.3',
'cryptography==2.5', 'cryptography==2.5',
'aiosqlite==0.10.0', 'aiosqlite==0.10.0',
'PyNaCl>=1.3.0', 'PyNaCl>=1.3.0',

View file

@ -119,10 +119,19 @@ def insert_comment(conn: sqlite3.Connection, claim_id: str, comment: str, parent
conn.execute( conn.execute(
""" """
INSERT INTO COMMENT(CommentId, LbryClaimId, ChannelId, Body, ParentId, INSERT INTO COMMENT(CommentId, LbryClaimId, ChannelId, Body, ParentId,
Timestamp, Signature, SigningTs) Timestamp, Signature, SigningTs, IsHidden)
VALUES (?, ?, ?, ?, ?, ?, ?, ?) VALUES (:comment_id, :claim_id, :channel_id, :comment, :parent_id,
""", :timestamp, :signature, :signing_ts, 0) """,
(comment_id, claim_id, channel_id, comment, parent_id, timestamp, signature, signing_ts) {
'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) logging.info('Inserted Comment into DB, `comment_id`: %s', comment_id)
return comment_id return comment_id

View file

@ -223,28 +223,34 @@ class ListCommentsTest(AsyncioTestCase):
print('exit reached') print('exit reached')
os.remove(self.db_file) os.remove(self.db_file)
async def asyncSetUp(self): async def create_lots_of_comments(self, n=23):
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)] self.comment_list = [{key: self.replace[key]() for key in self.replace.keys()} for _ in range(23)]
for comment in self.comment_list: for comment in self.comment_list:
comment['claim_id'] = self.claim_id comment['claim_id'] = self.claim_id
self.comment_ids = [(await self.post_comment(**comm))['result']['comment_id'] self.comment_ids = [(await self.post_comment(**comm))['result']['comment_id']
for comm in self.comment_list] 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)
async def testListComments(self): async def testListComments(self):
await self.create_lots_of_comments()
response_one = await jsonrpc_post( response_one = await jsonrpc_post(
self.url, 'get_claim_comments', page_size=20, page=1, top_level=1, claim_id=self.claim_id self.url, 'get_claim_comments', page_size=20, page=1, top_level=1, claim_id=self.claim_id
) )
self.assertIsNotNone(response_one) self.assertIsNotNone(response_one)
self.assertIn('result', response_one) self.assertIn('result', response_one)
response_one: dict = response_one['result'] response_one: dict = response_one['result']
self.assertIs(type(response_one), dict)
self.assertEqual(response_one['page_size'], len(response_one['items'])) self.assertEqual(response_one['page_size'], len(response_one['items']))
self.assertIn('items', response_one) 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']) self.assertGreaterEqual(response_one['total_pages'], response_one['page'])
last_page = response_one['total_pages'] last_page = response_one['total_pages']
response = await jsonrpc_post(self.url, 'get_claim_comments', page_size=20, response = await jsonrpc_post(self.url, 'get_claim_comments', page_size=20,