Total Complexity | 3 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | #!/usr/bin/python |
||
2 | # -*- coding: utf-8 -*- |
||
3 | import unittest |
||
4 | |||
5 | from tw_serverinfo import MasterServers |
||
6 | |||
7 | |||
8 | class TestMasterServers(unittest.TestCase): |
||
9 | |||
10 | def setUp(self): |
||
11 | """Constructor for the Unit Test |
||
12 | |||
13 | :return: |
||
14 | """ |
||
15 | self.master_servers_module = MasterServers() |
||
16 | |||
17 | def test_master_servers_plain(self): |
||
18 | """Test the function to retrieve the master servers without requesting information from it yet |
||
19 | |||
20 | :return: |
||
21 | """ |
||
22 | self.assertEqual(len(self.master_servers_module._master_servers), 0) |
||
23 | self.master_servers_module.get_master_servers() |
||
24 | self.assertEqual(len(self.master_servers_module._master_servers), |
||
25 | len(self.master_servers_module.master_servers_cfg)) |
||
26 | |||
27 | def test_master_servers_property(self): |
||
28 | """Test the function to retrieve and parse data from the master server |
||
29 | |||
30 | :return: |
||
31 | """ |
||
32 | # assert that we actually got a dictionary |
||
33 | self.assertIsInstance(self.master_servers_module.master_servers, dict) |
||
34 | # check for the keys in the dictionary |
||
35 | self.assertIn('timestamp', self.master_servers_module.master_servers) |
||
36 | self.assertIn('servers', self.master_servers_module.master_servers) |
||
37 | # check length |
||
38 | self.assertEqual(len(self.master_servers_module.master_servers_cfg), |
||
39 | len(self.master_servers_module.master_servers['servers'])) |
||
40 | |||
41 | |||
42 | if __name__ == '__main__': |
||
43 | suite = unittest.TestLoader().loadTestsFromTestCase(TestMasterServers) |
||
44 | unittest.TextTestRunner(verbosity=2).run(suite) |
||
45 |