UT for pipeline manager 07/14007/2
authorSwaraj Kumar <swaraj.kumar@samsung.com>
Mon, 13 Jan 2025 19:51:47 +0000 (01:21 +0530)
committersubhash kumar singh <subh.singh@samsung.com>
Tue, 14 Jan 2025 18:18:19 +0000 (18:18 +0000)
Change-Id: I88b8ae86302d96aef8aa55614160bdb2f0c11251
Signed-off-by: Swaraj Kumar <swaraj.kumar@samsung.com>
(cherry picked from commit 9a09cb191c6d097e2a75d50328ea9c223e1a7790)

tests/test_pipelinemgr.py

index 92d972d..c581c7a 100644 (file)
@@ -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