forked from AIObjectives/talk-to-the-city-reports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
python.integration.test.ts
54 lines (51 loc) · 1.76 KB
/
python.integration.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { describe, it, vi, expect } from 'vitest';
import PythonNodeV0, { python_node_data } from '$lib/compute/python_v0';
import deepCopy from 'deep-copy';
import _ from 'lodash';
import dotenv from 'dotenv';
dotenv.config();
describe('PythonNodeV0 integration', () => {
it('should execute python script and return outputData', async () => {
if (import.meta.env.VITE_PYTHON_LAMBDA_SECRET) {
const node = new PythonNodeV0(deepCopy(python_node_data));
node.data.text = 'outputData = 123';
const output = await node.compute({}, 'run', vi.fn(), vi.fn(), vi.fn(), 'test_slug', vi.fn());
expect(output).toEqual(123);
}
}, 10000);
it('should be able to pass input to outputData', async () => {
if (import.meta.env.VITE_PYTHON_LAMBDA_SECRET) {
const node = new PythonNodeV0(deepCopy(python_node_data));
node.data.text = 'outputData = inputData[0]';
node.data.input_ids.inputs.push('some_node');
const output = await node.compute(
{ some_node: 123 },
'run',
vi.fn(),
vi.fn(),
vi.fn(),
'test_slug',
vi.fn()
);
expect(output).toEqual(123);
}
}, 10000);
it('should be able to make get requests to jsonapi', async () => {
if (import.meta.env.VITE_PYTHON_LAMBDA_SECRET) {
const node = new PythonNodeV0(deepCopy(python_node_data));
node.data.text =
'import requests; outputData = requests.get("https://dummyjson.com/products").json()';
node.data.input_ids['input_0'] = 'some_node';
const output = await node.compute(
{ some_node: 123 },
'run',
vi.fn(),
vi.fn(),
vi.fn(),
'test_slug',
vi.fn()
);
expect(_.keys(output)).includes('products');
}
}, 10000);
});