diff --git a/src/tribler-core/tribler_core/components/metadata_store/utils.py b/src/tribler-core/tribler_core/components/metadata_store/utils.py index a90d1c12b94..c1a0ba9c816 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/utils.py +++ b/src/tribler-core/tribler_core/components/metadata_store/utils.py @@ -1,22 +1,23 @@ import random -import string import time from ipv8.keyvault.crypto import default_eccrypto from pony.orm import db_session +from faker import Faker + from tribler_core.components.metadata_store.db.store import MetadataStore 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): @@ -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 @@ -58,7 +63,7 @@ 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) @@ -66,7 +71,7 @@ def generate_torrent(metadata_store, tags_db, parent): @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) @@ -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 @@ -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)