Skip to content

Commit

Permalink
Replace random words by fake words
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Nov 29, 2021
1 parent 6b885ec commit 55dc478
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/tribler-core/tribler_core/components/metadata_store/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import random
import string
import time

from faker import Faker

from ipv8.keyvault.crypto import default_eccrypto

from pony.orm import db_session
Expand All @@ -10,13 +11,13 @@
from tribler_core.components.tag.community.tag_payload import TagOperation
from tribler_core.components.tag.db.tag_db import TagDatabase, TagOperationEnum
from tribler_core.tests.tools.common import PNG_FILE
from tribler_core.utilities.random_utils import random_infohash, random_string, random_utf8_string

from tribler_core.utilities.random_utils import random_infohash

# Some random keys used for generating tags.
random_key_1 = default_eccrypto.generate_key('low')
random_key_2 = default_eccrypto.generate_key('low')
random_key_3 = default_eccrypto.generate_key('low')
fake = Faker()


class RequestTimeoutException(Exception):
Expand All @@ -27,10 +28,14 @@ class NoChannelSourcesException(Exception):
pass


def generate_title(words_count=5):
return fake.sentence(nb_words=words_count)[:-1]


def tag_torrent(infohash, tags_db, tags=None, suggested_tags=None):
tags = tags or [random_string(size=random.randint(3, 10), chars=string.ascii_lowercase)
tags = tags or [fake.word()
for _ in range(random.randint(2, 6))]
suggested_tags = suggested_tags or [random_string(size=random.randint(3, 10), chars=string.ascii_lowercase)
suggested_tags = suggested_tags or [fake.word()
for _ in range(random.randint(1, 3))]

# Give each torrent some tags
Expand Down Expand Up @@ -58,15 +63,15 @@ def generate_torrent(metadata_store, tags_db, parent):
last_check = now - random.randint(3600, 24 * 3600)
category = random.choice(["Video", "Audio", "Documents", "Compressed", "Books", "Science"])
torrent_state = metadata_store.TorrentState(infohash=infohash, seeders=10, last_check=last_check)
metadata_store.TorrentMetadata(title=random_utf8_string(50), infohash=infohash, origin_id=parent.id_,
metadata_store.TorrentMetadata(title=generate_title(words_count=4), infohash=infohash, origin_id=parent.id_,
health=torrent_state, tags=category)

tag_torrent(infohash, tags_db)


@db_session
def generate_collection(metadata_store, tags_db, parent):
coll = metadata_store.CollectionNode(title=random_utf8_string(50), origin_id=parent.id_)
coll = metadata_store.CollectionNode(title=generate_title(words_count=3), origin_id=parent.id_)
for _ in range(0, 3):
generate_torrent(metadata_store, tags_db, coll)

Expand All @@ -78,7 +83,7 @@ def generate_channel(metadata_store: MetadataStore, tags_db: TagDatabase, title=

metadata_store.ChannelNode._my_key = default_eccrypto.generate_key('low')
chan = metadata_store.ChannelMetadata(
title=title or random_utf8_string(100), subscribed=subscribed, infohash=random_infohash()
title=generate_title(words_count=5), subscribed=subscribed, infohash=random_infohash()
)

# add some collections to the channel
Expand Down Expand Up @@ -112,7 +117,7 @@ def generate_test_channels(metadata_store, tags_db) -> None:
generate_collection(metadata_store, tags_db, chan1)
chan1.commit_channel_torrent()

chan2 = metadata_store.ChannelMetadata.create_channel(title="personal channel " + random_utf8_string(50))
chan2 = metadata_store.ChannelMetadata.create_channel(title="personal channel " + generate_title(words_count=2))
for _ in range(0, 3):
generate_collection(metadata_store, tags_db, chan2)

Expand Down

0 comments on commit 55dc478

Please sign in to comment.