def test_search_single_node_with_not_exist_name(self):
        """Test searching single node with not exist name."""
        test_name = "not_exist_name"

        with pytest.raises(exceptions.NodeNotInGraphError):
            graph_processor = GraphProcessor(self._train_id, self._mock_data_manager)
            graph_processor.search_single_node(test_name)
    def test_get_nodes_success(self, name, result_file):
        """Test getting nodes successfully."""
        graph_processor = GraphProcessor(self._train_id, self._mock_data_manager)
        results = graph_processor.list_nodes(name)

        expected_file_path = os.path.join(self.graph_results_dir, result_file)
        compare_result_with_file(results, expected_file_path)
    def test_get_nodes_with_not_exist_name(self, name):
        """Test getting nodes with not exist name."""
        with pytest.raises(NodeNotInGraphError) as exc_info:
            graph_processor = GraphProcessor(self._train_id, self._mock_data_manager)
            graph_processor.list_nodes(name)

        assert 'Can not find node in graph by the given node name' in exc_info.value.message
    def test_search_single_node_success(self, name, result_file):
        """Test searching single node successfully."""

        graph_processor = GraphProcessor(self._train_id, self._mock_data_manager)
        results = graph_processor.search_single_node(name)
        expected_file_path = os.path.join(self.graph_results_dir, result_file)
        compare_result_with_file(results, expected_file_path)
    def test_get_nodes_success(self, load_graph_record, name, node_type,
                               result_file):
        """Test getting nodes successfully."""

        graph_processor = GraphProcessor(self._train_id,
                                         self._mock_data_manager)
        results = graph_processor.get_nodes(name, node_type)
        self.compare_result_with_file(results, result_file)
    def test_search_single_node_success(self, load_graph_record, name,
                                        result_file):
        """Test searching single node successfully."""

        graph_processor = GraphProcessor(self._train_id,
                                         self._mock_data_manager)
        results = graph_processor.search_single_node(name)
        self.compare_result_with_file(results, result_file)
    def test_search_node_names_with_negative_offset(self, offset):
        """Test search node names with negative offset."""
        test_search_content = ""
        test_limit = 3

        graph_processor = GraphProcessor(self._train_id, self._mock_data_manager)
        with pytest.raises(ParamValueError) as exc_info:
            graph_processor.search_node_names(test_search_content, offset, test_limit)
        assert "'offset' should be greater than or equal to 0." in exc_info.value.message
    def test_search_node_names_with_wrong_limit(self):
        """Test search node names with wrong limit."""
        test_search_content = ""
        test_offset = 0
        test_limit = 0

        graph_processor = GraphProcessor(self._train_id, self._mock_data_manager)
        with pytest.raises(ParamValueError) as exc_info:
            graph_processor.search_node_names(test_search_content, test_offset, test_limit)
        assert "'limit' should in [1, 1000]." in exc_info.value.message
    def test_search_node_names_with_offset(self, offset, result_file):
        """Test search node names with offset."""
        test_search_content = "Default/bn1"
        test_offset = offset
        test_limit = 1

        graph_processor = GraphProcessor(self._train_id, self._mock_data_manager)
        results = graph_processor.search_node_names(test_search_content, test_offset, test_limit)
        expected_file_path = os.path.join(self.graph_results_dir, result_file)
        compare_result_with_file(results, expected_file_path)
    def test_search_node_names_with_offset(self, load_graph_record, offset,
                                           result_file):
        """Test search node names with offset."""
        test_search_content = "Default/bn1"
        test_offset = offset
        test_limit = 3

        graph_processor = GraphProcessor(self._train_id,
                                         self._mock_data_manager)
        results = graph_processor.search_node_names(test_search_content,
                                                    test_offset, test_limit)
        self.compare_result_with_file(results, result_file)
    def test_get_nodes_with_not_exist_name(self, load_graph_record, name,
                                           node_type):
        """Test getting nodes with not exist name."""
        with pytest.raises(ParamValueError) as exc_info:
            graph_processor = GraphProcessor(self._train_id,
                                             self._mock_data_manager)
            graph_processor.get_nodes(name, node_type)

        if name:
            assert "The node name is not in graph." in exc_info.value.message
        else:
            assert f'The node name "{name}" not in graph, node type is {node_type}.' in exc_info.value.message
    def test_search_node_names_with_search_content(self, search_content, result_file):
        """Test search node names with search content."""
        test_offset = 0
        test_limit = 1000

        graph_processor = GraphProcessor(self._train_id, self._mock_data_manager)
        results = graph_processor.search_node_names(search_content, test_offset, test_limit)
        if search_content == 'not_exist_search_content':
            expected_results = {'nodes': []}
            assert results == expected_results
        else:
            expected_file_path = os.path.join(self.graph_results_dir, result_file)
            compare_result_with_file(results, expected_file_path)
