Ticket #68: test_multi_introducers.py

File test_multi_introducers.py, 1.2 KB (added by writefaruq, at 2010-07-05T17:45:07Z)

Demo test file that checks if the number of introducer_clients is same as the number of introducers_furls found in "introducers" cfg file

Line 
1#!/usr/bin/python
2
3import unittest
4from mock import Mock, patch, sentinel
5
6from allmydata.introducer.client import IntroducerClient
7from allmydata.client import Client, MULTI_INTRODUCERS_CFG
8
9
10class 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
39if __name__ == "__main__":
40    unittest.main()