printpub/tests/post/views/post_test.py

34 lines
1.2 KiB
Python

import rest_framework.test
import printpub.post.models
import printpub.user.models
class TestPostGet:
def test_getting_nonexistent_post_returns_404(self):
client = rest_framework.test.APIClient()
res = client.get("/post/1234")
assert res.status_code == 404
def test_get_200_with_existing_post(self):
poster = printpub.user.models.Poster()
poster.save()
user = printpub.user.models.LocalUser(
username="wint", password="hunter2", display_name="dril", poster=poster
)
user.save()
post = printpub.post.models.Post(
author=poster,
content='"im not owned! im not owned!!", i continue to insist as i slowly shrink and transform into a corn cob',
)
post.save()
client = rest_framework.test.APIClient()
res = client.get(f"/post/{post.pk}")
assert res.status_code == 200
# More data is validated by the serializer, this is just a sanity check
assert (
res.data["content"]
== '"im not owned! im not owned!!", i continue to insist as i slowly shrink and transform into a corn cob'
)