diff --git a/apps/default/.wf/components-workflows_workflow-0-lfltcky7l1fsm6j2.jsonl b/apps/default/.wf/components-workflows_workflow-0-lfltcky7l1fsm6j2.jsonl new file mode 100644 index 000000000..ae4e87d67 --- /dev/null +++ b/apps/default/.wf/components-workflows_workflow-0-lfltcky7l1fsm6j2.jsonl @@ -0,0 +1 @@ +{"id": "lfltcky7l1fsm6j2", "type": "workflows_workflow", "content": {}, "handlers": {}, "parentId": "workflows_root", "position": 0} diff --git a/apps/default/.wf/metadata.json b/apps/default/.wf/metadata.json index e47807980..0874722e9 100644 --- a/apps/default/.wf/metadata.json +++ b/apps/default/.wf/metadata.json @@ -1,3 +1,3 @@ { - "writer_version": "0.8.0rc1" + "writer_version": "0.8.1" } \ No newline at end of file diff --git a/apps/hello/.wf/components-page-0-bb4d0e86-619e-4367-a180-be28ab6059f4.jsonl b/apps/hello/.wf/components-page-0-bb4d0e86-619e-4367-a180-be28ab6059f4.jsonl index 2a569b24f..d4e90d3b5 100644 --- a/apps/hello/.wf/components-page-0-bb4d0e86-619e-4367-a180-be28ab6059f4.jsonl +++ b/apps/hello/.wf/components-page-0-bb4d0e86-619e-4367-a180-be28ab6059f4.jsonl @@ -5,11 +5,11 @@ {"id": "385247e5-5c89-4352-a598-b8da81146a5a", "type": "sliderinput", "binding": {"eventType": "wf-number-change", "stateRef": "filter.min_weight"}, "content": {"label": "Minimum weight", "maxValue": "600", "minValue": "300", "stepSize": "1"}, "handlers": {"wf-number-change": "update"}, "isCodeManaged": false, "parentId": "7e625201-20c2-4b05-951c-d825de28b216", "position": 1} {"id": "70d82458-a08f-4005-8f96-dc8d3ba92fad", "type": "section", "content": {"title": "About this app"}, "isCodeManaged": false, "parentId": "fbad9feb-5c88-4425-bb17-0d138286a875", "position": 1} {"id": "12e11005-3b5e-4bd8-9a8c-fc7b8cb757d0", "type": "text", "content": {"text": "This app is meant to serve as a lighthearted introduction to the framework. It's not a comprehensive demonstration of its capabilities."}, "isCodeManaged": false, "parentId": "70d82458-a08f-4005-8f96-dc8d3ba92fad", "position": 0} -{"id": "84378aea-b64c-49a3-9539-f854532279ee", "type": "header", "content": {"accentColor": "#ffffff", "emptinessColor": "#000000", "text": "HACKER PIGEONS"}, "isCodeManaged": false, "parentId": "bb4d0e86-619e-4367-a180-be28ab6059f4", "position": 0} +{"id": "84378aea-b64c-49a3-9539-f854532279ee", "type": "header", "content": {"accentColor": "#ffffff", "emptinessColor": "#000000", "text": "Hacker Pigeons"}, "isCodeManaged": false, "parentId": "bb4d0e86-619e-4367-a180-be28ab6059f4", "position": 0} {"id": "92a2c0c8-7ab4-4865-b7eb-ed437408c8f5", "type": "columns", "content": {}, "isCodeManaged": false, "parentId": "bb4d0e86-619e-4367-a180-be28ab6059f4", "position": 1} -{"id": "d1e01ce1-fab1-4a6e-91a1-1f45f9e57aa5", "type": "column", "content": {"isCollapsible": "", "isSticky": "yes", "title": "", "width": "1"}, "isCodeManaged": false, "parentId": "92a2c0c8-7ab4-4865-b7eb-ed437408c8f5", "position": 0} +{"id": "d1e01ce1-fab1-4a6e-91a1-1f45f9e57aa5", "type": "column", "content": {"isCollapsible": "", "isSticky": "yes", "title": "", "width": "0.8"}, "isCodeManaged": false, "parentId": "92a2c0c8-7ab4-4865-b7eb-ed437408c8f5", "position": 0} {"id": "9c30af6d-4ee5-4782-9169-0f361d67fa76", "type": "section", "content": {"title": ""}, "isCodeManaged": false, "parentId": "d1e01ce1-fab1-4a6e-91a1-1f45f9e57aa5", "position": 0} -{"id": "7fdd1d02-53de-4466-bd3c-4822cbc2694f", "type": "image", "content": {"caption": "", "src": "static/pigeon1.jpg?8"}, "isCodeManaged": false, "parentId": "9c30af6d-4ee5-4782-9169-0f361d67fa76", "position": 0} +{"id": "7fdd1d02-53de-4466-bd3c-4822cbc2694f", "type": "image", "content": {"caption": "", "src": "static/pigeon1.jpg?9"}, "isCodeManaged": false, "parentId": "9c30af6d-4ee5-4782-9169-0f361d67fa76", "position": 0} {"id": "31c1b0d5-bfb6-4304-82bd-1687d492f0a2", "type": "heading", "content": {"alignment": "", "text": "Pigeon Power: Birds Tackle Data Apps"}, "isCodeManaged": false, "parentId": "9c30af6d-4ee5-4782-9169-0f361d67fa76", "position": 1} {"id": "b27lw9ex8ig3x17p", "type": "tags", "content": {"seed": "", "tags": "{\n \"fiction\": \"fiction\",\n \"inspirational\": \"inspirational\",\n \"ai-generated\": \"ai-generated\"\n}"}, "isCodeManaged": false, "parentId": "9c30af6d-4ee5-4782-9169-0f361d67fa76", "position": 2, "visible": {"binding": "", "expression": true, "reversed": false}} {"id": "804e15bf-11a7-463d-8082-f46ea3acac1b", "type": "separator", "content": {}, "isCodeManaged": false, "parentId": "9c30af6d-4ee5-4782-9169-0f361d67fa76", "position": 3} @@ -44,10 +44,10 @@ {"id": "573f095f-94a7-43e4-a94e-b2f69439a164", "type": "separator", "content": {}, "isCodeManaged": false, "parentId": "fb22acfc-cdb5-44b6-9e97-76c3a51a8fff", "position": 1} {"id": "b1ee642e-f2e7-453b-a6ef-3d96eea37140", "type": "column", "content": {"contentHAlign": "center", "isCollapsible": "", "startCollapsed": "", "title": "HTML Element", "width": "1"}, "isCodeManaged": false, "parentId": "fb22acfc-cdb5-44b6-9e97-76c3a51a8fff", "position": 2} {"id": "71766c0c-e1e5-4675-9dd0-3aa2627773a0", "type": "html", "content": {"styles": "{\n \"padding\": \"16px\",\n \"margin\": \"24px\",\n \"min-height\": \"64px\",\n \"min-width\": \"64px\",\n \"max-width\": \"90%\",\n \"border-radius\": \"8px\",\n \"transform\": \"rotate(-3deg)\",\n \"box-shadow\": \"0 4px 16px -8px black\"\n}"}, "isCodeManaged": false, "parentId": "b1ee642e-f2e7-453b-a6ef-3d96eea37140", "position": 0} -{"id": "c921816d-6d45-4ce3-9c18-2c78ff850e0e", "type": "html", "content": {"attrs": "{ \"src\": \"static/pigeon1.jpg?3\"}", "element": "img", "styles": "{\n \"filter\": \"hue-rotate(calc(80deg + @{hue_rotation}deg))\"\n}"}, "isCodeManaged": false, "parentId": "71766c0c-e1e5-4675-9dd0-3aa2627773a0", "position": 0} +{"id": "c921816d-6d45-4ce3-9c18-2c78ff850e0e", "type": "html", "content": {"attrs": "{ \"src\": \"static/pigeon1.jpg?9\"}", "element": "img", "styles": "{\n \"filter\": \"hue-rotate(calc(80deg + @{hue_rotation}deg))\"\n}"}, "isCodeManaged": false, "parentId": "71766c0c-e1e5-4675-9dd0-3aa2627773a0", "position": 0} {"id": "c73602a6-453d-4ccf-b8e3-b1774ab4ff17", "type": "text", "content": {"text": "Use the HTML Element component when you need additional control."}, "isCodeManaged": false, "parentId": "71766c0c-e1e5-4675-9dd0-3aa2627773a0", "position": 1} {"id": "a36b75bc-58e6-48ba-bdef-0824e6b21e8d", "type": "html", "content": {"styles": "{\n \"padding\": \"16px\",\n \"margin\": \"24px\",\n \"min-height\": \"64px\",\n \"min-width\": \"64px\",\n \"max-width\": \"90%\",\n \"border-radius\": \"8px\",\n \"transform\": \"rotate(3deg)\",\n \"box-shadow\": \"0 4px 16px -8px black\"\n}"}, "isCodeManaged": false, "parentId": "b1ee642e-f2e7-453b-a6ef-3d96eea37140", "position": 1} -{"id": "c684f61e-0c79-4cb1-af9f-46c9cab5dfea", "type": "html", "content": {"attrs": "{ \"src\": \"static/pigeon1.jpg?3\"}", "element": "img", "styles": "{\n \"filter\": \"hue-rotate(calc(140deg + @{hue_rotation}deg))\"\n}"}, "isCodeManaged": false, "parentId": "a36b75bc-58e6-48ba-bdef-0824e6b21e8d", "position": 0} +{"id": "c684f61e-0c79-4cb1-af9f-46c9cab5dfea", "type": "html", "content": {"attrs": "{ \"src\": \"static/pigeon1.jpg?9\"}", "element": "img", "styles": "{\n \"filter\": \"hue-rotate(calc(140deg + @{hue_rotation}deg))\"\n}"}, "isCodeManaged": false, "parentId": "a36b75bc-58e6-48ba-bdef-0824e6b21e8d", "position": 0} {"id": "5da5e007-d60a-4313-9d21-885deae7b37d", "type": "text", "content": {"text": "You can put other Writer Framework components inside HTML Elements."}, "isCodeManaged": false, "parentId": "a36b75bc-58e6-48ba-bdef-0824e6b21e8d", "position": 1} {"id": "ee82e035-cfb2-4d00-95ce-ccbb9eb2dbb9", "type": "sliderinput", "binding": {"eventType": "wf-number-change", "stateRef": "hue_rotation"}, "content": {"label": "Hue rotation", "maxValue": "360", "minValue": "0", "stepSize": "1"}, "isCodeManaged": false, "parentId": "b1ee642e-f2e7-453b-a6ef-3d96eea37140", "position": 2} {"id": "c9bb4720-d07a-4fd8-bc53-5bda8dc64046", "type": "text", "content": {"text": "As shown above, you can use _HTML Element_ components together with state references.", "useMarkdown": "yes"}, "isCodeManaged": false, "parentId": "b1ee642e-f2e7-453b-a6ef-3d96eea37140", "position": 3} @@ -74,5 +74,5 @@ {"id": "e296866a-75d2-4677-b55d-3c1456113b89", "type": "text", "content": {"text": "Refreshing automatically using a timer."}, "isCodeManaged": false, "parentId": "09ddb2da-6fa3-4157-8da3-4d5d44a6a58d", "position": 1} {"id": "db4c66d6-1eb7-44d3-a2d4-65d0b3e5cf12", "type": "dataframe", "content": {"dataframe": "@{random_df}", "enableDownload": "", "enableSearch": "", "fontStyle": "monospace"}, "isCodeManaged": false, "parentId": "85120b55-69c6-4b50-853a-bbbf73ff8121", "position": 1} {"id": "fdf38e46-c01e-4a93-94d5-e187f9e4c823", "type": "text", "content": {"primaryTextColor": "#8a8a8a", "text": "_pgcf_ stands for \"Pigeon Coefficient\" and is a meaningless, randomly-generated value.", "useMarkdown": "yes"}, "isCodeManaged": false, "parentId": "85120b55-69c6-4b50-853a-bbbf73ff8121", "position": 2} -{"id": "e2c46zr4072th36z", "type": "tab", "content": {"name": "Dataframe"}, "handlers": {}, "isCodeManaged": false, "parentId": "ee919cd6-8153-4f34-8c6a-bfc1153df360", "position": 6} +{"id": "e2c46zr4072th36z", "type": "tab", "content": {"name": "Dataframe"}, "handlers": {}, "isCodeManaged": false, "parentId": "ee919cd6-8153-4f34-8c6a-bfc1153df360", "position": 5} {"id": "qelh30k75scw87ma", "type": "dataframe", "content": {"dataframe": "@{editable_df}", "enableRecordAdd": "yes", "enableRecordUpdate": "yes"}, "handlers": {}, "isCodeManaged": false, "parentId": "e2c46zr4072th36z", "position": 0} diff --git a/apps/hello/.wf/components-page-1-23bc1387-26ed-4ff2-8565-b027c2960c3c.jsonl b/apps/hello/.wf/components-page-1-23bc1387-26ed-4ff2-8565-b027c2960c3c.jsonl index ef4db36ac..dc4639284 100644 --- a/apps/hello/.wf/components-page-1-23bc1387-26ed-4ff2-8565-b027c2960c3c.jsonl +++ b/apps/hello/.wf/components-page-1-23bc1387-26ed-4ff2-8565-b027c2960c3c.jsonl @@ -1,5 +1,5 @@ {"id": "23bc1387-26ed-4ff2-8565-b027c2960c3c", "type": "page", "content": {"buttonColor": "#242424", "buttonTextColor": "#ffffff", "containerBackgroundColor": "#4F4F4F", "emptinessColor": "#333333", "key": "story", "primaryTextColor": "#ffffff", "separatorColor": "rgba(0, 0, 0, 0.2)"}, "handlers": {}, "isCodeManaged": false, "parentId": "root", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}} -{"id": "1d195388-35a3-43e1-b825-1d263b100a28", "type": "header", "content": {"text": "HACKER PIGEONS"}, "handlers": {}, "isCodeManaged": false, "parentId": "23bc1387-26ed-4ff2-8565-b027c2960c3c", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}} +{"id": "qvxrj45yilce889c", "type": "reuse", "content": {"proxyId": "84378aea-b64c-49a3-9539-f854532279ee"}, "handlers": {}, "isCodeManaged": false, "parentId": "23bc1387-26ed-4ff2-8565-b027c2960c3c", "position": 0} {"id": "8fe33adf-a5ea-4c7a-8d1d-59cc4dc14f05", "type": "columns", "content": {}, "handlers": {}, "isCodeManaged": false, "parentId": "23bc1387-26ed-4ff2-8565-b027c2960c3c", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}} {"id": "dfaae7f9-db20-4f70-a376-919bdc7b6010", "type": "column", "content": {"width": "1"}, "handlers": {}, "isCodeManaged": false, "parentId": "8fe33adf-a5ea-4c7a-8d1d-59cc4dc14f05", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}} {"id": "771dc336-69b2-400e-9ea3-e881e2332c9d", "type": "section", "content": {"title": "The story"}, "handlers": {}, "isCodeManaged": false, "parentId": "dfaae7f9-db20-4f70-a376-919bdc7b6010", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}} @@ -9,7 +9,7 @@ {"id": "90fbfa9d-3178-4fc2-b445-c31e1acfa6a7", "type": "button", "content": {"icon": "arrow_back", "text": "Go back to the main page"}, "handlers": {"click": "$goToPage_main"}, "isCodeManaged": false, "parentId": "9bb8a686-7013-4af7-a89e-d89c7754120d", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}} {"id": "ed010441-0cac-4aa5-9e6f-97228e0c3536", "type": "button", "content": {"icon": "download", "text": "Download this story"}, "handlers": {"click": "handle_story_download"}, "isCodeManaged": false, "parentId": "9bb8a686-7013-4af7-a89e-d89c7754120d", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}} {"id": "7402263c-cb8b-412d-b170-e6dc6ffcb706", "type": "column", "content": {"width": "1"}, "handlers": {}, "isCodeManaged": false, "parentId": "8fe33adf-a5ea-4c7a-8d1d-59cc4dc14f05", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}} -{"id": "5bc38721-8b48-43d5-a454-ee5ebe713a4c", "type": "section", "content": {"title": ""}, "isCodeManaged": false, "parentId": "7402263c-cb8b-412d-b170-e6dc6ffcb706", "position": 0} +{"id": "5bc38721-8b48-43d5-a454-ee5ebe713a4c", "type": "section", "content": {"containerBackgroundColor": "#ffffff", "title": ""}, "isCodeManaged": false, "parentId": "7402263c-cb8b-412d-b170-e6dc6ffcb706", "position": 0} {"id": "42ab5c3d-21fc-4e88-befd-33e52fd15e8b", "type": "image", "content": {"caption": "", "src": "static/pigeon1.jpg"}, "isCodeManaged": false, "parentId": "5bc38721-8b48-43d5-a454-ee5ebe713a4c", "position": 0} -{"id": "2df56a4b-b6e7-423d-a7a1-5d23c77f65fa", "type": "heading", "content": {"alignment": "", "text": "Each page can have its own style"}, "isCodeManaged": false, "parentId": "5bc38721-8b48-43d5-a454-ee5ebe713a4c", "position": 1} -{"id": "77cb256b-ef12-4a55-a051-500497f41302", "type": "text", "content": {"text": "It's easy to switch between pages and it can be done from the frontend (via Writer Framework Builder) and from the backend (via Python)."}, "handlers": {}, "isCodeManaged": false, "parentId": "5bc38721-8b48-43d5-a454-ee5ebe713a4c", "position": 2, "visible": {"binding": "", "expression": true, "reversed": false}} +{"id": "2df56a4b-b6e7-423d-a7a1-5d23c77f65fa", "type": "heading", "content": {"alignment": "", "primaryTextColor": "#486778", "text": "Each page can have its own style"}, "isCodeManaged": false, "parentId": "5bc38721-8b48-43d5-a454-ee5ebe713a4c", "position": 1} +{"id": "77cb256b-ef12-4a55-a051-500497f41302", "type": "text", "content": {"primaryTextColor": "#1e2a31", "text": "It's easy to switch between pages and it can be done from the frontend (via Writer Framework Builder) and from the backend (via Python)."}, "handlers": {}, "isCodeManaged": false, "parentId": "5bc38721-8b48-43d5-a454-ee5ebe713a4c", "position": 2, "visible": {"binding": "", "expression": true, "reversed": false}} diff --git a/apps/hello/.wf/components-page-2-w0pur56ujeiv3s5v.jsonl b/apps/hello/.wf/components-page-2-w0pur56ujeiv3s5v.jsonl new file mode 100644 index 000000000..7e68496f8 --- /dev/null +++ b/apps/hello/.wf/components-page-2-w0pur56ujeiv3s5v.jsonl @@ -0,0 +1,7 @@ +{"id": "w0pur56ujeiv3s5v", "type": "page", "content": {}, "handlers": {}, "parentId": "root", "position": 2} +{"id": "tj5rln4r1dxr4t9y", "type": "section", "content": {"isCollapsible": "yes", "title": "Section Title"}, "handlers": {}, "parentId": "w0pur56ujeiv3s5v", "position": 0} +{"id": "1h2u1o63xfedkjgu", "type": "text", "content": {"text": "Text"}, "handlers": {}, "parentId": "tj5rln4r1dxr4t9y", "position": 0} +{"id": "o76ltlj9uym0f3p3", "type": "section", "content": {"isCollapsible": "yes", "startCollapsed": "yes", "title": "Section Title"}, "handlers": {}, "parentId": "w0pur56ujeiv3s5v", "position": 1} +{"id": "44o2mezeegspifl3", "type": "text", "content": {"text": "Text"}, "handlers": {}, "parentId": "o76ltlj9uym0f3p3", "position": 0} +{"id": "4go1gvv5s6pus80p", "type": "section", "content": {"isCollapsible": "yes", "title": "Section Title"}, "handlers": {}, "parentId": "w0pur56ujeiv3s5v", "position": 2} +{"id": "nwmweasodpa9sr9w", "type": "text", "content": {"text": "Text"}, "handlers": {}, "parentId": "4go1gvv5s6pus80p", "position": 0} diff --git a/apps/hello/.wf/metadata.json b/apps/hello/.wf/metadata.json index e47807980..0874722e9 100644 --- a/apps/hello/.wf/metadata.json +++ b/apps/hello/.wf/metadata.json @@ -1,3 +1,3 @@ { - "writer_version": "0.8.0rc1" + "writer_version": "0.8.1" } \ No newline at end of file diff --git a/apps/hello/main.py b/apps/hello/main.py index d97a965a9..40462ed07 100644 --- a/apps/hello/main.py +++ b/apps/hello/main.py @@ -170,7 +170,7 @@ def on_editable_df_record_action(state, payload): "editable_df_open_text": "", "highlighted_members": _get_highlighted_members(), "random_df": _generate_random_df(), - "hue_rotation": 26, + "hue_rotation": 180, "paginated_members": _get_paginated_members(0, 2), "paginated_members_page": 1, "paginated_members_total_items": len(_get_main_df()), diff --git a/apps/hello/static/pigeon1.jpg b/apps/hello/static/pigeon1.jpg index efa6ea399..9b0fcd60b 100644 Binary files a/apps/hello/static/pigeon1.jpg and b/apps/hello/static/pigeon1.jpg differ diff --git a/src/ui/src/builder/settings/BuilderSettingsHandlers.vue b/src/ui/src/builder/settings/BuilderSettingsHandlers.vue index 54f6cd71b..96d74fc6f 100644 --- a/src/ui/src/builder/settings/BuilderSettingsHandlers.vue +++ b/src/ui/src/builder/settings/BuilderSettingsHandlers.vue @@ -162,18 +162,16 @@ const options = computed(() => { .map((v) => v.name) .map((v) => ({ value: v, label: v, icon: "function" })); - const pageKeyOptions: Option[] = pageKeys.value - .map((v) => `$goToPage_${v}`) - .map((v) => ({ - icon: "link", - value: v, - label: v, - })); + const pageKeyOptions: Option[] = pageKeys.value.map((v) => ({ + label: `Go to page "${v}"`, + value: `$goToPage_${v}`, + icon: "link", + })); const workflowKeyOptions: Option[] = workflowKeys.value.map((v) => ({ - label: `$runWorkflow_${v}`, - value: `Run workflow "${v}"`, - icon: "move_down", + label: `Run workflow "${v}"`, + value: `$runWorkflow_${v}`, + icon: "linked_services", })); return [ diff --git a/src/ui/src/builder/useComponentActions.ts b/src/ui/src/builder/useComponentActions.ts index a7382bbde..c3c863d66 100644 --- a/src/ui/src/builder/useComponentActions.ts +++ b/src/ui/src/builder/useComponentActions.ts @@ -496,6 +496,10 @@ export function useComponentActions(wf: Core, ssbm: BuilderManager) { }); }); c.id = newId; + if (typeof c.x !== "undefined" && typeof c.y !== "undefined") { + c.x += 36; + c.y += 36; + } }); return deepCopiedSubtree; } diff --git a/src/ui/src/components/core/other/CoreReuse.vue b/src/ui/src/components/core/other/CoreReuse.vue index af43e616d..88a974b45 100644 --- a/src/ui/src/components/core/other/CoreReuse.vue +++ b/src/ui/src/components/core/other/CoreReuse.vue @@ -51,7 +51,12 @@ function renderError(message: string, cls: string) { shouldRender.value = props.contextSlot === "default"; vnode.value = h( "div", - { class: ["CoreReuse", cls] }, + { + class: ["CoreReuse", cls], + style: { + color: "var(--primaryTextColor)", + }, + }, isBeingEdited.value ? message : "", ); } diff --git a/tests/backend/blocks/test_writeraddtokg.py b/tests/backend/blocks/test_writeraddtokg.py index 7042a874c..bea0046bf 100644 --- a/tests/backend/blocks/test_writeraddtokg.py +++ b/tests/backend/blocks/test_writeraddtokg.py @@ -23,9 +23,10 @@ def mock_upload_file(data, type, name): return MockFile() -def test_add_to_kg(session, runner): - writer.ai.retrieve_graph = mock_retrieve_graph - writer.ai.upload_file = mock_upload_file +def test_add_to_kg(monkeypatch, session, runner): + monkeypatch.setattr("writer.ai.retrieve_graph", mock_retrieve_graph) + monkeypatch.setattr("writer.ai.upload_file", mock_upload_file) + session.session_state["my_files"] = [ { "data": b"123", @@ -47,9 +48,10 @@ def test_add_to_kg(session, runner): assert block.outcome == "success" -def test_add_to_kg_missing_type(session, runner): - writer.ai.retrieve_graph = mock_retrieve_graph - writer.ai.upload_file = mock_upload_file +def test_add_to_kg_missing_type(monkeypatch, session, runner): + monkeypatch.setattr("writer.ai.retrieve_graph", mock_retrieve_graph) + monkeypatch.setattr("writer.ai.upload_file", mock_upload_file) + session.session_state["my_files"] = [ { "data": b"123", @@ -65,9 +67,10 @@ def test_add_to_kg_missing_type(session, runner): with pytest.raises(WriterConfigurationError): block.run() -def test_add_to_kg_wrong_type(session, runner): - writer.ai.retrieve_graph = mock_retrieve_graph - writer.ai.upload_file = mock_upload_file +def test_add_to_kg_wrong_type(monkeypatch, session, runner): + monkeypatch.setattr("writer.ai.retrieve_graph", mock_retrieve_graph) + monkeypatch.setattr("writer.ai.upload_file", mock_upload_file) + session.session_state["my_files"] = "should be list" session.add_fake_component({ "graphId": "abc123", diff --git a/tests/backend/blocks/test_writerclassification.py b/tests/backend/blocks/test_writerclassification.py index 730968e77..eadcc9387 100644 --- a/tests/backend/blocks/test_writerclassification.py +++ b/tests/backend/blocks/test_writerclassification.py @@ -14,8 +14,8 @@ def fake_complete(prompt, config): return "other" -def test_classify(session, runner): - writer.ai.complete = fake_complete +def test_classify(monkeypatch, session, runner): + monkeypatch.setattr("writer.ai.complete", fake_complete) session.add_fake_component({ "text": "canine", "categories": json.dumps({ @@ -30,8 +30,8 @@ def test_classify(session, runner): assert block.outcome == "category_dog" -def test_classify_missing_categories(session, runner): - writer.ai.complete = fake_complete +def test_classify_missing_categories(monkeypatch, session, runner): + monkeypatch.setattr("writer.ai.complete", fake_complete) session.add_fake_component({ "text": "canine", "categories": json.dumps({}) diff --git a/tests/backend/blocks/test_writercompletion.py b/tests/backend/blocks/test_writercompletion.py index 6573a7f8f..9b1ca46a7 100644 --- a/tests/backend/blocks/test_writercompletion.py +++ b/tests/backend/blocks/test_writercompletion.py @@ -2,14 +2,14 @@ from writer.blocks.writercompletion import WriterCompletion -def test_complete(session, runner): +def test_complete(monkeypatch, session, runner): def fake_complete(prompt, config): assert config.get("temperature") == 0.9 assert config.get("model") == "buenos-aires-x-004" assert prompt == "What color is the sea?" return "Blue." - writer.ai.complete = fake_complete + monkeypatch.setattr("writer.ai.complete", fake_complete) session.add_fake_component({ "prompt": "What color is the sea?", "modelId": "buenos-aires-x-004", @@ -20,14 +20,14 @@ def fake_complete(prompt, config): assert block.result == "Blue." assert block.outcome == "success" -def test_complete_missing_text(session, runner): +def test_complete_missing_text(monkeypatch, session, runner): def fake_complete(prompt, config): assert config.get("temperature") == 0.9 assert config.get("model") == "buenos-aires-x-004" assert not prompt return "Plants are usually green." - writer.ai.complete = fake_complete + monkeypatch.setattr("writer.ai.complete", fake_complete) session.add_fake_component({ "prompt": "", "modelId": "buenos-aires-x-004", diff --git a/tests/backend/blocks/test_writernocodeapp.py b/tests/backend/blocks/test_writernocodeapp.py index f93cd38a6..9c8f576cd 100644 --- a/tests/backend/blocks/test_writernocodeapp.py +++ b/tests/backend/blocks/test_writernocodeapp.py @@ -1,26 +1,21 @@ import json -from unittest.mock import AsyncMock, MagicMock, patch import pytest import writer.ai from writer.blocks.writernocodeapp import WriterNoCodeApp -@pytest.fixture -def mock_app_content_generation(): - with patch('writer.ai.apps.generate_content') as mock_generate_content: - def fake_generate_content(application_id, app_inputs): - assert application_id == "123" +def fake_generate_content(application_id, app_inputs): + assert application_id == "123" - name = app_inputs.get("name") - animal = app_inputs.get("animal") + name = app_inputs.get("name") + animal = app_inputs.get("animal") - return f"{name} the {animal} " - mock_generate_content.side_effect = fake_generate_content + return f"{name} the {animal} " - yield mock_generate_content - -def test_call_nocode_app(mock_app_content_generation, session, runner): +def test_call_nocode_app(monkeypatch, session, runner): + monkeypatch.setattr("writer.ai.apps.generate_content", fake_generate_content) + writer.ai.apps.generate_content = fake_generate_content session.add_fake_component({ "appId": "123", "appInputs": json.dumps({ @@ -34,7 +29,8 @@ def test_call_nocode_app(mock_app_content_generation, session, runner): assert block.outcome == "success" -def test_call_nocode_app_missing_appid(mock_app_content_generation, session, runner): +def test_call_nocode_app_missing_appid(monkeypatch, session, runner): + monkeypatch.setattr("writer.ai.apps.generate_content", fake_generate_content) session.add_fake_component({ "appId": "", "appInputs": json.dumps({