Moves functions around into more logical locations
This commit is contained in:
parent
a1b1fa2b1f
commit
02cf92720e
6 changed files with 111 additions and 111 deletions
tests
|
@ -5,11 +5,10 @@ from faker.providers import internet
|
|||
from faker.providers import lorem
|
||||
from faker.providers import misc
|
||||
|
||||
from src.database import get_comments_by_id, create_comment, get_comment_ids, \
|
||||
get_claim_comments
|
||||
from schema.db_helpers import setup_database, teardown_database
|
||||
from src.settings import config
|
||||
from tests.testcase import DatabaseTestCase, AsyncioTestCase
|
||||
from src.database import get_comments_by_id, get_comment_ids, \
|
||||
get_claim_comments
|
||||
from src.writes import create_comment
|
||||
from tests.testcase import DatabaseTestCase
|
||||
|
||||
fake = faker.Faker()
|
||||
fake.add_provider(internet)
|
||||
|
@ -29,9 +28,11 @@ class TestCommentCreation(DatabaseTestCase):
|
|||
comment='This is a named comment',
|
||||
channel_name='@username',
|
||||
channel_id='529357c3422c6046d3fec76be2358004ba22abcd',
|
||||
signature=fake.uuid4(),
|
||||
signing_ts='aaa'
|
||||
)
|
||||
self.assertIsNotNone(comment)
|
||||
self.assertIsNone(comment['parent_id'])
|
||||
self.assertNotIn('parent_in', comment)
|
||||
previous_id = comment['comment_id']
|
||||
reply = create_comment(
|
||||
conn=self.conn,
|
||||
|
@ -39,11 +40,12 @@ class TestCommentCreation(DatabaseTestCase):
|
|||
comment='This is a named response',
|
||||
channel_name='@another_username',
|
||||
channel_id='529357c3422c6046d3fec76be2358004ba224bcd',
|
||||
parent_id=previous_id
|
||||
parent_id=previous_id,
|
||||
signature=fake.uuid4(),
|
||||
signing_ts='aaa'
|
||||
)
|
||||
self.assertIsNotNone(reply)
|
||||
self.assertEqual(reply['parent_id'], comment['comment_id'])
|
||||
self.assertEqual(reply['claim_id'], comment['claim_id'])
|
||||
|
||||
def test02AnonymousComments(self):
|
||||
comment = create_comment(
|
||||
|
@ -52,7 +54,6 @@ class TestCommentCreation(DatabaseTestCase):
|
|||
comment='This is an ANONYMOUS comment'
|
||||
)
|
||||
self.assertIsNotNone(comment)
|
||||
self.assertIsNone(comment['parent_id'])
|
||||
previous_id = comment['comment_id']
|
||||
reply = create_comment(
|
||||
conn=self.conn,
|
||||
|
@ -62,7 +63,6 @@ class TestCommentCreation(DatabaseTestCase):
|
|||
)
|
||||
self.assertIsNotNone(reply)
|
||||
self.assertEqual(reply['parent_id'], comment['comment_id'])
|
||||
self.assertEqual(reply['claim_id'], comment['claim_id'])
|
||||
|
||||
def test03SignedComments(self):
|
||||
comment = create_comment(
|
||||
|
@ -71,10 +71,10 @@ class TestCommentCreation(DatabaseTestCase):
|
|||
comment='I like big butts and i cannot lie',
|
||||
channel_name='@sirmixalot',
|
||||
channel_id='529357c3422c6046d3fec76be2358005ba22abcd',
|
||||
signature='siggy'
|
||||
signature=fake.uuid4(),
|
||||
signing_ts='asdasd'
|
||||
)
|
||||
self.assertIsNotNone(comment)
|
||||
self.assertIsNone(comment['parent_id'])
|
||||
previous_id = comment['comment_id']
|
||||
reply = create_comment(
|
||||
conn=self.conn,
|
||||
|
@ -83,11 +83,11 @@ class TestCommentCreation(DatabaseTestCase):
|
|||
channel_name='@LBRY',
|
||||
channel_id='529357c3422c6046d3fec76be2358001ba224bcd',
|
||||
parent_id=previous_id,
|
||||
signature='Cursive Font Goes Here'
|
||||
signature=fake.uuid4(),
|
||||
signing_ts='sfdfdfds'
|
||||
)
|
||||
self.assertIsNotNone(reply)
|
||||
self.assertEqual(reply['parent_id'], comment['comment_id'])
|
||||
self.assertEqual(reply['claim_id'], comment['claim_id'])
|
||||
|
||||
def test04UsernameVariations(self):
|
||||
invalid_comment = create_comment(
|
||||
|
@ -187,16 +187,10 @@ class ListDatabaseTest(DatabaseTestCase):
|
|||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
top_coms, self.claim_ids = generate_top_comments(5, 75)
|
||||
self.top_comments = {
|
||||
commie_id: [create_comment(self.conn, **commie) for commie in commie_list]
|
||||
for commie_id, commie_list in top_coms.items()
|
||||
}
|
||||
self.replies = [
|
||||
create_comment(self.conn, **reply)
|
||||
for reply in generate_replies(self.top_comments)
|
||||
]
|
||||
|
||||
def testLists(self):
|
||||
self.skipTest('Populating a database each time is not a good way to test listing')
|
||||
|
||||
for claim_id in self.claim_ids:
|
||||
with self.subTest(claim_id=claim_id):
|
||||
comments = get_claim_comments(self.conn, claim_id)
|
||||
|
@ -217,6 +211,22 @@ class ListDatabaseTest(DatabaseTestCase):
|
|||
self.assertEqual(len(matching_comments), len(comment_ids))
|
||||
|
||||
|
||||
def generate_top_comments(ncid=15, ncomm=100, minchar=50, maxchar=500):
|
||||
claim_ids = [fake.sha1() for _ in range(ncid)]
|
||||
top_comments = {
|
||||
cid: [{
|
||||
'claim_id': cid,
|
||||
'comment': ''.join(fake.text(max_nb_chars=randint(minchar, maxchar))),
|
||||
'channel_name': '@' + fake.user_name(),
|
||||
'channel_id': fake.sha1(),
|
||||
'signature': fake.uuid4(),
|
||||
'signing_ts': fake.uuid4()
|
||||
} for _ in range(ncomm)]
|
||||
for cid in claim_ids
|
||||
}
|
||||
return top_comments, claim_ids
|
||||
|
||||
|
||||
def generate_replies(top_comments):
|
||||
return [{
|
||||
'claim_id': comment['claim_id'],
|
||||
|
@ -224,7 +234,8 @@ def generate_replies(top_comments):
|
|||
'comment': ' '.join(fake.text(max_nb_chars=randint(50, 500))),
|
||||
'channel_name': '@' + fake.user_name(),
|
||||
'channel_id': fake.sha1(),
|
||||
'signature': fake.uuid4()
|
||||
'signature': fake.uuid4(),
|
||||
'signing_ts': fake.uuid4()
|
||||
}
|
||||
for claim, comments in top_comments.items()
|
||||
for i, comment in enumerate(comments)
|
||||
|
@ -247,19 +258,6 @@ def generate_replies_random(top_comments):
|
|||
]
|
||||
|
||||
|
||||
def generate_top_comments(ncid=15, ncomm=100, minchar=50, maxchar=500):
|
||||
claim_ids = [fake.sha1() for _ in range(ncid)]
|
||||
top_comments = {
|
||||
cid: [{
|
||||
'claim_id': cid,
|
||||
'comment': ''.join(fake.text(max_nb_chars=randint(minchar, maxchar))),
|
||||
'channel_name': '@' + fake.user_name(),
|
||||
'channel_id': fake.sha1(),
|
||||
'signature': fake.uuid4()
|
||||
} for _ in range(ncomm)]
|
||||
for cid in claim_ids
|
||||
}
|
||||
return top_comments, claim_ids
|
||||
|
||||
|
||||
def generate_top_comments_random():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue