-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_blog.py
More file actions
35 lines (24 loc) · 992 Bytes
/
test_blog.py
File metadata and controls
35 lines (24 loc) · 992 Bytes
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
from app import create_app
# new client to send test requests
def make_client():
# TESTING = true ->>> better error messages no server running to check this....
app = create_app({"TESTING": True})
return app.test_client()
def test_home():
client = make_client()
res = client.get("/")
assert res.status_code == 200
assert res.get_json() ["message"] == "Welcome to our Blog for testing"
def test_list_empty():
client = make_client()
res = client.get("/posts")
data = res.get_json()
assert res.status_code == 200
assert data == {"posts": []}
# need to check post id too (you can try on your own if you like will update the code soon :)
# def test_create_and_gest_post():
# client = make_client()
# res = client.get("/posts", json={"title": "Hello", "body": "Hey MY first blog"})
# assert res.status_code == 201
# post =res.get_json()["post"]
# assert post["title"] == "Hello"