diff tests/mockutil.py @ 322:7544c03b6bab

tests: Add utility function to create multiple mock pages in one go.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 29 Mar 2015 23:04:12 -0700
parents 1d44d8bd93e2
children 2a5996e0d3ec
line wrap: on
line diff
--- a/tests/mockutil.py	Sat Mar 28 14:26:14 2015 -0700
+++ b/tests/mockutil.py	Sun Mar 29 23:04:12 2015 -0700
@@ -140,6 +140,25 @@
         return self.withAsset('%s/%s' % (dirname, name),
                 contents)
 
+    def withPages(self, num, url_factory, config_factory=None,
+                  contents_factory=None):
+        for i in range(num):
+            if isinstance(url_factory, str):
+                url = url_factory.format(idx=i, idx1=(i + 1))
+            else:
+                url = url_factory(i)
+
+            config = None
+            if config_factory:
+                config = config_factory(i)
+
+            contents = None
+            if contents_factory:
+                contents = contents_factory(i)
+
+            self.withPage(url, config, contents)
+        return self
+
     def getStructure(self, path=None):
         root = self._fs[self._root]
         if path: