Example #1
0
def test_retrieve(test_file, tmp_path):
    storage = FlatStorage('flat', tmp_path)
    storage_info = storage.store(test_file)
    iterator = storage.retrieve(storage_info['ticket'])
    assert isinstance(iterator, Iterator)
    test_file.seek(0)
    assert b''.join(iterator) == test_file.read()
Example #2
0
def test_store(test_file, tmp_path):
    storage = FlatStorage('flat', tmp_path)
    storage_info = storage.store(test_file)
    assert storage_info == FileInfo(
        namespace='flat',
        ticket='my_tiny_id',
        size=28,
        checksum=('md5', '53195454e1210adae36ecb34453a1f5a'),
        metadata={})
Example #3
0
def test_register(tmp_path):
    center = StorageCenter()
    flat = FlatStorage('somewhere', tmp_path)
    center.register(flat)
    assert 'somewhere' in center.namespaces

    someother = FlatStorage('somewhere', tmp_path)
    with pytest.raises(NameError) as exc:
        center.register(someother)
    assert str(exc.value) == 'Namespace `somewhere` already exists.'
Example #4
0
def test_checksum(test_file, tmp_path):
    storage = FlatStorage('flat', tmp_path, algorithm="sha256")
    storage_info = storage.store(test_file)
    assert storage_info['checksum'] == (
        'sha256',
        '18e9b7c9c1be46b1c62938b11b02f513a4d507630c4aee744799df83e0a94ba6')

    with pytest.raises(LookupError) as exc:
        FlatStorage('flat', tmp_path, algorithm="pouet")
    assert str(exc.value) == "Unknown algorithm: `pouet`."
Example #5
0
def test_ticket_format(tmp_path):
    storage = FlatStorage('flat', tmp_path)
    ticket = storage.generate_ticket()
    assert len(ticket) == 16
    assert re.match(r'[^\w\-]', ticket) is None

    storage.id_size = 10
    ticket = storage.generate_ticket()
    assert len(ticket) == 10
    assert re.match(r'[^\w\-]', ticket) is None
Example #6
0
def test_delete(test_file, tmp_path):
    storage = FlatStorage('flat', tmp_path)
    storage_info = storage.store(test_file)
    storage.delete(storage_info['ticket'])

    with pytest.raises(FileNotFoundError):
        storage.delete(storage_info['ticket'])
Example #7
0
def test_store_get_retrieve_delete(test_file, tmp_path):
    center = StorageCenter()
    flat = FlatStorage('somewhere', tmp_path)
    center.register(flat)

    info = center.store('somewhere', test_file)
    assert isinstance(info, dict)

    test_file.seek(0)
    fiter = center[info]
    assert b''.join(fiter) == test_file.read()

    test_file.seek(0)
    fiter = center.retrieve('somewhere', info['ticket'])
    assert b''.join(fiter) == test_file.read()

    del center[info]
    with pytest.raises(FileNotFoundError):
        center.retrieve('somewhere', info['ticket'])
Example #8
0
def test_ticket(tmp_path):
    storage = FlatStorage('flat', tmp_path)
    ticket = storage.generate_ticket()
    assert ticket == 'my_tiny_id'
    path = storage.ticket_to_uri(ticket)
    assert path == tmp_path / ticket