def setUp(self): self.entry = ListEntry('result', 'C{list} of L{Node}', 'pass', True) self.driver = get_test_driver_instance( CloudStackNodeDriver, { 'secret': 'apikey', 'key': 'user', 'host': 'api.dummy.com', 'path': '/test/path' }) def test_to_json(self): n1 = Node('id1', 'test1', NodeState.RUNNING, None, None, None) n1_json_data = { "public_ips": [], "state": 0, "id": "id1", "name": "test1" } n2 = Node('id2', 'test2', NodeState.PENDING, None, None, None) n2_json_data = { "public_ips": [], "state": 3, "id": "id2", "name": "test2" } self.assertItemsEqual([n1_json_data, n2_json_data], json.loads(self.entry.to_json([n1, n2]))) def test_from_json(self): nodes = '{"result": [{"node_id": "2600"}, {"node_id": "2601"}]}' result = self.entry.from_json(nodes, self.driver) get_node = lambda x: [node for node in result if node.id == x][0] self.assertTrue(get_node('2600')) self.assertTrue(get_node('2601'))
def setUp(self): self.entry = ListEntry('result', 'C{list} of L{Node}', 'pass', True) self.driver = get_test_driver_instance(CloudStackNodeDriver, secret='apikey', key='user', host='api.dummy.com', path='/test/path')
def get_driver_instance_by_request(providers, request): provider_name = request.args.get('provider') headers = request.headers api_data = parse_request_headers(headers) Driver = get_driver_by_provider_name( providers.DRIVERS, providers.Provider, provider_name) if TEST_QUERY_STRING in request.query_string and DEBUG: driver_instance = get_test_driver_instance(Driver, api_data) else: driver_instance = get_driver_instance(Driver, api_data) return driver_instance
def setUp(self): self.entry = ListEntry('result', 'C{list} of L{Node}', 'pass', True) self.driver = get_test_driver_instance(CloudStackNodeDriver, {'secret': 'apikey', 'key': 'user', 'host': 'api.dummy.com', 'path': '/test/path'}) def test_to_json(self): n1 = Node('id1', 'test1', NodeState.RUNNING, None, None, None) n1_json_data = {"public_ips": [], "state": 0, "id": "id1", "name": "test1"} n2 = Node('id2', 'test2', NodeState.PENDING, None, None, None) n2_json_data = {"public_ips": [], "state": 3, "id": "id2", "name": "test2"} self.assertItemsEqual([n1_json_data, n2_json_data], json.loads(self.entry.to_json([n1, n2]))) def test_from_json(self): nodes = '{"result": [{"node_id": "2600"}, {"node_id": "2601"}]}' result = self.entry.from_json(nodes, self.driver) get_node = lambda x: [node for node in result if node.id == x][0] self.assertTrue(get_node('2600')) self.assertTrue(get_node('2601'))