Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/tests/functional/test_directory_entry.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import pytest | import pytest | ||||
from swh.graphql import server | from swh.graphql import server | ||||
from swh.model.swhids import CoreSWHID, ObjectType | from swh.model.swhids import CoreSWHID, ObjectType | ||||
from . import utils | from . import utils | ||||
from ..data import get_directories, get_directories_with_nested_path | from ..data import ( | ||||
get_directories, | |||||
get_directories_with_nested_path, | |||||
get_directories_with_special_name_entries, | |||||
) | |||||
def get_target_type(target_type): | def get_target_type(target_type): | ||||
mapping = {"file": "content", "dir": "directory", "rev": "revision"} | mapping = {"file": "content", "dir": "directory", "rev": "revision"} | ||||
return mapping.get(target_type) | return mapping.get(target_type) | ||||
def test_get_directory_entry_missing_path(client): | def test_get_directory_entry_missing_path(client): | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | for dir_entry in storage.directory_ls(directory.id): | ||||
client, | client, | ||||
query_str, | query_str, | ||||
swhid=str(directory.swhid()), | swhid=str(directory.swhid()), | ||||
nameInclude=name_include, | nameInclude=name_include, | ||||
) | ) | ||||
for entry in data["directory"]["entries"]["nodes"]: | for entry in data["directory"]["entries"]["nodes"]: | ||||
assert name_include in entry["name"]["text"] | assert name_include in entry["name"]["text"] | ||||
assert entry["targetType"] == get_target_type(dir_entry["type"]) | assert entry["targetType"] == get_target_type(dir_entry["type"]) | ||||
def test_directory_entry_connection_filter_by_name_special_chars(client): | |||||
directory = get_directories_with_special_name_entries()[0] | |||||
query_str = """ | |||||
query getDirectory($swhid: SWHID!, $nameInclude: String) { | |||||
directory(swhid: $swhid) { | |||||
entries(nameInclude: $nameInclude) { | |||||
nodes { | |||||
targetType | |||||
name { | |||||
text | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
""" | |||||
data, _ = utils.get_query_response( | |||||
client, | |||||
query_str, | |||||
swhid=str(directory.swhid()), | |||||
nameInclude="ssSSé", | |||||
) | |||||
assert data["directory"]["entries"]["nodes"][0] == { | |||||
"name": {"text": "ßßétEÉt"}, | |||||
"targetType": "content", | |||||
} |