Exemple #13
0
def graph_search_single_node():
    """
    Interface to search single node.

    Returns:
         Response, which contains a JSON object.
    """
    name = request.args.get("name")
    tag = request.args.get("tag", default=None)
    train_id = get_train_id(request)

    graph_process = GraphProcessor(train_id, DATA_MANAGER, tag)
    resp = graph_process.search_single_node(name)
    return jsonify(resp)
Exemple #14
0
def graph_nodes():
    """
    Interface to get graph nodes.

    Returns:
        Response, which contains a JSON object.

    """
    name = request.args.get('name', default=None)
    tag = request.args.get("tag", default=None)
    train_id = get_train_id(request)

    graph_process = GraphProcessor(train_id, DATA_MANAGER, tag)
    response = graph_process.list_nodes(scope=name)
    return jsonify(response)
    def test_check_graph_status_no_graph(self):
        """Test checking graph status no graph."""
        with pytest.raises(GraphNotExistError) as exc_info:
            GraphProcessor(self._train_id, self._mock_data_manager)

        assert exc_info.value.error_code == '5054500C'
        assert exc_info.value.message == "Graph is not exist."
Exemple #16
0
def graph_node_names():
    """
    Interface to query node names.

    Returns:
        Response, which contains a JSON object.
    """
    search_content = request.args.get("search")
    offset = request.args.get("offset", default=0)
    limit = request.args.get("limit", default=100)
    tag = request.args.get("tag", default=None)
    train_id = get_train_id(request)

    graph_process = GraphProcessor(train_id, DATA_MANAGER, tag)
    resp = graph_process.search_node_names(search_content, offset, limit)
    return jsonify(resp)
    def test_get_nodes_with_loader_is_none(self, mock_get_train_job_by_plugin):
        """Test get nodes with loader is None."""
        mock_get_train_job_by_plugin.return_value = None
        with pytest.raises(exceptions.TrainJobNotExistError):
            GraphProcessor(self._train_id, self._mock_data_manager)

        assert mock_get_train_job_by_plugin.called
    def test_get_nodes_with_loader_is_none(self, mock_get_train_job_by_plugin,
                                           load_graph_record):
        """Test get nodes with loader is None."""
        mock_get_train_job_by_plugin.return_value = None
        with pytest.raises(exceptions.SummaryLogPathInvalid):
            GraphProcessor(self._train_id, self._mock_data_manager)

        assert mock_get_train_job_by_plugin.called
 def test_get_nodes_with_not_exist_train_id(self, load_graph_record):
     """Test getting nodes with not exist train id."""
     test_train_id = "not_exist_train_id"
     with pytest.raises(ParamValueError) as exc_info:
         GraphProcessor(test_train_id, self._mock_data_manager)
     assert "Can not find the train job in data manager." in exc_info.value.message
 def test_check_graph_status_no_graph(self, load_no_graph_record):
     """Test checking graph status no graph."""
     with pytest.raises(ParamValueError) as exc_info:
         GraphProcessor(self._train_id, self._mock_data_manager)
     assert exc_info.value.message == "Invalid parameter value. Can not find any graph data " \
                                      "in the train job."
 def test_get_nodes_with_not_exist_train_id(self):
     """Test getting nodes with not exist train id."""
     test_train_id = "not_exist_train_id"
     with pytest.raises(exceptions.TrainJobNotExistError) as exc_info:
         GraphProcessor(test_train_id, self._mock_data_manager)
     assert exc_info.value.message == "Train job is not exist. Detail: Can not find the train job in data manager."