def test_delete(self): client = sunstone_rest_client.RestClient("http://foobar:4711") client.cache = {"/vm": {"VM_POOL": {"VM": {"NAME": "dummyVM", "ID": "42"}}}} client.session = Mock() client.session.delete = Mock(return_value="ok") result = client.delete_multiple_vms_by_name("dummyVM") self.assertEqual(result["42"], "ok")
def test_fetch_successfully(self): client = sunstone_rest_client.RestClient("http://foobar:4711") client.session = Mock() client.csrftoken = "1234" successfully = Attrs(ok=True, json=lambda: "tadahh") client.session.get = Mock(return_value=successfully) response = client._fetch() self.assertEqual("tadahh", response)
def test_instantiate(self): client = sunstone_rest_client.RestClient("http://foobar:4711") client.cache = {"/vm": {"VM_POOL": {"VM": {"NAME": "dummyVM", "ID": "42"}}}, "/vmtemplate": { "VMTEMPLATE_POOL": {"VMTEMPLATE": {"NAME": "foo", "UID": "333", "TEMPLATE": "empty"}}}} client.session = Mock() client.session.post = Mock(return_value="ok") result = client.instantiate_by_name("foo", "newVM") self.assertEqual(result, "ok")
def test_fetch_hosts(self): client = sunstone_rest_client.RestClient("http://foobar:4711") client.cache = { "/host": { "HOST_POOL": { "HOST": { "NAME": "dummyHost", "ID": "42" } } } } result = client.fetch_hosts() self.assertTrue("NAME" in result[0])
def test_fetch_vms(self): client = sunstone_rest_client.RestClient("http://foobar:4711") client.cache = {"/vm": {"VM_POOL": {"VM": {"NAME": "dummyVM", "ID": "42"}}}, "/vmtemplate": {"VMTEMPLATE_POOL": {"VMTEMPLATE": {"NAME": "foo", "UID": "333"}}}} result = client.fetch_vms() self.assertTrue("NAME" in result[0]) result = client.get_vm_by_id(42) self.assertTrue(result["ID"] == "42") result = client.get_first_vm_by_name("dummyVM") self.assertTrue(result["ID"] == "42") result = client.get_first_template_by_name("foo") self.assertTrue(result["UID"] == "333") self.assertRaises(StopIteration, client.get_first_vm_by_name, "unknownVM")
def test_fetch_failed(self): client = sunstone_rest_client.RestClient("http://foobar:4711") client.session = Mock() failed = Attrs(ok=False, reason="oops") client.session.get = Mock(return_value=failed) self.assertRaises(Exception, client._fetch)
def test_init(self): sunstone_rest_client.RestClient("http://foobar:4711")
def test_failed_login(self): client = sunstone_rest_client.RestClient("http://foobar:4711").login("user", "passwd") self.assertRaises(Exception, client._login)
def test_login(self): sunstone_rest_client.RestClient("http://foobar:4711").login("user", "passwd")
def test_find_by_id(self): client = sunstone_rest_client.RestClient("http://foobar:4711") client.cache = {"/vmtemplate": { "VMTEMPLATE_POOL": {"VMTEMPLATE": {"NAME": "foo", "UID": "333", "TEMPLATE": "empty"}}}} result = client.get_template_by_id(333) self.assertEqual(result["NAME"], "foo")