Beispiel #1
0
def test_path_parent_slash(initial_pwd_non_root):
    path = '../'
    named_path = ['/', 'folder_a', 'folder_b']
    id_path = ['root', 'folder_a_id', 'folder_b_id']
    expected_item = gditem.GDItem.folder(named_path, id_path)
    items = gdpath.items_from_path(path)
    assert len(items) == 1
    assert items[0] == expected_item
Beispiel #2
0
def test_path_mixing_parents_and_dots(initial_pwd_non_root):
    path = './.././../.'
    named_path = ['/', 'folder_a']
    id_path = ['root', 'folder_a_id']
    expected_item = gditem.GDItem.folder(named_path, id_path)
    items = gdpath.items_from_path(path)
    assert len(items) == 1
    assert items[0] == expected_item
Beispiel #3
0
def assert_expected_results(contents, path, expected_items, monkeypatch):
    """ given the contents to be return by the GD API and
        the path to query and
        the expected items to be found, it
        asserts that the items found in GD for this path are the expected ones
    """
    fake_get_items_by_name = utiltests.build_mock_get(contents)
    monkeypatch.setattr(gdcore, 'get_items_by_name', fake_get_items_by_name)

    items = gdpath.items_from_path(path)
    assert items == expected_items
Beispiel #4
0
def test_path_non_existing_absolute_item_from_non_root(monkeypatch,
                                                       initial_pwd_non_root):
    path = '/nonexistentfile'
    contents = [[]]
    fake_get_items_by_name = utiltests.build_mock_get(
        contents,
        expected_args=('nonexistentfile', ),
        expected_kwargs={'folder': gditem.GDItem.root()})
    monkeypatch.setattr(gdcore, 'get_items_by_name', fake_get_items_by_name)
    items = gdpath.items_from_path(path)
    assert not items
Beispiel #5
0
def test_path_slash_existent_folder_from_root(monkeypatch, initial_pwd_root):
    path = '/folder1'
    named_path = ['/', 'folder1']
    id_path = ['root', 'folder1id']
    contents = [[gditem.GDItem.folder(named_path, id_path)]]
    fake_get_items_by_name = utiltests.build_mock_get(contents)
    monkeypatch.setattr(gdcore, 'get_items_by_name', fake_get_items_by_name)
    expected_item = gditem.GDItem.folder(['/', 'folder1'],
                                         ['root', 'folder1id'])
    items = gdpath.items_from_path(path)
    assert len(items) == 1
    assert items[0] == expected_item
Beispiel #6
0
def get_files(path):
    """ gets the files in the corresponding path.
        If path corresponds to a folder, it will return its contents.
        @param path: the path to the files to be listed
        @return: a list[GDItem] the list of items found matching requirements
        """
    found = []
    items = gdpath.items_from_path(path)
    for item in items:
        if item.is_folder():
            found += gdcore.get_items_by_folder(item)
        else:
            found.append(item)
    return found
Beispiel #7
0
def test_path_non_existing_relative_item_from_non_root(monkeypatch,
                                                       initial_pwd_non_root):
    path = 'nonexistentfile'
    contents = [[]]
    named_path = ['/', 'folder_a', 'folder_b', 'folder_c']
    id_path = ['root', 'folder_a_id', 'folder_b_id', 'folder_c_id']
    expected_folder = gditem.GDItem.folder(named_path, id_path)
    fake_get_items_by_name = utiltests.build_mock_get(
        contents,
        expected_args=('nonexistentfile', ),
        expected_kwargs={'folder': expected_folder})
    monkeypatch.setattr(gdcore, 'get_items_by_name', fake_get_items_by_name)
    items = gdpath.items_from_path(path)
    assert not items
Beispiel #8
0
def test_path_slash_parent(initial_pwd_non_root):
    path = '/..'
    expected_item = gditem.GDItem.root()
    items = gdpath.items_from_path(path)
    assert len(items) == 1
    assert items[0] == expected_item