feat: add user and post management with CRUD operations; include tests for functionality
All checks were successful
Build and Push to Private Registry101 / build (push) Successful in 10s
All checks were successful
Build and Push to Private Registry101 / build (push) Successful in 10s
This commit is contained in:
65
test_papi.py
65
test_papi.py
@@ -11,69 +11,4 @@ def test_read_main():
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"message": "Hello World"}
|
||||
|
||||
def test_read_users():
|
||||
response = client.get("/users")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == []
|
||||
|
||||
|
||||
def test_create_read_delete_user():
|
||||
|
||||
response = client.post("/users",json={"name":"test","email":"mynameisdeleted@gmail.com","password":"pass2"})
|
||||
assert response.status_code == 200
|
||||
user=response.json()['user']
|
||||
user_id = str(user['id'])
|
||||
response = client.get("/users/"+user_id)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == user
|
||||
|
||||
update_response = client.put("/users/"+user_id,json={"name":"updated name"})
|
||||
#assert update_respose.status_code == 200
|
||||
put_user = update_response.json()['user']
|
||||
assert put_user['name'] == "updated name"
|
||||
|
||||
update_response = client.put("/users/"+user_id,json={"email":"updated@gmail.com"})
|
||||
|
||||
put_user = update_response.json()['user']
|
||||
assert put_user['email'] == "updated@gmail.com"
|
||||
|
||||
|
||||
response = client.delete("/users/"+user_id)
|
||||
assert response.status_code == 200
|
||||
|
||||
response = client.get("/users")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == []
|
||||
|
||||
|
||||
|
||||
|
||||
def test_create_read_delete_post():
|
||||
|
||||
|
||||
response = client.post("/posts",json={"title":"test title","content":"testing123","author_id":"1"})
|
||||
assert response.status_code == 200
|
||||
post=response.json()['post']
|
||||
post_id = str(post['id'])
|
||||
response = client.get("/posts/"+post_id)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == post
|
||||
|
||||
update_response = client.put("/posts/"+post_id,json={"title":"test title updated"})
|
||||
#assert update_respose.status_code == 200
|
||||
put_post = update_response.json()['post']
|
||||
assert put_post['title'] == "test title updated"
|
||||
|
||||
|
||||
update_response = client.put("/posts/"+post_id,json={"content":"updated content"})
|
||||
#assert update_respose.status_code == 200
|
||||
put_post = update_response.json()['post']
|
||||
assert put_post['title'] == "test title updated"
|
||||
assert put_post['content'] == "updated content"
|
||||
|
||||
response = client.delete("/posts/"+post_id)
|
||||
assert response.status_code == 200
|
||||
|
||||
response = client.get("/posts")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == []
|
||||
Reference in New Issue
Block a user