class ListEntryTest(unittest2.TestCase): 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'))
class ListEntryTest(unittest2.TestCase): 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')) class RecordTypeTest(unittest2.TestCase): def setUp(self): self.entry = Entry('type', 'L{RecordType}', 'pass', True) def test_from_json(self): valid_json = '{"record_type": 1}' self.assertEqual(self.entry.from_json(valid_json, None), RecordType.AAAA) invalid_json = '{"record_type": "ABC"}' self.assertRaises(ValidationError, self.entry.from_json, invalid_json, None)
class ListEntryTest(unittest2.TestCase): 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')) class RecordTypeTest(unittest2.TestCase): def setUp(self): self.entry = Entry('type', 'L{RecordType}', 'pass', True) def test_from_json(self): valid_json = '{"record_type": 1}' self.assertEqual(self.entry.from_json(valid_json, None), RecordType.AAAA) invalid_json = '{"record_type": "ABC"}' self.assertRaises(ValidationError, self.entry.from_json, invalid_json, None)
class ListEntryTest(unittest2.TestCase): 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'))