Exemple #1
0
def test_random_utf8_string():
    test_string = random_utf8_string()
    assert test_string
    assert isinstance(test_string, str)
    assert len(test_string) == 6

    text_length = 16
    test_string2 = random_utf8_string(length=text_length)
    assert isinstance(test_string, str)
    assert len(test_string2) == text_length
Exemple #2
0
    def test_random_utf8_string(self):
        test_string = random_utf8_string()
        self.assertIsNotNone(test_string)
        self.assertTrue(isinstance(test_string, str))
        self.assertEqual(len(test_string), 6)

        text_length = 16
        test_string2 = random_utf8_string(length=text_length)
        self.assertTrue(isinstance(test_string, str))
        self.assertEqual(len(test_string2), text_length)
Exemple #3
0
def generate_test_channels(metadata_store):
    # First, generate some foreign channels
    for ind in range(0, 10):
        generate_channel(metadata_store, subscribed=ind % 2 == 0)

    # This one is necessary to test filters, etc
    generate_channel(metadata_store, title="non-random channel name")

    # The same, but subscribed
    generate_channel(metadata_store,
                     title="non-random subscribed channel name",
                     subscribed=True)

    # Now generate a couple of personal channels
    chan1 = metadata_store.ChannelMetadata.create_channel(
        title="personal channel with non-random name")
    for _ in range(0, 3):
        generate_collection(metadata_store, chan1)
    chan1.commit_channel_torrent()

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

    # add 'Tribler' entry to facilitate keyword search tests
    generate_channel(metadata_store,
                     title="Tribler tribler chan",
                     subscribed=True)
Exemple #4
0
def generate_channel(metadata_store, title=None, subscribed=False):
    # Remember and restore the original key
    orig_key = metadata_store.ChannelNode._my_key

    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()
    )

    # add some collections to the channel
    for _ in range(0, 3):
        generate_collection(metadata_store, chan)

    metadata_store.ChannelNode._my_key = orig_key
Exemple #5
0
def generate_test_channels(metadata_store):
    # First, generate some foreign channels
    for ind in range(0, 10):
        generate_channel(metadata_store, subscribed=ind % 2 == 0)

    # This one is necessary to test filters, etc
    generate_channel(metadata_store, title="non-random channel name")

    # The same, but subscribed
    generate_channel(metadata_store, title="non-random subscribed channel name", subscribed=True)

    # Now generate a couple of personal channels
    chan1 = metadata_store.ChannelMetadata.create_channel(title="personal channel with non-random name")

    with open(PNG_FILE, "rb") as f:
        pic_bytes = f.read()
    metadata_store.ChannelThumbnail(binary_data=pic_bytes, data_type="image/png", origin_id=chan1.id_)
    metadata_store.ChannelDescription(json_text='{"description_text": "# Hi guys"}', origin_id=chan1.id_)

    for _ in range(0, 3):
        generate_collection(metadata_store, chan1)
    chan1.commit_channel_torrent()

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

    # add 'Tribler' entry to facilitate keyword search tests
    generate_channel(metadata_store, title="Tribler tribler chan", subscribed=True)
Exemple #6
0
def generate_collection(metadata_store, parent):
    coll = metadata_store.CollectionNode(title=random_utf8_string(50), origin_id=parent.id_)
    for _ in range(0, 3):
        generate_torrent(metadata_store, coll)
Exemple #7
0
def generate_torrent(metadata_store, parent):
    metadata_store.TorrentMetadata(title=random_utf8_string(50), infohash=random_infohash(), origin_id=parent.id_)