Refactor test system to be more extendable, add comment test

This commit is contained in:
Ben Rog-Wilhelm 2022-12-17 17:41:35 -08:00 committed by GitHub
parent 23a8fb9663
commit e257db1542
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 147 additions and 59 deletions

54
files/tests/test_basic.py Normal file
View file

@ -0,0 +1,54 @@
from . import fixture_accounts
from . import util
def test_rules(accounts):
response = accounts.logged_off().get("/rules")
assert response.status_code == 200
assert response.text.startswith("<!DOCTYPE html>")
def test_post_and_comment(accounts):
client = accounts.client_for_account()
# get our formkey
submit_get_response = client.get("/submit")
assert submit_get_response.status_code == 200
# make the post
post_title = util.generate_text()
post_body = util.generate_text()
submit_post_response = client.post("/submit", data={
"title": post_title,
"body": post_body,
"formkey": util.formkey_from(submit_get_response.text),
})
assert submit_post_response.status_code == 200
assert post_title in submit_post_response.text
assert post_body in submit_post_response.text
# verify it actually got posted
root_response = client.get("/")
assert root_response.status_code == 200
assert post_title in root_response.text
assert post_body in root_response.text
# yank the ID out
post = util.ItemData.from_html(submit_post_response.text)
# post a comment child
comment_body = util.generate_text()
submit_comment_response = client.post("/comment", data={
"parent_fullname": post.id_full,
"parent_level": 1,
"submission": post.id,
"body": comment_body,
"formkey": util.formkey_from(submit_post_response.text),
})
assert submit_comment_response.status_code == 200
# verify it actually got posted
post_response = client.get(post.url)
assert post_response.status_code == 200
assert comment_body in post_response.text