11from datetime import datetime
22import json
3- from . import SelectionConfirm , Tab
43from nicegui import ui , events
4+ import httpx
5+ from . import SelectionConfirm , Tab
56from bale import elements as el
67from bale .result import Result
78from bale .interfaces import zfs
@@ -98,6 +99,20 @@ def set_content(status: str, e: events.JsonEditorChangeEventArguments) -> None:
9899 http [status ]["data" ] = e .content ["json" ]["data" ]
99100 http [status ]["headers" ] = e .content ["json" ]["headers" ]
100101
102+ def test (status ):
103+ try :
104+ url = http [status ]["url" ]
105+ data = self .process_pipe_data (result = Result (name = self .host , command = "TEST COMMAND" , status = status ), data = http [status ]["data" ])
106+ headers = http [status ]["headers" ]
107+ post = httpx .post (url = url , json = data , headers = headers )
108+ print (post .status_code )
109+ if post .status_code == 200 :
110+ el .notify ("Test successful!" , type = "positive" )
111+ else :
112+ el .notify (f"Test failed with status code { post .status_code } !" , type = "negative" )
113+ except :
114+ el .notify ("Test failed!" , type = "negative" )
115+
101116 def show_controls (status ):
102117 if status not in http :
103118 http [status ] = {}
@@ -115,7 +130,7 @@ def show_controls(status):
115130 "topic" : "mytopic" ,
116131 "tags" : ["turtle" ],
117132 "title" : "Successful Automation Run for {name}" ,
118- "message" : "{stdout }" ,
133+ "message" : "{command }" ,
119134 },
120135 )
121136 editor .properties ["content" ]["json" ]["headers" ] = self .get_pipe_status ("http" , status ).get ("headers" , {"Authorization" : "Bearer tk_..." })
@@ -134,11 +149,15 @@ def show_controls(status):
134149 with ui .step ("On Success" ):
135150 with el .WColumn ().classes ("col justify-start" ):
136151 show_controls (status = "success" )
137- el .LgButton ("NEXT" , on_click = lambda _ : stepper .next ())
152+ with el .WRow ():
153+ el .LgButton ("TEST" , on_click = lambda _ : test (status = "success" ))
154+ el .LgButton ("NEXT" , on_click = lambda _ : stepper .next ())
138155 with ui .step ("On Error" ):
139156 with el .WColumn ().classes ("col justify-start" ):
140157 show_controls (status = "error" )
141- el .DButton ("SAVE" , on_click = lambda : host_dialog .submit ("save" ))
158+ with el .WRow ():
159+ el .LgButton ("TEST" , on_click = lambda _ : test (status = "error" ))
160+ el .DButton ("SAVE" , on_click = lambda : host_dialog .submit ("save" ))
142161
143162 result = await host_dialog
144163 if result == "save" :
0 commit comments