-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
102 lines (89 loc) · 2.22 KB
/
test.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import requests
BASE_URL = "http://127.0.0.1:8000"
def test_create_user():
query = """
mutation {
createUser(name: "Shikha Pandey") {
id
name
}
}
"""
response = requests.post(f"{BASE_URL}/graphql", json={"query": query})
assert response.status_code == 200
data = response.json()
assert "errors" not in data
assert "data" in data
user = data["data"]["createUser"]
assert user["name"] == "Shikha Pandey"
def test_update_user():
query = """
mutation {
updateUser(id: 1, name: "Yogesh Singh") {
id
name
}
}
"""
response = requests.post(f"{BASE_URL}/graphql", json={"query": query})
assert response.status_code == 200
data = response.json()
assert "errors" not in data
assert "data" in data
user = data["data"]["updateUser"]
assert user["name"] == "Yogesh Singh"
def test_delete_user():
query = """
mutation {
deleteUser(id: 1) {
id
name
}
}
"""
response = requests.post(f"{BASE_URL}/graphql", json={"query": query})
assert response.status_code == 200
data = response.json()
assert "errors" not in data
assert "data" in data
user = data["data"]["deleteUser"]
assert user["name"] == "Shikha Pandey"
def test_get_all_users():
query = """
query {
users {
id
name
}
}
"""
response = requests.post(f"{BASE_URL}/graphql", json={"query": query})
assert response.status_code == 200
data = response.json()
assert "errors" not in data
assert "data" in data
users = data["data"]["users"]
print(users)
assert len(users) > 0
def test_get_user_by_id():
query = """
query {
user(id: 1) {
id
name
}
}
"""
response = requests.post(f"{BASE_URL}/graphql", json={"query": query})
assert response.status_code == 200
data = response.json()
assert "errors" not in data
assert "data" in data
user = data["data"]["user"]
assert len(user) > 0
# Run the test cases
test_create_user()
test_update_user()
test_delete_user()
test_get_all_users()
test_get_user_by_id()