2006-11-30 23:23:01 +00:00
|
|
|
|
2007-03-27 23:12:11 +00:00
|
|
|
import os
|
2006-11-30 23:23:01 +00:00
|
|
|
from twisted.trial import unittest
|
|
|
|
|
|
|
|
from allmydata import client
|
|
|
|
|
2007-03-27 23:12:11 +00:00
|
|
|
class MyClient(client.Client):
|
|
|
|
def __init__(self, basedir):
|
|
|
|
self.connections = {}
|
|
|
|
client.Client.__init__(self, basedir)
|
|
|
|
|
|
|
|
def get_all_peerids(self):
|
|
|
|
return self.connections
|
|
|
|
|
2006-11-30 23:23:01 +00:00
|
|
|
class Basic(unittest.TestCase):
|
2006-12-01 03:18:51 +00:00
|
|
|
def test_loadable(self):
|
2007-03-27 23:12:11 +00:00
|
|
|
basedir = "test_client.Basic.test_loadable"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
c = client.Client(basedir)
|
2006-11-30 23:23:01 +00:00
|
|
|
|
2006-12-01 03:18:51 +00:00
|
|
|
def test_permute(self):
|
2007-03-27 23:12:11 +00:00
|
|
|
basedir = "test_client.Basic.test_permute"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
c = MyClient(basedir)
|
2007-03-23 23:15:57 +00:00
|
|
|
for k in ["%d" % i for i in range(5)]:
|
|
|
|
c.connections[k] = None
|
2006-12-01 03:18:51 +00:00
|
|
|
self.failUnlessEqual(c.permute_peerids("one"), ['3','1','0','4','2'])
|
|
|
|
self.failUnlessEqual(c.permute_peerids("one", 3), ['3','1','0'])
|
|
|
|
self.failUnlessEqual(c.permute_peerids("two"), ['0','4','2','1','3'])
|
2007-03-23 23:15:57 +00:00
|
|
|
c.connections.clear()
|
2006-12-01 03:18:51 +00:00
|
|
|
self.failUnlessEqual(c.permute_peerids("one"), [])
|
2007-01-16 04:22:22 +00:00
|
|
|
|
2007-03-27 23:12:11 +00:00
|
|
|
c2 = MyClient(basedir)
|
2007-03-23 23:15:57 +00:00
|
|
|
for k in ["%d" % i for i in range(5)]:
|
|
|
|
c2.connections[k] = None
|
2007-01-16 04:22:22 +00:00
|
|
|
self.failUnlessEqual(c2.permute_peerids("one"), ['3','1','0','4','2'])
|
|
|
|
|