Skip to content

Commit 94fba0b

Browse files
committed
added test to http pipe
1 parent 8572ad7 commit 94fba0b

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

bale/tabs/history.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from datetime import datetime
22
import json
3-
from . import SelectionConfirm, Tab
43
from nicegui import ui, events
4+
import httpx
5+
from . import SelectionConfirm, Tab
56
from bale import elements as el
67
from bale.result import Result
78
from 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

Comments
 (0)