]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
provisioning.py: get full test coverage
authorBrian Warner <warner@lothar.com>
Mon, 17 Sep 2007 08:38:54 +0000 (01:38 -0700)
committerBrian Warner <warner@lothar.com>
Mon, 17 Sep 2007 08:38:54 +0000 (01:38 -0700)
src/allmydata/provisioning.py
src/allmydata/test/test_web.py

index 93164e876a60a663da84a74bf10192563a81579f..adcfbee6860e487eb2c472cdcf5bcdf08a84a3cf 100644 (file)
@@ -18,14 +18,11 @@ def factorial(n):
     result = 1
     for i in xrange(1, abs(n)+1):
         result *= i
-    if n >= 0:
-        return result
-    else:
-        return -result
+    assert n >= 0
+    return result
 
 def binomial(n, k):
-    if not 0 <= k <= n:
-        return 0
+    assert 0 <= k <= n
     if k == 0 or k == n:
         return 1
     # calculate n!/k! as one product, avoiding factors that
@@ -78,12 +75,12 @@ class ProvisioningTool(rend.Page):
         def add_input(section, text, entry):
             if section not in sections:
                 sections[section] = []
-            sections[section].append(T.div[text, ": ", entry])
+            sections[section].extend([T.div[text, ": ", entry], "\n"])
 
         def add_output(section, entry):
             if section not in sections:
                 sections[section] = []
-            sections[section].append(T.div[entry])
+            sections[section].extend([entry, "\n"])
 
         def build_section(section):
             return T.fieldset[T.legend[section], sections[section]]
index 83d73e8adfbc641a727137489546a4cbb79adf4c..82bb61b40e7375fd6e6a68c0beeb0f39303395f6 100644 (file)
@@ -6,7 +6,7 @@ from twisted.trial import unittest
 from twisted.internet import defer
 from twisted.web import client, error, http
 from twisted.python import failure, log
-from allmydata import webish, interfaces, dirnode, uri
+from allmydata import webish, interfaces, dirnode, uri, provisioning
 from allmydata.encode import NotEnoughPeersError
 from allmydata.util import fileutil
 import itertools
@@ -406,6 +406,13 @@ class Web(WebMixin, unittest.TestCase):
         d.addCallback(_check2)
         return d
 
+    def test_provisioning_math(self):
+        self.failUnlessEqual(provisioning.binomial(10, 0), 1)
+        self.failUnlessEqual(provisioning.binomial(10, 1), 10)
+        self.failUnlessEqual(provisioning.binomial(10, 2), 45)
+        self.failUnlessEqual(provisioning.binomial(10, 9), 10)
+        self.failUnlessEqual(provisioning.binomial(10, 10), 1)
+
     def test_provisioning(self):
         d = self.GET("/provisioning/")
         def _check(res):
@@ -429,7 +436,32 @@ class Web(WebMixin, unittest.TestCase):
         def _check2(res):
             self.failUnless('Tahoe Provisioning Tool' in res)
             self.failUnless("Share space consumed: 167.01TB" in res)
+
+            fields = {'filled': True,
+                      "num_users": int(50e6),
+                      "files_per_user": 1000,
+                      "space_per_user": int(5e9),
+                      "sharing_ratio": 1.0,
+                      "encoding_parameters": "25-of-100-50",
+                      "num_servers": 30000,
+                      "ownership_mode": "E",
+                      "drive_failure_model": "U",
+                      "drive_size": 1000,
+                      "download_rate": 1000,
+                      "upload_rate": 100,
+                      "delete_rate": 100,
+                      "lease_timer": 7,
+                      }
+            return self.POST("/provisioning/", **fields)
         d.addCallback(_check2)
+        def _check3(res):
+            self.failUnless("Share space consumed: huge!" in res)
+            fields = {'filled': True}
+            return self.POST("/provisioning/", **fields)
+        d.addCallback(_check3)
+        def _check4(res):
+            self.failUnless("Share space consumed:" in res)
+        d.addCallback(_check4)
         return d
 
     def test_start_html(self):