This repository was archived by the owner on May 26, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathtest_content_api.py
More file actions
94 lines (76 loc) · 2.78 KB
/
test_content_api.py
File metadata and controls
94 lines (76 loc) · 2.78 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def test_content_create(api_client_authenticated):
response = api_client_authenticated.post(
"/content/",
json={
"title": "hello test",
"text": "this is just a test",
"published": True,
"tags": ["test", "hello"],
},
)
assert response.status_code == 200
result = response.json()
assert result["slug"] == "hello-test"
def test_content_list(api_client_authenticated):
response = api_client_authenticated.get("/content/")
assert response.status_code == 200
result = response.json()
assert result[0]["slug"] == "hello-test"
def test_content_get_individual(api_client_authenticated):
response = api_client_authenticated.get("/content/hello-test")
assert response.status_code == 200
result = response.json()
assert result["slug"] == "hello-test"
def test_content_get_individual_404(api_client_authenticated):
response = api_client_authenticated.get("/content/does-not-exist/")
assert response.status_code == 404
def test_content_update(api_client_authenticated):
response = api_client_authenticated.post(
"/content/",
json={
"title": "Test Post 2 for Patch",
"text": "this is just a test",
"published": True,
"tags": ["test", "hello"],
},
)
assert response.status_code == 200
result = response.json()
assert result["slug"] == "test-post-2-for-patch"
response2 = api_client_authenticated.patch(
f"/content/{result['id']}/",
json={
"published": "false",
},
)
assert response2.status_code == 200
result2 = response2.json()
assert result["slug"] == result2["slug"]
assert result["text"] == result2["text"]
assert result["tags"] == result2["tags"]
assert result["published"] != result2["published"]
def test_content_update_404(api_client_authenticated):
response = api_client_authenticated.patch(
"/content/999/",
json={
"published": "false",
},
)
assert response.status_code == 404
def test_content_update_unauthorized(api_client_not_superuser):
response = api_client_not_superuser.patch(
"/content/1/",
json={
"published": "false",
},
)
assert response.status_code == 403
def test_content_delete_404(api_client_authenticated):
response = api_client_authenticated.delete("/content/999/")
assert response.status_code == 404
def test_content_delete_unauthorized(api_client_not_superuser):
response = api_client_not_superuser.delete("/content/2/")
assert response.status_code == 403
def test_content_delete(api_client_authenticated):
response = api_client_authenticated.delete("/content/2/")
assert response.status_code == 200