@@ -185,6 +185,110 @@ def test_push_pipeline(
185185 result .output ,
186186 )
187187
188+ @patch ("openhexa.cli.api.graphql" )
189+ @patch .dict (os .environ , {"HEXA_API_URL" : "https://www.bluesquarehub.com/" , "HEXA_WORKSPACE" : "workspace" })
190+ def test_push_pipeline_with_yes_flag_without_code (self , mock_graphql ):
191+ """Test pushing a pipeline with the --yes flag without providing a --code."""
192+ with self .runner .isolated_filesystem () as tmp :
193+ with open (Path (tmp ) / python_file_name , "w" ) as f :
194+ f .write (python_code )
195+ mock_graphql .return_value = setup_graphql_response ()
196+
197+ result = self .runner .invoke (
198+ pipelines_push ,
199+ [tmp , "--yes" ],
200+ )
201+ self .assertEqual (result .exit_code , 1 )
202+ self .assertIn (
203+ "❌ You must provide a pipeline code (using -c or --code) when using the --yes flag." , result .output
204+ )
205+
206+ @patch ("openhexa.cli.api.graphql" )
207+ @patch ("openhexa.cli.cli.get_pipeline" )
208+ @patch ("openhexa.cli.cli.get_pipelines_pages" )
209+ @patch ("openhexa.cli.cli.get_pipeline_from_code" )
210+ @patch .dict (os .environ , {"HEXA_API_URL" : "https://www.bluesquarehub.com/" , "HEXA_WORKSPACE" : "workspace" })
211+ def test_push_pipeline_with_non_existing_code (
212+ self , mock_get_pipeline_from_code , mock_get_pipelines_pages , mock_get_pipeline , mock_graphql
213+ ):
214+ """Test pushing a pipeline with a non-existing --code flag."""
215+ with self .runner .isolated_filesystem () as tmp :
216+ with open (Path (tmp ) / python_file_name , "w" ) as f :
217+ f .write (python_code )
218+ mock_graphql .return_value = setup_graphql_response ()
219+ mock_pipeline = MagicMock (spec = Pipeline )
220+ mock_pipeline .name = pipeline_name
221+ mock_get_pipeline .return_value = mock_pipeline
222+ mock_get_pipelines_pages .return_value = {
223+ "items" : [
224+ {"name" : "Pipeline1" , "code" : "code1" },
225+ {"name" : "Pipeline2" , "code" : "code2" },
226+ ],
227+ "totalPages" : 2 ,
228+ }
229+ mock_get_pipeline_from_code .return_value = None # Simulate non-existing pipeline code
230+
231+ result = self .runner .invoke (
232+ pipelines_push ,
233+ [tmp , "--code" , "non_existing_code" ],
234+ )
235+ self .assertEqual (result .exit_code , 1 )
236+ self .assertIn ("❌ Pipeline with code 'non_existing_code' not found." , result .output )
237+
238+ @patch ("openhexa.cli.api.graphql" )
239+ @patch ("openhexa.cli.cli.get_pipeline" )
240+ @patch ("openhexa.cli.cli.get_pipelines_pages" )
241+ @patch ("openhexa.cli.cli.upload_pipeline" )
242+ @patch .dict (os .environ , {"HEXA_API_URL" : "https://www.bluesquarehub.com/" , "HEXA_WORKSPACE" : "workspace" })
243+ def test_push_pipeline_with_code_flag (
244+ self , mock_upload_pipeline , mock_get_pipelines_pages , mock_get_pipeline , mock_graphql
245+ ):
246+ """Test pushing a pipeline using the --code flag."""
247+ code = "code1"
248+ with self .runner .isolated_filesystem () as tmp :
249+ with open (Path (tmp ) / python_file_name , "w" ) as f :
250+ f .write (python_code )
251+ mock_graphql .return_value = {
252+ "pipelineByCode" : {
253+ "code" : code ,
254+ "currentVersion" : {"zipfile" : "" },
255+ },
256+ "pipelines" : {"items" : []},
257+ }
258+ mock_pipeline = MagicMock (spec = Pipeline )
259+ mock_pipeline .name = pipeline_name
260+ mock_get_pipeline .return_value = mock_pipeline
261+ mock_get_pipelines_pages .return_value = {
262+ "items" : [
263+ {"name" : "Pipeline1" , "code" : "code1" },
264+ {"name" : "Pipeline2" , "code" : "code2" },
265+ ],
266+ "totalPages" : 2 ,
267+ }
268+ mock_upload_pipeline .return_value = {
269+ "versionName" : version ,
270+ "pipeline" : {
271+ "id" : pipeline_id ,
272+ "permissions" : {"createTemplateVersion" : True },
273+ "template" : template ,
274+ },
275+ "id" : pipeline_version_id ,
276+ }
277+
278+ result = self .runner .invoke (
279+ pipelines_push ,
280+ [tmp , "--name" , version , "--code" , code ],
281+ input = "Y\n n\n " ,
282+ )
283+ self .assertEqual (result .exit_code , 0 )
284+ self .assertNotIn ("Which pipeline do you want to update?" , result .output )
285+ self .assertTrue (mock_upload_pipeline .called )
286+ self .assertEqual (mock_upload_pipeline .call_args [0 ][0 ], code )
287+ self .assertIn (
288+ f"✅ New version '{ version } ' created! " ,
289+ result .output ,
290+ )
291+
188292 @patch ("openhexa.cli.cli.click.prompt" )
189293 def test_select_pipeline (self , mock_prompt ):
190294 workspace_pipelines = [
0 commit comments