-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_main.py
119 lines (79 loc) · 3.91 KB
/
test_main.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import json
import os
from uuid import UUID
from fastapi.testclient import TestClient
from _tests.tests import run_tests, test_admin_user, post, new_response, new_post
from main import app
from models.posts import NewResponse, NewPost
from services.db.deta.postsDB import delete_post_permanently_db
from services.db.deta.userDB import permanently_delete_user_from_db
from services.user import get_user
client = TestClient(app)
user = test_admin_user
@app.delete("/users/{username}/", include_in_schema=False)
async def delete_user(username):
if username == user['username']:
userd = await get_user(username)
if userd is None:
return "User didn't Exists"
await permanently_delete_user_from_db(userd)
return "success"
else:
return "Invalid Operation"
@app.delete("/posts/delete/{post_id}/", include_in_schema=False)
async def delete_post(post_id: UUID):
if str(post_id) == post['key']:
await delete_post_permanently_db(post_id.hex)
# def test_read_main():
# response = client.get("/test/")
# assert response.status_code == 200
# assert response.json() == "Ok"
# def test_read_item_bad_token():
# response = client.post("/posts/all/", headers={"Authorization": "invalid_token"})
# assert response.status_code == 401
# assert response.json() == {"detail": "Not authenticated"}
# def test_validation_and_models():
# run_tests()
# def test_delete_test_user():
# response = client.delete(f"/users/{user['username']}/")
# assert response.status_code == 200
# def test_create_new_user():
# response = client.post("/users/new/", data=json.dumps(user))
# assert response.status_code == 200
# def test_get_jwt():
# response = client.post("/token", data={"username": user['username'], "password": user['password']})
# os.environ['TOKEN'] = response.json()['access_token']
# assert response.status_code == 200
# def test_get_my_details():
# response = client.get("/users/me/", headers={"Authorization": f"Bearer {os.getenv('TOKEN')}"})
# assert response.status_code == 200
# def test_get_all_users():
# response = client.post("/posts/all/", headers={"Authorization": f"Bearer {os.getenv('TOKEN')}"})
# assert response.status_code == 200
# def test_remove_the_post():
# response = client.delete(f"/posts/delete/{post['key']}/", headers={"Authorization": f"Bearer {os.getenv('TOKEN')}"})
# assert response.status_code == 200
# def test_create_new_post():
# response = client.post("/posts/new/", data=NewPost(**new_post).json(), headers={"Authorization": f"Bearer {os.getenv('TOKEN')}"})
# assert response.status_code == 200
# def test_get_single_post():
# response = client.get(f"/posts/{post['key']}/", headers={"Authorization": f"Bearer {os.getenv('TOKEN')}"})
# assert response.status_code == 200
# def test_get_all_post():
# response = client.post("/posts/all/", headers={"Authorization": f"Bearer {os.getenv('TOKEN')}"})
# assert response.status_code == 200
# def test_delete_single_post():
# response = client.delete(f"/posts/{post['key']}/", headers={"Authorization": f"Bearer {os.getenv('TOKEN')}"})
# assert response.status_code == 200
# def test_add_new_response():
# response = client.post(f"/posts/response/new/", data=NewResponse(**new_response).json(), headers={"Authorization": f"Bearer {os.getenv('TOKEN')}"})
# assert response.status_code == 200
# def test_delete_response():
# response = client.delete(f"/posts/{post['key']}/response/0/", headers={"Authorization": f"Bearer {os.getenv('TOKEN')}"})
# assert response.status_code == 200
# def test_clean_the_post():
# response = client.delete(f"/posts/delete/{post['key']}/", headers={"Authorization": f"Bearer {os.getenv('TOKEN')}"})
# assert response.status_code == 200
# def test_clean_test_user():
# response = client.delete(f"/users/{user['username']}/")
# assert response.status_code == 200