File size: 2,239 Bytes
e4ff751
2601533
 
becba58
2601533
 
 
 
 
 
 
 
 
 
 
 
becba58
 
 
2601533
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4ff751
 
 
2601533
 
 
 
 
 
 
e4ff751
2601533
 
 
 
 
 
e4ff751
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import pathlib
import uuid
from fastapi.testclient import TestClient
from lynxkite_app.main import app, detect_plugins
import os


client = TestClient(app)


def test_detect_plugins_with_plugins():
    # This test assumes that these plugins are installed as part of the testing process.
    plugins = detect_plugins()
    assert all(
        plugin in plugins.keys()
        for plugin in [
            "lynxkite_graph_analytics",
            "lynxkite_lynxscribe",
            "lynxkite_pillow_example",
        ]
    )


def test_get_catalog():
    response = client.get("/api/catalog")
    assert response.status_code == 200


def test_save_and_load():
    save_request = {
        "path": "test",
        "ws": {
            "env": "test",
            "nodes": [
                {
                    "id": "Node_1",
                    "type": "basic",
                    "data": {
                        "display": None,
                        "error": "Unknown operation.",
                        "title": "Test node",
                        "params": {"param1": "value"},
                    },
                    "position": {"x": -493.5496596237119, "y": 20.90123252513356},
                }
            ],
            "edges": [],
        },
    }
    response = client.post("/api/save", json=save_request)
    saved_ws = response.json()
    assert response.status_code == 200
    response = client.get("/api/load?path=test")
    assert response.status_code == 200
    assert saved_ws == response.json()


def test_list_dir():
    test_dir = pathlib.Path() / str(uuid.uuid4())
    test_dir.mkdir(parents=True, exist_ok=True)
    test_file = test_dir / "test_file.txt"
    test_file.touch()
    response = client.get(f"/api/dir/list?path={str(test_dir)}")
    assert response.status_code == 200
    assert len(response.json()) == 1
    assert response.json()[0]["name"] == f"{test_dir}/test_file.txt"
    assert response.json()[0]["type"] == "workspace"
    test_file.unlink()
    test_dir.rmdir()


def test_make_dir():
    dir_name = str(uuid.uuid4())
    response = client.post("/api/dir/mkdir", json={"path": dir_name})
    assert response.status_code == 200
    assert os.path.exists(dir_name)
    os.rmdir(dir_name)