aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_api_post.py
blob: 48436ab7829c9e5a7b09beebaa68045b53db8c5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import requests

BASE = "https://jsonplaceholder.typicode.com"

def test_post_create_post_status_201():
    payload = {"title": "qa test", "body": "automated test run", "userId": 1}
    r = requests.post(f"{BASE}/posts", json=payload)
    assert r.status_code == 201
    assert r.json()["title"] == "qa test"

def test_post_create_post_missing_title():
    payload = {"body": "no title field", "userId": 1}
    r = requests.post(f"{BASE}/posts", json=payload)
    assert r.status_code == 201
    assert "id" in r.json()

def test_post_create_post_empty_payload():
    payload = {}
    r = requests.post(f"{BASE}/posts", json=payload)
    assert r.status_code == 201
    assert "id" in r.json()