# Path: invenio_files_rest/helpers.py
# def make_path(base_uri, path, filename, path_dimensions, split_length):
#     """Generate a path as base location for file instance.
# 
#     :param base_uri: The base URI.
#     :param path: The relative path.
#     :param path_dimensions: Number of chunks the path should be split into.
#     :param split_length: The length of any chunk.
#     :returns: A string representing the full path.
#     """
#     assert len(path) > path_dimensions * split_length
# 
#     uri_parts = []
#     for i in range(path_dimensions):
#         uri_parts.append(path[0:split_length])
#         path = path[split_length:]
#     uri_parts.append(path)
#     uri_parts.append(filename)
# 
#     return os.path.join(base_uri, *uri_parts)


import pytest
from invenio_files_rest.helpers import make_path
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2015-2019 CERN.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Storage module tests."""




def test_make_path():
    """Test path for files."""
    myid = 'deadbeef-dead-dead-dead-deaddeafbeef'
    base = '/base'
    f = 'data'

    assert make_path(base, myid, f, 1, 1) == \
        '/base/d/eadbeef-dead-dead-dead-deaddeafbeef/data'
    assert make_path(base, myid, f, 3, 1) == \
        '/base/d/e/a/dbeef-dead-dead-dead-deaddeafbeef/data'
    assert make_path(base, myid, f, 1, 3) == \
        '/base/dea/dbeef-dead-dead-dead-deaddeafbeef/data'
    assert make_path(base, myid, f, 2, 2) == \
        '/base/de/ad/beef-dead-dead-dead-deaddeafbeef/data'


# Path: invenio_files_rest/helpers.py
# def make_path(base_uri, path, filename, path_dimensions, split_length):
#     """Generate a path as base location for file instance.
# 
#     :param base_uri: The base URI.
#     :param path: The relative path.
#     :param path_dimensions: Number of chunks the path should be split into.
#     :param split_length: The length of any chunk.
#     :returns: A string representing the full path.
#     """
#     assert len(path) > path_dimensions * split_length
# 
#     uri_parts = []
#     for i in range(path_dimensions):
#         uri_parts.append(path[0:split_length])
#         path = path[split_length:]
#     uri_parts.append(path)
#     uri_parts.append(filename)
# 
#     return os.path.join(base_uri, *uri_parts)


# Path: tests/test_helpers.py
import pytest
from invenio_files_rest.helpers import make_path

# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2015-2019 CERN.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Storage module tests."""




def test_make_path():
    """Test path for files."""
    myid = 'deadbeef-dead-dead-dead-deaddeafbeef'
    base = '/base'
    f = 'data'

    assert make_path(base, myid, f, 1, 1) == \
        '/base/d/eadbeef-dead-dead-dead-deaddeafbeef/data'
    assert make_path(base, myid, f, 3, 1) == \
        '/base/d/e/a/dbeef-dead-dead-dead-deaddeafbeef/data'
    assert make_path(base, myid, f, 1, 3) == \
        '/base/dea/dbeef-dead-dead-dead-deaddeafbeef/data'
    assert make_path(base, myid, f, 2, 2) == \
        '/base/de/ad/beef-dead-dead-dead-deaddeafbeef/data'


    pytest.raises(AssertionError, make_path, base, myid, f, 1, 50)