All checks were successful
Build and Push to Private Registry101 / build (push) Successful in 8s
Co-authored-by: stephen schuresko <mynameisdeleted@gmail.com> Reviewed-on: https://192.168.1.134:3000/posts-api/papi-py/pulls/6
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from papi import app
|
|
client = TestClient(app)
|
|
|
|
def test_read_post():
|
|
response = client.get("/posts")
|
|
assert response.status_code == 200
|
|
assert response.json() != None
|
|
|
|
def test_create_post():
|
|
response = client.post("/posts",json={"title":"test title","content":"testing123","author_id":"1"})
|
|
assert response.status_code == 200
|
|
post=response.json()['post']
|
|
assert post['title'] == "test title"
|
|
assert post['content'] == "testing123"
|
|
assert post['author_id'] == 1
|
|
client.delete("/posts/"+str(post['id']))
|
|
|
|
|
|
def test_create_read_delete_post():
|
|
first_posts = client.get("/posts").json()
|
|
|
|
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() == first_posts |