diff tests/conftest.py @ 18:a921cc2306bc

Do our own HTML parsing/stripping of micropost contents. - This lets us properly handle various forms of linking. - Add tests for processing posts with links. - Fix configuration in tests. - Basic error handling for processing posts.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 16 Sep 2018 21:16:20 -0700
parents a1b7a459326a
children d3c4c5082bbc
line wrap: on
line diff
--- a/tests/conftest.py	Mon Jul 30 18:19:04 2018 -0700
+++ b/tests/conftest.py	Sun Sep 16 21:16:20 2018 -0700
@@ -47,6 +47,7 @@
 [cache]
 uri=memory://for_test
 """
+        self._feedcfg = []
         self._pre_hooks = []
         self._cleanup = []
 
@@ -70,6 +71,14 @@
         self._cfgtxt += cfgtxt
         return self
 
+    def appendFeedConfig(self, feed_name, feed_url):
+        self._feedcfg.append((feed_name, feed_url))
+        return self
+
+    def setFeedConfig(self, feed_name, feed_url):
+        self._feedcfg = []
+        return self.appendFeedConfig(feed_name, feed_url)
+
     def appendSiloConfig(self, silo_name, silo_type, **options):
         cfgtxt = '[silo:%s]\n' % silo_name
         cfgtxt += 'type=%s\n' % silo_type
@@ -83,11 +92,16 @@
 
     def run(self, *args):
         pre_args = []
-        if self._cfgtxt:
+        if self._cfgtxt or self._feedcfg:
+            cfgtxt = self._cfgtxt
+            cfgtxt += '\n\n[urls]\n'
+            for n, u in self._feedcfg:
+                cfgtxt += '%s=%s\n' % (n, u)
+
             tmpfd, tmpcfg = tempfile.mkstemp()
             print("Creating temporary configuration file: %s" % tmpcfg)
             with os.fdopen(tmpfd, 'w') as tmpfp:
-                tmpfp.write(self._cfgtxt)
+                tmpfp.write(cfgtxt)
             self._cleanup.append(tmpcfg)
             pre_args = ['-c', tmpcfg]
 
@@ -124,7 +138,10 @@
 
             print("Cleaning %d temporary files." % len(self._cleanup))
             for tmpname in self._cleanup:
-                os.remove(tmpname)
+                try:
+                    os.remove(tmpname)
+                except FileNotFoundError:
+                    pass
 
         return main_ctx, main_res