def test_get_tool__invalid(self): """Tool and redirect don't match""" tool_example = Tool(name="foo", version="1.0.0", license=License("apache-2.0"), repository="www.google.com", description="foobar", author="Bob", author_email="*****@*****.**", url="www.google.com", type=ToolType("nlpsandbox:date-annotator"), api_version="1.0.0") with self.config as config,\ self.api_client as api_client,\ patch.object(tool_api, "ToolApi", return_value=self.mock_api) as resource_api,\ patch.object(self.mock_api, "get_tool", return_value=tool_example) as get_tool,\ patch.object(client, "_get_tool_redirect", return_value={}),\ pytest.raises(ValueError, match="Tool base URL must redirect*"): api_client.return_value = api_client api_client.__enter__ = Mock(return_value=self.api) api_client.__exit__ = Mock(return_value=None) tool = client.get_tool(host=self.host)
def test_get_tool(self): """Get tool""" tool_example = Tool(name="foo", version="1.0.0", license=License("apache-2.0"), repository="www.google.com", description="foobar", author="Bob", author_email="*****@*****.**", url="www.google.com", type=ToolType("nlpsandbox:date-annotator"), api_version="1.0.0") with self.config as config,\ self.api_client as api_client,\ patch.object(tool_api, "ToolApi", return_value=self.mock_api) as resource_api,\ patch.object(self.mock_api, "get_tool", return_value=tool_example) as get_tool,\ patch.object(client, "_get_tool_redirect", return_value=tool_example.to_dict()): api_client.return_value = api_client api_client.__enter__ = Mock(return_value=self.api) api_client.__exit__ = Mock(return_value=None) tool = client.get_tool(host=self.host) assert tool == tool_example
def get_tool_dependencies(): # noqa: E501 """Get tool dependencies Get the dependencies of this tool # noqa: E501 :rtype: ToolDependencies """ config = Config() tool_dependencies = [] for hostname in ( config.date_annotator_api_url, config.person_name_annotator_api_url, config.physical_address_annotator_api_url, config.contact_annotator_api_url, config.id_annotator_api_url, ): client_tool = client.get_tool(host=hostname) tool = Tool.from_dict({ client_tool.attribute_map[key]: value for key, value in client_tool.to_dict().items() }) tool_dependencies.append(tool) return ToolDependencies(tools=tool_dependencies)
def get_tool(annotator_host, output): """Get tool information""" tool = client.get_tool(host=annotator_host) utils.stdout_or_json(tool.to_dict(), output)