qa (#6)
All checks were successful
Build and Push to Private Registry101 / build (push) Successful in 8s
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
This commit was merged in pull request #6.
This commit is contained in:
51
test_posts.py
Normal file
51
test_posts.py
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user