From: Swaraj Kumar Date: Mon, 13 Jan 2025 19:51:47 +0000 (+0530) Subject: UT for pipeline manager X-Git-Tag: 4.0.0~31 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F67%2F14067%2F1;p=aiml-fw%2Fawmf%2Ftm.git UT for pipeline manager Change-Id: I88b8ae86302d96aef8aa55614160bdb2f0c11251 Signed-off-by: Swaraj Kumar --- diff --git a/tests/test_pipelinemgr.py b/tests/test_pipelinemgr.py index 92d972d..c581c7a 100644 --- a/tests/test_pipelinemgr.py +++ b/tests/test_pipelinemgr.py @@ -41,7 +41,7 @@ class TestPipelineMgr: result = pipeline_mgr.get_all_pipelines() assert len(result) == 2 assert result[0]["id"] == "pipeline1" - + @patch("requests.get") def test_get_all_pipelines_invalid_response(self, mock_get, pipeline_mgr): mock_response = MagicMock() @@ -50,3 +50,46 @@ class TestPipelineMgr: mock_get.return_value = mock_response with pytest.raises(TMException, match="Kf adapter doesn't sends json type response"): pipeline_mgr.get_all_pipelines() + + @patch("requests.get") + def test_get_all_pipeline_versions_success(self, mock_get, pipeline_mgr): + mock_response = MagicMock() + mock_response.status_code = 200 + mock_response.headers = {"content-type": "application/json"} + mock_response.json.return_value = [{"version": "1.0"}, {"version": "2.0"}] + mock_get.return_value = mock_response + result = pipeline_mgr.get_all_pipeline_versions("pipeline1") + assert len(result) == 2 + assert result[0]["version"] == "1.0" + + @patch("requests.post") + def test_upload_pipeline_file_success(self, mock_post, pipeline_mgr, tmp_path): + mock_response = MagicMock() + mock_response.status_code = 200 + mock_post.return_value = mock_response + # Create a temporary file for testing + file_path = tmp_path / "test_pipeline.yaml" + file_path.write_text("pipeline content") + result = pipeline_mgr.upload_pipeline_file("pipeline1", str(file_path), "Test pipeline") + assert result is True + + @patch("requests.post") + def test_upload_pipeline_file_failure(self, mock_post, pipeline_mgr, tmp_path): + mock_response = MagicMock() + mock_response.status_code = 400 + mock_response.json.return_value = {"message": "Invalid file"} + mock_post.return_value = mock_response + # Create a temporary file for testing + file_path = tmp_path / "test_pipeline.yaml" + file_path.write_text("pipeline content") + with pytest.raises(TMException, match="Error while uploading pipeline"): + pipeline_mgr.upload_pipeline_file("pipeline1", str(file_path), "Test pipeline") + + @patch("requests.post") + def test_start_training_success(self, mock_post, pipeline_mgr): + mock_response = MagicMock() + mock_response.status_code = 200 + mock_post.return_value = mock_response + training_details = {"param1": "value1"} + response = pipeline_mgr.start_training(training_details, "trainingjob1") + assert response.status_code == 200