diff --git a/files/tests/test_basic.py b/files/tests/test_basic.py index 676cd78b0..15b017609 100644 --- a/files/tests/test_basic.py +++ b/files/tests/test_basic.py @@ -52,3 +52,22 @@ def test_post_and_comment(accounts): post_response = client.get(post.url) assert post_response.status_code == 200 assert comment_body in post_response.text + + # yank the ID out again + comment = util.ItemData.from_json(submit_comment_response.text) + + # post a comment grandchild! + grandcomment_body = util.generate_text() + submit_grandcomment_response = client.post("/comment", data={ + "parent_fullname": comment.id_full, + "parent_level": 1, + "submission": comment.id, + "body": grandcomment_body, + "formkey": util.formkey_from(submit_post_response.text), + }) + assert submit_grandcomment_response.status_code == 200 + + # verify it actually got posted + post_response = client.get(post.url) + assert post_response.status_code == 200 + assert grandcomment_body in post_response.text diff --git a/files/tests/util.py b/files/tests/util.py index efc990211..3caf08c18 100644 --- a/files/tests/util.py +++ b/files/tests/util.py @@ -1,5 +1,6 @@ from bs4 import BeautifulSoup +import json import random import re import string @@ -34,3 +35,20 @@ class ItemData: result.id_full = f"t2_{result.id}" result.url = url return result + + @staticmethod + def from_json(text): + data = json.loads(text) + + soup = BeautifulSoup(data["comment"], 'html.parser') + divid = soup.find("div")["id"] + + match = re.search(r'comment-(\d+)', divid) + if match is None: + return None + + result = ItemData() + result.id = match.group(1) # this really should get yanked out of the JS, not the HTML + result.id_full = f"t3_{result.id}" + result.url = f"/comment/{result.id}" + return result