/ justapi / crates / justapi-py / test_graphql.py
swadhinbiswas test(py): add comprehensive test suite for Python bindings · 7/8/2026
f693697
39 lines · 947 Bytes
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
import requests
import time
import threading
from justapi import JustAPIApp

def test_graphql():
    app = JustAPIApp()
    
    def run_server():
        app.run("127.0.0.1:9200")
        
    t = threading.Thread(target=run_server, daemon=True)
    t.start()
    time.sleep(1) # Wait for startup
    
    # Test 1: GraphiQL UI
    resp = requests.get("http://127.0.0.1:9200/graphql")
    assert resp.status_code == 200
    assert b"GraphiQL" in resp.content
    
    # Test 2: GraphQL Query
    query = """
    query {
        systemStatus
        version
    }
    """
    resp = requests.post("http://127.0.0.1:9200/graphql", json={"query": query})
    assert resp.status_code == 200
    
    data = resp.json()
    assert "data" in data
    assert data["data"]["systemStatus"] == "JustAPI GraphQL Federation Gateway is running"
    
    print("Test Passed: GraphQL & Federation Gateway Works!")

if __name__ == "__main__":
    test_graphql()