mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-31 08:25:35 +00:00
provisioning.py: get full test coverage
This commit is contained in:
parent
941d1551a0
commit
79bd7d422d
@ -18,14 +18,11 @@ def factorial(n):
|
|||||||
result = 1
|
result = 1
|
||||||
for i in xrange(1, abs(n)+1):
|
for i in xrange(1, abs(n)+1):
|
||||||
result *= i
|
result *= i
|
||||||
if n >= 0:
|
assert n >= 0
|
||||||
return result
|
return result
|
||||||
else:
|
|
||||||
return -result
|
|
||||||
|
|
||||||
def binomial(n, k):
|
def binomial(n, k):
|
||||||
if not 0 <= k <= n:
|
assert 0 <= k <= n
|
||||||
return 0
|
|
||||||
if k == 0 or k == n:
|
if k == 0 or k == n:
|
||||||
return 1
|
return 1
|
||||||
# calculate n!/k! as one product, avoiding factors that
|
# calculate n!/k! as one product, avoiding factors that
|
||||||
@ -78,12 +75,12 @@ class ProvisioningTool(rend.Page):
|
|||||||
def add_input(section, text, entry):
|
def add_input(section, text, entry):
|
||||||
if section not in sections:
|
if section not in sections:
|
||||||
sections[section] = []
|
sections[section] = []
|
||||||
sections[section].append(T.div[text, ": ", entry])
|
sections[section].extend([T.div[text, ": ", entry], "\n"])
|
||||||
|
|
||||||
def add_output(section, entry):
|
def add_output(section, entry):
|
||||||
if section not in sections:
|
if section not in sections:
|
||||||
sections[section] = []
|
sections[section] = []
|
||||||
sections[section].append(T.div[entry])
|
sections[section].extend([entry, "\n"])
|
||||||
|
|
||||||
def build_section(section):
|
def build_section(section):
|
||||||
return T.fieldset[T.legend[section], sections[section]]
|
return T.fieldset[T.legend[section], sections[section]]
|
||||||
|
@ -6,7 +6,7 @@ from twisted.trial import unittest
|
|||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from twisted.web import client, error, http
|
from twisted.web import client, error, http
|
||||||
from twisted.python import failure, log
|
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.encode import NotEnoughPeersError
|
||||||
from allmydata.util import fileutil
|
from allmydata.util import fileutil
|
||||||
import itertools
|
import itertools
|
||||||
@ -406,6 +406,13 @@ class Web(WebMixin, unittest.TestCase):
|
|||||||
d.addCallback(_check2)
|
d.addCallback(_check2)
|
||||||
return d
|
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):
|
def test_provisioning(self):
|
||||||
d = self.GET("/provisioning/")
|
d = self.GET("/provisioning/")
|
||||||
def _check(res):
|
def _check(res):
|
||||||
@ -429,7 +436,32 @@ class Web(WebMixin, unittest.TestCase):
|
|||||||
def _check2(res):
|
def _check2(res):
|
||||||
self.failUnless('Tahoe Provisioning Tool' in res)
|
self.failUnless('Tahoe Provisioning Tool' in res)
|
||||||
self.failUnless("Share space consumed: 167.01TB" 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)
|
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
|
return d
|
||||||
|
|
||||||
def test_start_html(self):
|
def test_start_html(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user