diff --git a/swh/graphql/app.py b/swh/graphql/app.py --- a/swh/graphql/app.py +++ b/swh/graphql/app.py @@ -28,11 +28,14 @@ resolvers.snapshot_branch, resolvers.revision, resolvers.release, + resolvers.release_target, resolvers.directory, resolvers.directory_entry, + resolvers.directory_entry_target, + resolvers.directory_entry_target_node, resolvers.search_result, resolvers.branch_target, - resolvers.release_target, + resolvers.release_target_node, resolvers.directory_entry_target, resolvers.search_result_target, resolvers.binary_string, diff --git a/swh/graphql/resolvers/content.py b/swh/graphql/resolvers/content.py --- a/swh/graphql/resolvers/content.py +++ b/swh/graphql/resolvers/content.py @@ -3,13 +3,8 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -from typing import Union - from .base_node import BaseSWHNode -from .directory_entry import BaseDirectoryEntryNode -from .release import BaseReleaseNode -from .search import SearchResultNode -from .snapshot_branch import BaseSnapshotBranchNode +from .target import TargetNode class BaseContentNode(BaseSWHNode): @@ -88,12 +83,7 @@ """ _can_be_null = True - obj: Union[ - SearchResultNode, - BaseDirectoryEntryNode, - BaseReleaseNode, - BaseSnapshotBranchNode, - ] + obj: TargetNode def _get_node_data(self): - return self._get_content_by_hashes(hashes={"sha1_git": self.obj.target_hash}) + return self._get_content_by_hashes(hashes={"sha1_git": self.obj.target_id}) diff --git a/swh/graphql/resolvers/directory.py b/swh/graphql/resolvers/directory.py --- a/swh/graphql/resolvers/directory.py +++ b/swh/graphql/resolvers/directory.py @@ -3,16 +3,12 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -from typing import Union - from swh.model.model import Directory from swh.model.swhids import ObjectType from .base_node import BaseSWHNode -from .release import BaseReleaseNode from .revision import BaseRevisionNode -from .search import SearchResultNode -from .snapshot_branch import BaseSnapshotBranchNode +from .target import TargetNode class BaseDirectoryNode(BaseSWHNode): @@ -68,12 +64,7 @@ from .directory_entry import BaseDirectoryEntryNode _can_be_null = True - obj: Union[ - BaseSnapshotBranchNode, - BaseReleaseNode, - BaseDirectoryEntryNode, - SearchResultNode, - ] + obj: TargetNode def _get_node_data(self): - return self._get_directory_by_id(self.obj.target_hash) + return self._get_directory_by_id(self.obj.target_id) diff --git a/swh/graphql/resolvers/directory_entry.py b/swh/graphql/resolvers/directory_entry.py --- a/swh/graphql/resolvers/directory_entry.py +++ b/swh/graphql/resolvers/directory_entry.py @@ -12,11 +12,11 @@ class BaseDirectoryEntryNode(BaseNode): @property - def target_hash(self): # for DirectoryNode + def target_id(self): return self._node.target @property - def targetType(self): # To support the schema naming convention + def target_type(self): mapping = {"file": "content", "dir": "directory", "rev": "revision"} return mapping.get(self._node.type) diff --git a/swh/graphql/resolvers/release.py b/swh/graphql/resolvers/release.py --- a/swh/graphql/resolvers/release.py +++ b/swh/graphql/resolvers/release.py @@ -3,11 +3,8 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -from typing import Union - from .base_node import BaseSWHNode -from .search import SearchResultNode -from .snapshot_branch import BaseSnapshotBranchNode +from .target import TargetNode class BaseReleaseNode(BaseSWHNode): @@ -19,11 +16,11 @@ return self.archive.get_releases([release_id])[0] @property - def target_hash(self): + def target_id(self): return self._node.target @property - def targetType(self): # To support the schema naming convention + def target_type(self): return self._node.target_type.value def is_type_of(self): @@ -47,8 +44,7 @@ """ _can_be_null = True - obj: Union[BaseSnapshotBranchNode, BaseReleaseNode, SearchResultNode] + obj: TargetNode def _get_node_data(self): - # self.obj.target_hash is the requested release id - return self._get_release_by_id(self.obj.target_hash) + return self._get_release_by_id(self.obj.target_id) diff --git a/swh/graphql/resolvers/resolver_factory.py b/swh/graphql/resolvers/resolver_factory.py --- a/swh/graphql/resolvers/resolver_factory.py +++ b/swh/graphql/resolvers/resolver_factory.py @@ -28,6 +28,7 @@ VisitSnapshotNode, ) from .snapshot_branch import AliasSnapshotBranchNode, SnapshotBranchConnection +from .target import TargetNode from .visit import LatestVisitNode, OriginVisitConnection, OriginVisitNode from .visit_status import LatestVisitStatusNode, VisitStatusConnection @@ -49,23 +50,22 @@ "revision": RevisionNode, "revision-directory": RevisionDirectoryNode, "release": ReleaseNode, - "release-revision": TargetRevisionNode, - "release-release": TargetReleaseNode, - "release-directory": TargetDirectoryNode, - "release-content": TargetContentNode, "directory": DirectoryNode, "directory-entry": DirectoryEntryNode, "content": ContentNode, "content-by-hash": HashContentNode, - "dir-entry-content": TargetContentNode, - "dir-entry-directory": TargetDirectoryNode, - "dir-entry-revision": TargetRevisionNode, "search-result-origin": TargetOriginNode, "search-result-snapshot": TargetSnapshotNode, "search-result-revision": TargetRevisionNode, "search-result-release": TargetReleaseNode, "search-result-directory": TargetDirectoryNode, "search-result-content": TargetContentNode, + "target": TargetNode, + "target-revision": TargetRevisionNode, + "target-release": TargetReleaseNode, + "target-snapshot": TargetSnapshotNode, + "target-directory": TargetDirectoryNode, + "target-content": TargetContentNode, } @classmethod diff --git a/swh/graphql/resolvers/resolvers.py b/swh/graphql/resolvers/resolvers.py --- a/swh/graphql/resolvers/resolvers.py +++ b/swh/graphql/resolvers/resolvers.py @@ -34,14 +34,16 @@ snapshot_branch: ObjectType = ObjectType("Branch") revision: ObjectType = ObjectType("Revision") release: ObjectType = ObjectType("Release") +release_target: ObjectType = ObjectType("ReleaseTarget") directory: ObjectType = ObjectType("Directory") directory_entry: ObjectType = ObjectType("DirectoryEntry") +directory_entry_target: ObjectType = ObjectType("DirectoryEntryTarget") search_result: ObjectType = ObjectType("SearchResult") binary_string: ObjectType = ObjectType("BinaryString") branch_target: UnionType = UnionType("BranchTarget") -release_target: UnionType = UnionType("ReleaseTarget") -directory_entry_target: UnionType = UnionType("DirectoryEntryTarget") +release_target_node: UnionType = UnionType("ReleaseTargetNode") +directory_entry_target_node: UnionType = UnionType("DirectoryEntryTargetNode") search_result_target: UnionType = UnionType("SearchResultTarget") # Node resolvers @@ -127,21 +129,6 @@ return NodeObjectFactory.create("release", obj, info, **kw) -@release.field("target") -def release_target_resolver( - obj: rs.release.BaseReleaseNode, info: GraphQLResolveInfo, **kw -) -> Union[ - rs.revision.BaseRevisionNode, - rs.release.BaseReleaseNode, - rs.directory.BaseDirectoryNode, - rs.content.BaseContentNode, -]: - """ - Release target can be a release, revision, directory or a content - """ - return NodeObjectFactory.create(f"release-{obj.targetType}", obj, info, **kw) - - @query.field("directory") def directory_resolver( obj: None, info: GraphQLResolveInfo, **kw @@ -156,20 +143,6 @@ return NodeObjectFactory.create("directory-entry", obj, info, **kw) -@directory_entry.field("target") -def directory_entry_target_resolver( - obj: rs.directory_entry.BaseDirectoryEntryNode, info: GraphQLResolveInfo, **kw -) -> Union[ - rs.revision.BaseRevisionNode, - rs.directory.BaseDirectoryNode, - rs.content.BaseContentNode, -]: - """ - DirectoryEntry target can be a directory, content or a revision - """ - return NodeObjectFactory.create(f"dir-entry-{obj.targetType}", obj, info, **kw) - - @query.field("content") def content_resolver( obj: None, info: GraphQLResolveInfo, **kw @@ -202,6 +175,29 @@ return NodeObjectFactory.create("content-by-hash", obj, info, **kw) +@directory_entry.field("target") +@release.field("target") +def generic_target_resolver( + obj: Union[rs.release.BaseReleaseNode, rs.directory_entry.BaseDirectoryEntryNode], + info: GraphQLResolveInfo, + **kw, +) -> rs.target.TargetNode: + return NodeObjectFactory.create("target", obj, info, **kw) + + +@directory_entry_target.field("node") +@release_target.field("node") +def target_node_resolver( + obj: rs.target.TargetNode, info: GraphQLResolveInfo, **kw +) -> Union[ + rs.revision.BaseRevisionNode, + rs.release.BaseReleaseNode, + rs.directory.BaseDirectoryNode, + rs.content.BaseContentNode, +]: + return NodeObjectFactory.create(f"target-{obj.type}", obj, info, **kw) + + # Connection resolvers # A connection resolver should return an instance of BaseConnection @@ -279,8 +275,8 @@ # Other resolvers -@release_target.type_resolver -@directory_entry_target.type_resolver +@release_target_node.type_resolver +@directory_entry_target_node.type_resolver @branch_target.type_resolver @search_result_target.type_resolver def union_resolver( diff --git a/swh/graphql/resolvers/revision.py b/swh/graphql/resolvers/revision.py --- a/swh/graphql/resolvers/revision.py +++ b/swh/graphql/resolvers/revision.py @@ -3,7 +3,7 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -from typing import Union +# from typing import Union from swh.graphql.utils import utils from swh.model.model import Revision @@ -12,10 +12,7 @@ from .base_connection import BaseConnection from .base_node import BaseSWHNode -from .directory_entry import BaseDirectoryEntryNode -from .release import BaseReleaseNode -from .search import SearchResultNode -from .snapshot_branch import BaseSnapshotBranchNode +from .target import TargetNode class BaseRevisionNode(BaseSWHNode): @@ -62,16 +59,10 @@ """ _can_be_null = True - obj: Union[ - BaseSnapshotBranchNode, - BaseReleaseNode, - BaseDirectoryEntryNode, - SearchResultNode, - ] + obj: TargetNode def _get_node_data(self): - # self.obj.target_hash is the requested revision id - return self._get_revision_by_id(self.obj.target_hash) + return self._get_revision_by_id(self.obj.target_id) class ParentRevisionConnection(BaseConnection): diff --git a/swh/graphql/resolvers/search.py b/swh/graphql/resolvers/search.py --- a/swh/graphql/resolvers/search.py +++ b/swh/graphql/resolvers/search.py @@ -27,7 +27,7 @@ if self.archive.is_object_available(swhid.object_id, swhid.object_type): results = [ { - "target_hash": swhid.object_id, + "target_id": swhid.object_id, "type": swhid.object_type.name.lower(), } ] diff --git a/swh/graphql/resolvers/snapshot.py b/swh/graphql/resolvers/snapshot.py --- a/swh/graphql/resolvers/snapshot.py +++ b/swh/graphql/resolvers/snapshot.py @@ -77,7 +77,7 @@ obj: Union[SearchResultNode, BaseSnapshotBranchNode] def _get_node_data(self): - snapshot_id = self.obj.target_hash + snapshot_id = self.obj.target_id return self._get_snapshot_by_id(snapshot_id) diff --git a/swh/graphql/resolvers/snapshot_branch.py b/swh/graphql/resolvers/snapshot_branch.py --- a/swh/graphql/resolvers/snapshot_branch.py +++ b/swh/graphql/resolvers/snapshot_branch.py @@ -25,8 +25,8 @@ branch_name, branch_obj = node_data node = { "name": branch_name, - "type": branch_obj.target_type.value, - "target_hash": branch_obj.target, + "target_type": branch_obj.target_type.value, + "target_id": branch_obj.target, } return namedtuple("NodeObj", node.keys())(*node.values()) @@ -35,7 +35,7 @@ @property def targetType(self): # To support the schema naming convention - return self._node.type + return self._node.target_type def snapshot_swhid(self): """ @@ -65,7 +65,7 @@ def _get_node_data(self): snapshot_swhid = self.snapshot_swhid() - target_branch = self.obj.target_hash + target_branch = self.obj.target_id alias_branch = self.archive.get_snapshot_branches( snapshot_swhid.object_id, first=1, name_include=target_branch diff --git a/swh/graphql/resolvers/target.py b/swh/graphql/resolvers/target.py new file mode 100644 --- /dev/null +++ b/swh/graphql/resolvers/target.py @@ -0,0 +1,39 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Union + +from .base_node import BaseNode + +# from swh.model.swhids import CoreSWHID, ObjectType + + +if TYPE_CHECKING: + from .directory_entry import BaseDirectoryEntryNode + from .release import BaseReleaseNode + + +class TargetNode(BaseNode): + + obj: Union[BaseReleaseNode, BaseDirectoryEntryNode] + + # def _get_target_swhid(self, target_type: str, target_id): + # mapping = { + # "revision": ObjectType.REVISION, + # "release": ObjectType.RELEASE, + # "snapshot": ObjectType.SNAPSHOT, + # "directory": ObjectType.DIRECTORY, + # "content": ObjectType.CONTENT, + # } + # return CoreSWHID(object_type=mapping[target_type], object_id=target_id) + + def _get_node_data(self): + # node field of a target object is resolved in the top level resolver + return { + # field exposed in the schema + "type": self.obj.target_type, + # field exposed in the schema, the same field is used to + # get the node object + "identifier": self.obj.target_id, + # field NOT exposed in schema, used to get the target object + "target_id": self.obj.target_id, + } diff --git a/swh/graphql/schema/schema.graphql b/swh/graphql/schema/schema.graphql --- a/swh/graphql/schema/schema.graphql +++ b/swh/graphql/schema/schema.graphql @@ -639,21 +639,6 @@ ): RevisionConnection } -""" -Possible release target objects -""" -union ReleaseTarget = Release | Revision | Directory | Content - -""" -Possible release target types -""" -enum ReleaseTargetType { - release - revision - content - directory -} - """ A release object """ @@ -689,14 +674,44 @@ date: DateTime """ - Type of release target + Release target node """ - targetType: ReleaseTargetType + target: ReleaseTarget +} +""" +Possible release target types +""" +enum ReleaseTargetType { + release + revision + content + directory +} + +""" +Possible release target nodes +""" +union ReleaseTargetNode = Release | Revision | Directory | Content + +""" +A release target object +""" +type ReleaseTarget { """ - Release target object + Release target type """ - target: ReleaseTarget + type: ReleaseTargetType! + + """ + Release target identifier + """ + identifier: ID! + + """ + Release target SWH object + """ + node: ReleaseTargetNode } """ @@ -739,10 +754,26 @@ node: DirectoryEntry } + +""" +A directory entry object +""" +type DirectoryEntry { + """ + The directory entry name + """ + name: BinaryString + + """ + Directory entry target node + """ + target: DirectoryEntryTarget +} + """ Possible directory entry target objects """ -union DirectoryEntryTarget = Directory | Content | Revision +union DirectoryEntryTargetNode = Directory | Content | Revision """ Possible directory entry types @@ -754,25 +785,26 @@ } """ -A directory entry object +A directoryentry target object """ -type DirectoryEntry { +type DirectoryEntryTarget { """ - The directory entry name + Directoryentry target type """ - name: BinaryString + type: DirectoryEntryTargetType! """ - Directory entry object type; can be file, dir or rev + Directoryentry target SWHID """ - targetType: DirectoryEntryTargetType + identifier: ID! """ - Directory entry target object + Directoryentry target SWH object """ - target: DirectoryEntryTarget + node: DirectoryEntryTargetNode } + """ A directory object """ @@ -944,8 +976,9 @@ node: SearchResult } -union SearchResultTarget = Origin | Revision | Release | Content | Directory | Snapshot - +""" +Possible search result target types +""" enum SearchResultTargetType { origin revision @@ -955,6 +988,11 @@ snapshot } +""" +Possible search result target nodes +""" +union SearchResultTarget = Origin | Revision | Release | Content | Directory | Snapshot + """ A SearchResult object """ diff --git a/swh/graphql/tests/functional/test_content.py b/swh/graphql/tests/functional/test_content.py --- a/swh/graphql/tests/functional/test_content.py +++ b/swh/graphql/tests/functional/test_content.py @@ -148,11 +148,14 @@ swhid entries(first: 2) { nodes { - targetType target { - ...on Content { - swhid - length + type + identifier + node { + ...on Content { + swhid + length + } } } } @@ -163,8 +166,12 @@ data, _ = utils.get_query_response(client, query_str, swhid=directory_swhid) content_obj = data["directory"]["entries"]["nodes"][1]["target"] assert content_obj == { - "length": 4, - "swhid": "swh:1:cnt:86bc6b377e9d25f9d26777a4a28d08e63e7c5779", + "type": "content", + "identifier": "86bc6b377e9d25f9d26777a4a28d08e63e7c5779", + "node": { + "length": 4, + "swhid": "swh:1:cnt:86bc6b377e9d25f9d26777a4a28d08e63e7c5779", + }, } diff --git a/swh/graphql/tests/functional/test_directory.py b/swh/graphql/tests/functional/test_directory.py --- a/swh/graphql/tests/functional/test_directory.py +++ b/swh/graphql/tests/functional/test_directory.py @@ -65,8 +65,10 @@ release(swhid: $swhid) { swhid target { - ...on Directory { - swhid + node { + ...on Directory { + swhid + } } } } @@ -77,7 +79,7 @@ query_str, swhid="swh:1:rel:ee4d20e80af850cc0f417d25dc5073792c5010d2", ) - assert data["release"]["target"] == { + assert data["release"]["target"]["node"] == { "swhid": "swh:1:dir:0505050505050505050505050505050505050505" } diff --git a/swh/graphql/tests/functional/test_directory_entry.py b/swh/graphql/tests/functional/test_directory_entry.py --- a/swh/graphql/tests/functional/test_directory_entry.py +++ b/swh/graphql/tests/functional/test_directory_entry.py @@ -30,10 +30,13 @@ name { text } - targetType target { - ...on Content { - swhid + type + identifier + node { + ...on Content { + swhid + } } } } @@ -59,16 +62,18 @@ name { text } - targetType target { - ...on Content { - swhid - } - ...on Directory { - swhid - } - ...on Revision { - swhid + type + node { + ...on Content { + swhid + } + ...on Directory { + swhid + } + ...on Revision { + swhid + } } } } @@ -96,8 +101,12 @@ ) assert data["directoryEntry"] == { "name": {"text": entry["name"].decode()}, - "target": {"swhid": str(swhid)} if swhid else None, - "targetType": get_target_type(entry["type"]), + "target": { + "type": get_target_type(entry["type"]), + "node": {"swhid": str(swhid)}, + } + if swhid + else {"type": get_target_type(entry["type"]), "node": None}, } @@ -109,10 +118,12 @@ swhid entries { nodes { - targetType name { text } + target { + type + } } } } @@ -122,7 +133,10 @@ directory_entries = data["directory"]["entries"]["nodes"] assert len(directory_entries) == len(directory.entries) output = [ - {"name": {"text": de.name.decode()}, "targetType": get_target_type(de.type)} + { + "name": {"text": de.name.decode()}, + "target": {"type": get_target_type(de.type)}, + } for de in directory.entries ] for each_entry in output: @@ -140,10 +154,12 @@ swhid entries(nameInclude: $nameInclude) { nodes { - targetType name { text } + target { + type + } } } } @@ -157,7 +173,7 @@ ) for entry in data["directory"]["entries"]["nodes"]: assert name_include in entry["name"]["text"] - assert entry["targetType"] == get_target_type(dir_entry["type"]) + assert entry["target"]["type"] == get_target_type(dir_entry["type"]) def test_directory_entry_connection_filter_by_name_special_chars(client): @@ -167,7 +183,6 @@ directory(swhid: $swhid) { entries(nameInclude: $nameInclude) { nodes { - targetType name { text } @@ -184,5 +199,4 @@ ) assert data["directory"]["entries"]["nodes"][0] == { "name": {"text": "ßßétEÉt"}, - "targetType": "content", } diff --git a/swh/graphql/tests/functional/test_release_node.py b/swh/graphql/tests/functional/test_release_node.py --- a/swh/graphql/tests/functional/test_release_node.py +++ b/swh/graphql/tests/functional/test_release_node.py @@ -44,7 +44,9 @@ } } date - targetType + target { + type + } } } """ @@ -65,7 +67,9 @@ if release.author else None, "date": release.date.to_datetime().isoformat() if release.date else None, - "targetType": release.target_type.value, + "target": { + "type": release.target_type.value, + }, } @@ -88,19 +92,21 @@ query_str = """ query getRelease($swhid: SWHID!) { release(swhid: $swhid) { - targetType target { - ...on Revision { - swhid - } - ...on Release { - swhid - } - ...on Directory { - swhid - } - ...on Content { - swhid + type + node { + ...on Revision { + swhid + } + ...on Release { + swhid + } + ...on Directory { + swhid + } + ...on Content { + swhid + } } } } @@ -111,16 +117,19 @@ ) if release_with_target.target_type == ObjectType.REVISION: - target_swhid = get_revisions()[0].swhid() + target = get_revisions()[0] elif release_with_target.target_type == ObjectType.RELEASE: - target_swhid = get_releases()[0].swhid() + target = get_releases()[0] elif release_with_target.target_type == ObjectType.DIRECTORY: - target_swhid = get_directories()[0].swhid() + target = get_directories()[0] elif release_with_target.target_type == ObjectType.CONTENT: - target_swhid = get_contents()[0].swhid() + target = get_contents()[0] assert data["release"] == { - "targetType": release_with_target.target_type.value, - "target": {"swhid": str(target_swhid)}, + "target": { + "type": release_with_target.target_type.value, + # "identifier": target.id.hex(), + "node": {"swhid": str(target.swhid())}, + }, } @@ -134,22 +143,25 @@ query_str = """ query getRelease($swhid: SWHID!) { release(swhid: $swhid) { - targetType target { - ...on Revision { - swhid - message { - text + type + identifier + node { + ...on Revision { + swhid + message { + text + } + } + ...on Release { + swhid + } + ...on Directory { + swhid + } + ...on Content { + swhid } - } - ...on Release { - swhid - } - ...on Directory { - swhid - } - ...on Content { - swhid } } } @@ -158,10 +170,13 @@ data, _ = utils.get_query_response(client, query_str, swhid=str(swhid)) assert data["release"] == { "target": { - "message": {"text": "hello"}, - "swhid": str(get_revisions()[0].swhid()), + "type": "revision", + "identifier": get_revisions()[0].id.hex(), + "node": { + "message": {"text": "hello"}, + "swhid": str(get_revisions()[0].swhid()), + }, }, - "targetType": "revision", } diff --git a/swh/graphql/tests/unit/resolvers/test_resolvers.py b/swh/graphql/tests/unit/resolvers/test_resolvers.py --- a/swh/graphql/tests/unit/resolvers/test_resolvers.py +++ b/swh/graphql/tests/unit/resolvers/test_resolvers.py @@ -65,58 +65,6 @@ # assert the right object is returned assert isinstance(connection_obj, connection_cls) - @pytest.mark.parametrize( - "branch_type, node_cls", - [ - ("revision", resolvers.revision.TargetRevisionNode), - ("release", resolvers.release.TargetReleaseNode), - ("directory", resolvers.directory.TargetDirectoryNode), - ("content", resolvers.content.TargetContentNode), - ("snapshot", resolvers.snapshot.TargetSnapshotNode), - ], - ) - def test_snapshot_branch_target_resolver( - self, mocker, dummy_node, branch_type, node_cls - ): - obj = mocker.Mock(targetType=branch_type) - mock_get = mocker.patch.object(node_cls, "_get_node", return_value=dummy_node) - node_obj = rs.snapshot_branch_target_resolver(obj, None) - assert isinstance(node_obj, node_cls) - assert mock_get.assert_called - - @pytest.mark.parametrize( - "target_type, node_cls", - [ - ("revision", resolvers.revision.TargetRevisionNode), - ("release", resolvers.release.TargetReleaseNode), - ("directory", resolvers.directory.TargetDirectoryNode), - ("content", resolvers.content.TargetContentNode), - ], - ) - def test_release_target_resolver(self, mocker, dummy_node, target_type, node_cls): - obj = mocker.Mock(targetType=target_type) - mock_get = mocker.patch.object(node_cls, "_get_node", return_value=dummy_node) - node_obj = rs.release_target_resolver(obj, None) - assert isinstance(node_obj, node_cls) - assert mock_get.assert_called - - @pytest.mark.parametrize( - "target_type, node_cls", - [ - ("directory", resolvers.directory.TargetDirectoryNode), - ("content", resolvers.content.TargetContentNode), - ("revision", resolvers.revision.TargetRevisionNode), - ], - ) - def test_directory_entry_target_resolver( - self, mocker, dummy_node, target_type, node_cls - ): - obj = mocker.Mock(targetType=target_type) - mock_get = mocker.patch.object(node_cls, "_get_node", return_value=dummy_node) - node_obj = rs.directory_entry_target_resolver(obj, None) - assert isinstance(node_obj, node_cls) - assert mock_get.assert_called - def test_union_resolver(self, mocker): obj = mocker.Mock() obj.is_type_of.return_value = "test"