]> git.scottworley.com Git - paperdoorknob/commitdiff
next_thread should be an absolute URL
authorScott Worley <scottworley@scottworley.com>
Fri, 26 Jan 2024 02:09:18 +0000 (18:09 -0800)
committerScott Worley <scottworley@scottworley.com>
Fri, 26 Jan 2024 02:09:18 +0000 (18:09 -0800)
glowfic.py
glowfic_test.py

index 81a5342c2621d434dd320eb2104fb98d8eb34841..9d863c887e2992cd8bbdbc4d1a8a1ddffce65155 100644 (file)
@@ -7,7 +7,7 @@
 
 from dataclasses import dataclass
 import itertools
 
 from dataclasses import dataclass
 import itertools
-from urllib.parse import parse_qsl, urlencode, urlparse, urlunparse
+from urllib.parse import parse_qsl, urlencode, urljoin, urlparse, urlunparse
 
 from typing import Iterable
 
 
 from typing import Iterable
 
@@ -63,7 +63,7 @@ class Thread:
                 for a in c.findChildren('a'):
                     if 'Next Post' in a.text and 'href' in a.attrs and isinstance(
                             a.attrs['href'], str):
                 for a in c.findChildren('a'):
                     if 'Next Post' in a.text and 'href' in a.attrs and isinstance(
                             a.attrs['href'], str):
-                        return a.attrs['href']
+                        return urljoin(spec.url, a.attrs['href'])
             return None
 
         spec.log('Fetching HTML...\r')
             return None
 
         spec.log('Fetching HTML...\r')
index 22eea257c21d4fe4d9b7776fdd159b579a8016f8..bd26e3c9dfc5bc0ee4ec02eead21e34bdca42689 100644 (file)
@@ -103,7 +103,7 @@ class TestThread(unittest.TestCase):
             </body></html>'''))
         self.assertEqual(t.title(), 'Teh Story!')
 
             </body></html>'''))
         self.assertEqual(t.title(), 'Teh Story!')
 
-    def testNextThread(self) -> None:
+    def testNextThreadRelative(self) -> None:
         t = Thread(spec_for_testing(b'''
             <html><body>
               <div class="post-navheader">
         t = Thread(spec_for_testing(b'''
             <html><body>
               <div class="post-navheader">
@@ -113,7 +113,19 @@ class TestThread(unittest.TestCase):
               </div>
               <div class="post-container post-post">The "post"</div>
             </body></html>'''))
               </div>
               <div class="post-container post-post">The "post"</div>
             </body></html>'''))
-        self.assertEqual(t.next_thread(), '/posts/4567')
+        self.assertEqual(t.next_thread(), 'https://fake/posts/4567')
+
+    def testNextThreadAbsolute(self) -> None:
+        t = Thread(spec_for_testing(b'''
+            <html><body>
+              <div class="post-navheader">
+                <a class="view-button-link" href="https://elsewhere/posts/4567"><div class="view-button">Next Post &raquo;</div>
+                </a><a class="view-button-link" href="https://elsewhere/posts/4321"><div class="view-button float-none">&laquo; Previous Post</div>
+                </a>
+              </div>
+              <div class="post-container post-post">The "post"</div>
+            </body></html>'''))
+        self.assertEqual(t.next_thread(), 'https://elsewhere/posts/4567')
 
 
 if __name__ == '__main__':
 
 
 if __name__ == '__main__':