def setUp(self): save_conf = client.BaseClient._configure_manager client.BaseClient._configure_manager = Mock() self.identity = pyos.identity = ID_CLS() self.client = client.BaseClient(self.identity) client.BaseClient._configure_manager = save_conf self.client._manager = fakes.FakeManager()
def _create_dummy_resource(self): mgr = fakes.FakeManager() info = { "name": "test_resource", "size": 42, "id": utils.random_unicode() } return resource.BaseResource(mgr, info)
def test_delete_network_fail(self): clt = self.client nm = "fake" net = fakes.FakeCloudNetwork(name=nm) net.manager = fakes.FakeManager() err = exc.Forbidden(403) net.manager.delete = Mock(side_effect=err) self.assertRaises(exc.NetworkInUse, net.delete)
def test_delete_network(self): clt = self.client nm = "fake" net = fakes.FakeCloudNetwork(name=nm) net.manager = fakes.FakeManager() net.manager.delete = Mock() net.delete() net.manager.delete.assert_called_once_with(net)
def test_instantiate_instance(self): inst = CloudDatabaseInstance(fakes.FakeManager(), { "id": 42, "volume": { "size": 1, "used": 0.2 } }) self.assertTrue(isinstance(inst, CloudDatabaseInstance)) self.assertTrue(isinstance(inst.volume, CloudDatabaseVolume))
def test_wait_until_callback(self): cback = Mock() status_obj = fakes.FakeStatusChanger() status_obj.manager = fakes.FakeManager() status_obj.manager.get = Mock(return_value=status_obj) status_obj.get = status_obj.manager.get thread = utils.wait_until(obj=status_obj, att="status", desired="ready", interval=0.00001, callback=cback) thread.join() cback.assert_called_once_with(status_obj)
def test_wait_until_fail(self): status_obj = fakes.FakeStatusChanger() self.assertRaises(exc.NoReloadError, utils.wait_until, status_obj, "status", "available") status_obj.manager = fakes.FakeManager() status_obj.manager.get = Mock(return_value=status_obj) status_obj.get = status_obj.manager.get ret = utils.wait_until(status_obj, "status", "fake", interval=0.00001, attempts=2) self.assertFalse(ret.status == "fake")
def test_create_volume(self): mgr = fakes.FakeManager() mgr.api.region_name = "FAKE" sav = pyos.connect_to_cloudservers fakenovavol = utils.random_unicode() class FakeVol(object): def __init__(self, *args, **kwargs): self.volumes = fakenovavol pyos.connect_to_cloudservers = Mock(return_value=FakeVol()) vol = CloudBlockStorageVolume(mgr, {}) self.assertTrue(isinstance(vol, CloudBlockStorageVolume)) self.assertEqual(vol._nova_volumes, fakenovavol) pyos.connect_to_cloudservers = sav
def test_wait_until(self): status_obj = fakes.FakeStatusChanger() self.assertRaises(exc.NoReloadError, utils.wait_until, status_obj, "status", "available") status_obj.manager = fakes.FakeManager() status_obj.manager.get = Mock(return_value=status_obj) status_obj.get = status_obj.manager.get sav_out = sys.stdout out = StringIO() sys.stdout = out ret = utils.wait_until(status_obj, "status", "ready", interval=0.00001, verbose=True, verbose_atts="progress") self.assertTrue(isinstance(ret, fakes.FakeStatusChanger)) self.assertEqual(ret.status, "ready") self.assertTrue(len(out.getvalue()) > 0) sys.stdout = sav_out
class TestClient(object): _manager = fakes.FakeManager() @assure_instance def test_method(self, instance): return instance
class TestClient(object): _snapshot_manager = fakes.FakeManager() @assure_snapshot def test_method(self, snapshot): return snapshot
class TestClient(object): _manager = fakes.FakeManager() @assure_volume def test_method(self, volume): return volume
class TestClient(object): _manager = fakes.FakeManager() @assure_image def test_method(self, img): return img