def setUp(self): self._mock_sampler = XmlRPCClientTest._MockedSampler() self._mock_sampler_server =\ NodeSamplerServer(port=8000, sampler=self._mock_sampler) def start_server(): self._mock_sampler_server.start() server_thread = Thread(target=start_server) server_thread.setDaemon(True) server_thread.start() self.xmlrpc_client = XmlRPCClient() self.fake_node_services =\ [Service(name="$$test_service_a$$", ip=TEST_IP, check_methods=TEST_METHOD), Service(name="$$test_service_b$$", ip=TEST_IP, check_methods=TEST_METHOD)] self.expected_respond = [{"name": "$$test_service_a$$", "ip": TEST_IP, "check_methods": TEST_METHOD}, {"name": "$$test_service_b$$", "ip": TEST_IP, "check_methods": TEST_METHOD}]
class XmlRPCClientTest(TestCase): """ The test cases to test the capibility of xmlrpclib. """ def setUp(self): self._mock_sampler = XmlRPCClientTest._MockedSampler() self._mock_sampler_server =\ NodeSamplerServer(port=8000, sampler=self._mock_sampler) def start_server(): self._mock_sampler_server.start() server_thread = Thread(target=start_server) server_thread.setDaemon(True) server_thread.start() self.xmlrpc_client = XmlRPCClient() self.fake_node_services =\ [Service(name="$$test_service_a$$", ip=TEST_IP, check_methods=TEST_METHOD), Service(name="$$test_service_b$$", ip=TEST_IP, check_methods=TEST_METHOD)] self.expected_respond = [{"name": "$$test_service_a$$", "ip": TEST_IP, "check_methods": TEST_METHOD}, {"name": "$$test_service_b$$", "ip": TEST_IP, "check_methods": TEST_METHOD}] def test_connect(self): """ The test case to check the capability of xmlrpclib when "ip" attribute of Service obj is string type. :return: """ node_result = self.xmlrpc_client.connect( ip=TEST_IP, group=TEST_GROUP, port=TEST_PORT, node_services=self.fake_node_services) self.assertEquals(node_result, self.expected_respond) class _MockedSampler(XmlRPCClient): """ The mocked NodeSampler inheriting from NodeSampler of XmlRPCClient contains stubs to check the communication inner status. """ def sample(self, services): return services