Skip to content

Commit

Permalink
test: Tests for workflow API async jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
ramedina86 committed Dec 10, 2024
1 parent 7f11062 commit 278f668
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
28 changes: 27 additions & 1 deletion tests/backend/test_serve.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import mimetypes
import os

import fastapi
import fastapi.testclient
import pytest
from writer import crypto
import writer.abstract
import writer.serve
from fastapi import FastAPI
Expand Down Expand Up @@ -213,4 +215,28 @@ def test_feature_flags(self):
"Content-Type": "application/json"
})
feature_flags = res.json().get("featureFlags")
assert feature_flags == ["flag_one", "flag_two"]
assert feature_flags == ["flag_one", "flag_two"]

# def test_create_workflow_job_api(self):
# asgi_app: fastapi.FastAPI = writer.serve.get_asgi_app(
# test_app_dir, "run")
# os.environ["WRITER_BASE_HASH"] = "abc"
# workflow_key = "workflow2"

# with fastapi.testclient.TestClient(asgi_app) as client:
# create_job_token = crypto.get_hash(f"create_job_{workflow_key}")
# res = client.post(f"/api/job/workflow/{workflow_key}", json={
# "proposedSessionId": None
# }, headers={
# "Content-Type": "application/json",
# "Authorization": f"Bearer {create_job_token}"
# })
# job_id = res.json().get("id")
# get_job_token = res.json().get("token")
# res = client.get(f"/api/job/{job_id}", headers={
# "Authorization": f"Bearer {get_job_token}"
# })
# assert res.json().get("result") == 987127

# os.environ["WRITER_BASE_HASH"] = ""

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{"id": "hywgzgfetx6rpiqz", "type": "workflows_workflow", "content": {}, "handlers": {}, "isCodeManaged": false, "parentId": "workflows_root", "position": 0}
{"id": "rbh725i69ilo6gsr", "type": "workflows_setstate", "content": {"element": "test", "value": "test"}, "handlers": {}, "outs": [{"outId": "success", "toNodeId": "f052suq3dgzb5np7"}, {"outId": "success", "toNodeId": "f052suq3dgzb5np7"}], "parentId": "hywgzgfetx6rpiqz", "position": 0, "x": 248, "y": 204}
{"id": "mw5rz7ay5p8pg2fm", "type": "workflows_writerclassification", "content": {}, "handlers": {}, "parentId": "hywgzgfetx6rpiqz", "position": 1, "x": 935, "y": 153}
{"id": "3cy7f577x6xsijiq", "type": "workflows_runworkflow", "content": {}, "handlers": {}, "parentId": "hywgzgfetx6rpiqz", "position": 2, "x": 645, "y": 328}
{"id": "c0v1pnroo32gfsye", "type": "workflows_httprequest", "content": {}, "handlers": {}, "parentId": "hywgzgfetx6rpiqz", "position": 3, "x": 497, "y": 80}
{"id": "rbh725i69ilo6gsr", "type": "workflows_setstate", "content": {"element": "test", "value": "test"}, "handlers": {}, "isCodeManaged": false, "outs": [{"outId": "success", "toNodeId": "f052suq3dgzb5np7"}, {"outId": "success", "toNodeId": "f052suq3dgzb5np7"}], "parentId": "hywgzgfetx6rpiqz", "position": 0, "x": 248, "y": 204}
{"id": "mw5rz7ay5p8pg2fm", "type": "workflows_writerclassification", "content": {}, "handlers": {}, "isCodeManaged": false, "parentId": "hywgzgfetx6rpiqz", "position": 1, "x": 935, "y": 153}
{"id": "3cy7f577x6xsijiq", "type": "workflows_runworkflow", "content": {}, "handlers": {}, "isCodeManaged": false, "parentId": "hywgzgfetx6rpiqz", "position": 2, "x": 645, "y": 328}
{"id": "c0v1pnroo32gfsye", "type": "workflows_httprequest", "content": {}, "handlers": {}, "isCodeManaged": false, "parentId": "hywgzgfetx6rpiqz", "position": 3, "x": 497, "y": 80}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"id": "8ffkuce0ermsm9dr", "type": "workflows_workflow", "content": {"key": "workflow2"}, "handlers": {}, "parentId": "workflows_root", "position": 1}
{"id": "6ymlyaewhil88bck", "type": "workflows_returnvalue", "content": {"value": "987127"}, "handlers": {}, "parentId": "8ffkuce0ermsm9dr", "position": 0, "x": 408, "y": 172}
2 changes: 1 addition & 1 deletion tests/backend/testapp/.wf/metadata.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"writer_version": "0.8.0rc1"
"writer_version": "0.8.3rc1"
}
2 changes: 2 additions & 0 deletions tests/backend/testapp/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import writer.core
from writer import WriterUIManager


writer.Config.feature_flags.append("workflows")
writer.Config.feature_flags.append("flag_one")
writer.Config.feature_flags.append("flag_two")

Expand Down

0 comments on commit 278f668

Please sign in to comment.