1 # Written by Arno Bakker, Jie Yang
2 # see LICENSE.txt for license information
12 from traceback import print_exc
14 from M2Crypto import EC
16 from BaseLib.Core.Session import *
17 from BaseLib.Core.SessionConfig import *
22 class TestAsServer(unittest.TestCase):
24 Parent class for testing the server-side of Tribler
28 """ unittest test setup code """
29 self.setUpPreSession()
30 self.session = Session(self.config)
31 self.hisport = self.session.get_listen_port()
32 self.setUpPostSession()
34 def setUpPreSession(self):
35 """ Should set self.config_path and self.config """
36 self.config_path = tempfile.mkdtemp()
38 self.config = SessionStartupConfig()
39 self.config.set_state_dir(self.config_path)
40 self.config.set_listen_port(random.randint(10000, 60000))
41 self.config.set_buddycast(False)
42 self.config.set_start_recommender(False)
43 self.config.set_torrent_checking(False)
44 self.config.set_superpeer(False)
45 self.config.set_dialback(False)
46 self.config.set_social_networking(False)
47 self.config.set_remote_query(False)
48 self.config.set_internal_tracker(False)
49 self.config.set_bartercast(False)
50 self.config.set_multicast_local_peer_discovery(False)
51 # Assume all test scripts are run from Tribler/Test
52 self.config.set_install_dir(os.path.abspath(os.path.join('..','..')))
54 self.my_keypair = EC.gen_params(EC.NID_sect233k1)
55 self.my_keypair.gen_key()
57 def setUpPostSession(self):
58 """ Should set self.his_keypair """
59 keypair_filename = os.path.join(self.config_path,'ec.pem')
60 self.his_keypair = EC.load_key(keypair_filename)
63 """ unittest test tear down code """
64 if self.session is not None:
65 self.session.shutdown()
66 print >>sys.stderr,"test_as_server: sleeping after session shutdown"
69 shutil.rmtree(self.config_path)
71 # Not fatal if something goes wrong here, and Win32 often gives
72 # spurious Permission Denied errors.