Esempio n. 1
0
def test_squash_mdblobs_multiple_chunks(metadata_store):
    rng = random.Random(123)
    md_list = [
        metadata_store.TorrentMetadata(
            title=''.join(
                rng.choice(string.ascii_uppercase + string.digits)
                for _ in range(20)),
            infohash=random_infohash(rng),
            id_=rng.randint(0, 100000000),
            torrent_date=int2time(rng.randint(0, 4000000)),
            timestamp=rng.randint(0, 100000000),
        ) for _ in range(0, 10)
    ]
    # Test splitting into multiple chunks
    chunk, index = entries_to_chunk(md_list, chunk_size=900)
    chunk2, _ = entries_to_chunk(md_list, chunk_size=900, start_index=index)
    dict_list = [d.to_dict()["signature"] for d in md_list]
    for d in md_list:
        d.delete()
    assert dict_list[:index] == [
        d.md_obj.to_dict()["signature"]
        for d in metadata_store.process_compressed_mdblob(
            chunk, skip_personal_metadata_payload=False)
    ]

    assert dict_list[index:] == [
        d.md_obj.to_dict()["signature"]
        for d in metadata_store.process_compressed_mdblob(
            chunk2, skip_personal_metadata_payload=False)
    ]
Esempio n. 2
0
def test_time_convert():
    """
    Test converting various datetime objects to float
    """
    test_time_list = [
        datetime.datetime(2005, 7, 14, 12, 30, 12),
        datetime.datetime(2039, 7, 14, 12, 30, 12),
        datetime.datetime.utcnow().replace(second=0, microsecond=0),
    ]
    for test_time in test_time_list:
        assert test_time == int2time(time2int(test_time))
Esempio n. 3
0
def test_data_dont_fit_in_mdblob(metadata_store):
    import random as rng  # pylint: disable=import-outside-toplevel

    rng.seed(123)
    md_list = [
        metadata_store.TorrentMetadata(
            title='test' + str(x),
            infohash=random_infohash(rng),
            id_=rng.randint(0, 100000000),
            torrent_date=int2time(rng.randint(0, 4000000)),
            timestamp=rng.randint(0, 100000000),
        ) for x in range(0, 1)
    ]
    chunk, index = entries_to_chunk(md_list, chunk_size=1)
    assert index == 1
    assert len(chunk) == 205

    # Test corner case of empty list and/or too big index
    with pytest.raises(Exception):
        entries_to_chunk(md_list, chunk_size=1000, start_index=1000)
    with pytest.raises(Exception):
        entries_to_chunk([], chunk_size=1)
Esempio n. 4
0
def test_negative_time():
    """
    Test whether we are able to deal with time below the epoch time
    """
    negative_time = EPOCH - datetime.timedelta(1)
    assert negative_time == int2time(time2int(negative_time))
Esempio n. 5
0
def test_zero_time():
    """
    Test whether a time of zero converts to the epoch time
    """
    assert int2time(0.0) == EPOCH