1 | #!/usr/bin/python |
---|
2 | |
---|
3 | import unittest |
---|
4 | from mock import Mock, patch, sentinel |
---|
5 | |
---|
6 | from allmydata.introducer.client import IntroducerClient |
---|
7 | from allmydata.client import Client, MULTI_INTRODUCERS_CFG |
---|
8 | |
---|
9 | |
---|
10 | class TestClient(unittest.TestCase): |
---|
11 | |
---|
12 | def setUp(self): |
---|
13 | pass |
---|
14 | # set-up two introducers and few clients |
---|
15 | |
---|
16 | def tearDown(self): |
---|
17 | pass |
---|
18 | # shut-down introducers and clients |
---|
19 | |
---|
20 | @patch('allmydata.introducer.client.IntroducerClient') |
---|
21 | def test_introducer_clients_count(self, MockIntroducerClient): |
---|
22 | MockIntroducerClient.return_value = sentinel.IntroducerClient |
---|
23 | |
---|
24 | # See how many introducers are listed in "introducers" cfgfile |
---|
25 | furls = 1 # default introducer_furl from tahoe.cfg |
---|
26 | f = open(MULTI_INTRODUCERS_CFG, 'r') |
---|
27 | for introducer_furl in f.read().split('\n'): |
---|
28 | if not introducer_furl.strip(): |
---|
29 | continue |
---|
30 | furls += 1 |
---|
31 | f.close() |
---|
32 | |
---|
33 | # get a client and count of introducer_clients |
---|
34 | myclient = Client() |
---|
35 | ic_count = len(myclient.introducer_clients) |
---|
36 | |
---|
37 | self.assertEquals(furls, ic_count) |
---|
38 | |
---|
39 | if __name__ == "__main__": |
---|
40 | unittest.main() |
---|