-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_main.py
More file actions
61 lines (51 loc) · 1.37 KB
/
test_main.py
File metadata and controls
61 lines (51 loc) · 1.37 KB
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
from fastapi.testclient import TestClient
from App.main import app
from Test import Main
from App.Config.Database import DatabaseSession
client = TestClient(app)
graph_url = "/graphql"
db = DatabaseSession("sqlite+aiosqlite:///database.db")
app.dependency_overrides[DatabaseSession] = db
def clientMap(func):
def wrapper(*args, **kwargs):
func(client, graph_url, *args, **kwargs)
return wrapper
def test_read_main():
Main.test_read_main(client)
email = "test3@mail.com"
password = "test"
@clientMap
def test_auth(client, url):
query = '''
mutation {
register(registerInput: {
username: "test", email: "''' + email + '''", password: "''' + password + '''"
}) {
success
message
}
}
'''
response = client.post(url, json={"query": query})
assert response.status_code == 200
assert "data" in response.json()
assert "register" in response.json()["data"]
assert "success" in response.json()["data"]["register"]
@clientMap
def test_login(client, url):
query = '''
mutation {
login(loginInput: {
email: "''' + email + '''", password: "''' + password + '''"
}) {
email
token
}
}
'''
response = client.post(url, json={"query": query})
assert response.status_code == 200
assert "data" in response.json()
assert "login" in response.json()["data"]
assert "email" in response.json()["data"]["login"]
assert "token" in response.json()["data"]["login"]