]> git.scottworley.com Git - paperdoorknob/commitdiff
Replies
authorScott Worley <scottworley@scottworley.com>
Fri, 24 Nov 2023 03:32:52 +0000 (19:32 -0800)
committerScott Worley <scottworley@scottworley.com>
Wed, 20 Dec 2023 01:37:10 +0000 (17:37 -0800)
paperdoorknob.py
paperdoorknob_test.py

index b88c02d73e64a604763ad5c8ca8785055496d53f..0c6ec856b50377f1b895a2dfe2d9681badf93dba 100644 (file)
@@ -7,6 +7,9 @@
 
 from argparse import ArgumentParser
 import os.path
+
+from typing import Iterable
+
 from bs4 import BeautifulSoup
 from bs4.element import Tag
 import requests
@@ -25,6 +28,11 @@ class Post:
         assert isinstance(text, Tag)
         return text
 
+    def replies(self) -> Iterable[Tag]:
+        replies = self._html.find_all("div", class_="post-reply")
+        assert all(isinstance(r, Tag) for r in replies)
+        return replies
+
 
 def command_line_parser() -> ArgumentParser:
     parser = ArgumentParser(prog='paperdoorknob', description='Print glowfic')
index 83cf76ad4c9f17f7ac43150db9dbc3e62d7ea66e..7c486079818f73058a47e181de41eca4ef4e1e08 100644 (file)
@@ -33,6 +33,14 @@ class FakeGlowficHTTPRequestHandler(BaseHTTPRequestHandler):
     <div class="post-container post-post">
       This is glowfic
     </div>
+    <div class="flat-post-replies">
+      <div class="post-container post-reply">
+        You sure?
+      </div>
+      <div class="post-container post-reply">
+        Pretty sure.
+      </div>
+    </div>
   </body>
 </html>'''
         self.send_response(self._response_code())
@@ -92,6 +100,8 @@ class TestFetch(unittest.TestCase):
             post = paperdoorknob.Post(paperdoorknob.fetch(
                 f"http://localhost:{self._port()}", s, TIMEOUT))
             self.assertEqual(post.text().text.strip(), "This is glowfic")
+            self.assertEqual([r.text.strip() for r in post.replies()],
+                             ["You sure?", "Pretty sure."])
 
     def testFetchErrors(self) -> None:
         with requests.session() as s: