tahoe-lafs/src/allmydata/test/test_client.py

53 lines
1.9 KiB
Python
Raw Normal View History

2006-11-30 23:23:01 +00:00
import os
2006-11-30 23:23:01 +00:00
from twisted.trial import unittest
import allmydata
2007-03-30 03:19:52 +00:00
from allmydata import client, introducer
from allmydata.util import version
2006-11-30 23:23:01 +00:00
2007-03-30 03:19:52 +00:00
class MyIntroducerClient(introducer.IntroducerClient):
def __init__(self):
self.connections = {}
2007-03-30 03:19:52 +00:00
def permute(c, key):
return [ y for x, y, z in c.get_permuted_peers(key) ]
2006-11-30 23:23:01 +00:00
class Basic(unittest.TestCase):
2006-12-01 03:18:51 +00:00
def test_loadable(self):
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):
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("")
2007-03-30 03:19:52 +00:00
c = client.Client(basedir)
c.introducer_client = MyIntroducerClient()
for k in ["%d" % i for i in range(5)]:
2007-03-30 03:19:52 +00:00
c.introducer_client.connections[k] = None
self.failUnlessEqual(permute(c, "one"), ['3','1','0','4','2'])
self.failUnlessEqual(permute(c, "two"), ['0','4','2','1','3'])
c.introducer_client.connections.clear()
self.failUnlessEqual(permute(c, "one"), [])
c2 = client.Client(basedir)
c2.introducer_client = MyIntroducerClient()
for k in ["%d" % i for i in range(5)]:
2007-03-30 03:19:52 +00:00
c2.introducer_client.connections[k] = None
self.failUnlessEqual(permute(c2, "one"), ['3','1','0','4','2'])
def test_versions(self):
basedir = "test_client.Basic.test_versions"
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)
mine, oldest = c.remote_get_versions()
self.failUnlessEqual(version.Version(mine), allmydata.__version__)