def test_imgmgr_create_body(self): clt = self.client mgr = clt._manager nm = utils.random_unicode() meta = utils.random_unicode() body = mgr._create_body(nm, metadata=meta) self.assertEqual(body, {"metadata": meta})
def test_claim(self): msgs = [] num = random.randint(1, 9) for ii in range(num): msg_id = utils.random_unicode() claim_id = utils.random_unicode() age = utils.random_unicode() body = utils.random_unicode() ttl = utils.random_unicode() href = "http://example.com/%s" % msg_id info = {"href": href, "age": age, "body": body, "ttl": ttl, } msgs.append(info) id_ = _safe_id() href = "http://example.com/%s" % id_ info = {"href": href, "messages": msgs, } mgr = fakes.FakeQueueManager() mgr._message_manager = fakes.FakeQueueManager() clm = QueueClaim(manager=mgr, info=info) self.assertEqual(clm.id, id_) self.assertEqual(len(clm.messages), num)
def test_manager_list_all(self): clt = self.client mgr = clt._manager fake_name = utils.random_unicode() ret_body = {"domains": [{"name": fake_name}]} uri_string_next = utils.random_unicode() next_uri = "%s/domains/%s" % (example_uri, uri_string_next) mgr.count = 0 def mock_get(uri): if mgr.count: return ({}, ret_body) mgr.count += 1 ret = { "totalEntries": 2, "links": [{ "href": next_uri, "rel": "next" }] } ret.update(ret_body) return ({}, ret) clt.method_get = Mock(wraps=mock_get) ret = mgr._list(example_uri, list_all=True) self.assertEqual(len(ret), 2)
def test_reset_paging_body(self): clt = self.client mgr = clt._manager mgr._paging["domain"]["total_entries"] = 99 mgr._paging["domain"]["next_uri"] = "FAKE" exp_entries = random.randint(100, 200) uri_string_next = utils.random_unicode() next_uri = "%s/domains/%s" % (example_uri, uri_string_next) uri_string_prev = utils.random_unicode() prev_uri = "%s/domains/%s" % (example_uri, uri_string_prev) body = { "totalEntries": exp_entries, "links": [{ "href": next_uri, "rel": "next" }, { "href": prev_uri, "rel": "previous" }] } mgr._reset_paging("domain", body=body) self.assertEqual(mgr._paging["domain"]["total_entries"], exp_entries) self.assertEqual(mgr._paging["domain"]["next_uri"], "/domains/%s" % uri_string_next) self.assertEqual(mgr._paging["domain"]["prev_uri"], "/domains/%s" % uri_string_prev)
def test_create_body_volume(self): mgr = self.client._manager size = random.randint(MIN_SIZE, MAX_SIZE) name = utils.random_unicode() snapshot_id = utils.random_unicode() clone_id = utils.random_unicode() display_description = None volume_type = None metadata = None availability_zone = utils.random_unicode() fake_body = {"volume": { "size": size, "snapshot_id": snapshot_id, "source_volid": clone_id, "display_name": name, "display_description": "", "volume_type": "SATA", "metadata": {}, "availability_zone": availability_zone, }} ret = mgr._create_body(name=name, size=size, volume_type=volume_type, description=display_description, metadata=metadata, snapshot_id=snapshot_id, clone_id=clone_id, availability_zone=availability_zone) self.assertEqual(ret, fake_body)
def test_img_update(self): img = self.image key = utils.random_unicode() val = utils.random_unicode() img.manager.update = Mock() img.update({key: val}) img.manager.update.assert_called_once_with(img, {key: val})
def test_queue_mgr_create_body(self): clt = self.client mgr = clt._manager name = utils.random_unicode() metadata = utils.random_unicode() ret = mgr._create_body(name, metadata=metadata) self.assertEqual(ret, {"metadata": metadata})
def test_queue_post_message(self): q = self.queue q._message_manager.create = Mock() body = utils.random_unicode() ttl = utils.random_unicode() q.post_message(body, ttl) q._message_manager.create.assert_called_once_with(body, ttl)
def test_findall(self): mgr = self.client._manager mgr.findall = Mock() prop = utils.random_unicode() val = utils.random_unicode() self.client.findall(prop=val) mgr.findall.assert_called_once_with(prop=val)
def test_img_member_mgr_create_body(self): img = self.image mgr = img._member_manager nm = utils.random_unicode() project_id = utils.random_unicode() ret = mgr._create_body(nm, project_id) self.assertEqual(ret, {"member": project_id})
def test_find(self): mgr = self.client._manager mgr.find = Mock() prop = utils.random_unicode() val = utils.random_unicode() self.client.find(prop=val) mgr.find.assert_called_once_with(prop=val)
def test_queue_claim_messages(self): q = self.queue q._claim_manager.claim = Mock() ttl = utils.random_unicode() grace = utils.random_unicode() count = random.randint(1, 9) q.claim_messages(ttl, grace, count=count) q._claim_manager.claim.assert_called_once_with(ttl, grace, count=count)
def test_queue_delete_message(self): q = self.queue q._message_manager.delete = Mock() msg_id = utils.random_unicode() claim_id = utils.random_unicode() q.delete_message(msg_id, claim_id=claim_id) q._message_manager.delete.assert_called_once_with(msg_id, claim_id=claim_id)
def test_snapshot_description_property(self): snap = self.snapshot nm = utils.random_unicode() snap.display_description = nm self.assertEqual(snap.description, snap.display_description) nm = utils.random_unicode() snap.description = nm self.assertEqual(snap.description, snap.display_description)
def test_snapshot_name_property(self): snap = self.snapshot nm = utils.random_unicode() snap.display_name = nm self.assertEqual(snap.name, snap.display_name) nm = utils.random_unicode() snap.name = nm self.assertEqual(snap.name, snap.display_name)
def __init__(self, *args, **kwargs): info = kwargs.pop("info", {"fake": "fake"}) info["name"] = utils.random_unicode() info["id"] = utils.random_unicode() mgr = kwargs.pop("manager", FakeImageManager()) kwargs["member_manager_class"] = FakeImageMemberManager kwargs["tag_manager_class"] = FakeImageTagManager super(FakeImage, self).__init__(mgr, info, *args, **kwargs)
def test_queue_id_property(self): q = self.queue val = utils.random_unicode() q.name = val self.assertEqual(q.id, val) val = utils.random_unicode() q.id = val self.assertEqual(q.name, val)
def test_create_snapshot(self): vol = self.volume vol.manager.create_snapshot = Mock() name = utils.random_unicode() desc = utils.random_unicode() vol.create_snapshot(name=name, description=desc, force=False) vol.manager.create_snapshot.assert_called_once_with(volume=vol, name=name, description=desc, force=False)
def test_detach_from_instance_fail(self): vol = self.volume srv_id = utils.random_unicode() att_id = utils.random_unicode() vol.attachments = [{"server_id": srv_id, "id": att_id}] vol._nova_volumes.delete_server_volume = Mock( side_effect=Exception("test")) self.assertRaises(exc.VolumeDetachmentFailed, vol.detach)
def test_auth_with_token(self): pyos.authenticated = False tok = utils.random_unicode() tname = utils.random_unicode() pyos.auth_with_token(tok, tenant_name=tname) self.assertTrue(pyos.identity.authenticated) self.assertEqual(pyos.identity.token, tok) self.assertEqual(pyos.identity.tenant_name, tname)
def test_list_users(self): inst = self.instance inst._user_manager.list = Mock() limit = utils.random_unicode() marker = utils.random_unicode() inst.list_users(limit=limit, marker=marker) inst._user_manager.list.assert_called_once_with(limit=limit, marker=marker)
def test_volume_description_property(self): vol = self.volume nm = utils.random_unicode() vol.display_description = nm self.assertEqual(vol.description, vol.display_description) nm = utils.random_unicode() vol.description = nm self.assertEqual(vol.description, vol.display_description)
def test_volume_name_property(self): vol = self.volume nm = utils.random_unicode() vol.display_name = nm self.assertEqual(vol.name, vol.display_name) nm = utils.random_unicode() vol.name = nm self.assertEqual(vol.name, vol.display_name)
def test_list_flavors(self): clt = self.client clt._flavor_manager.list = Mock() limit = utils.random_unicode() marker = utils.random_unicode() clt.list_flavors(limit=limit, marker=marker) clt._flavor_manager.list.assert_called_once_with(limit=limit, marker=marker)
def test_get_extensions(self): ident = self.identity v1 = utils.random_unicode() v2 = utils.random_unicode() resp_body = {"extensions": {"values": [v1, v2]}} ident.method_get = Mock(return_value=(None, resp_body)) ret = ident.get_extensions() self.assertEqual(ret, [v1, v2])
def test_clt_post_message(self): clt = self.client q = self.queue body = utils.random_unicode() ttl = utils.random_unicode() q.post_message = Mock() clt.post_message(q, body, ttl) q.post_message.assert_called_once_with(body, ttl)
def test_clt_change_user_password(self): clt = self.client inst = self.instance inst.change_user_password = Mock() user = utils.random_unicode() pw = utils.random_unicode() clt.change_user_password(inst, user, pw) inst.change_user_password.assert_called_once_with(user, pw)
def test_delete_role_from_user(self): ident = self.identity role = utils.random_unicode() user = utils.random_unicode() ident.method_delete = Mock(return_value=(None, None)) exp_uri = "users/%s/roles/OS-KSADM/%s" % (user, role) ident.delete_role_from_user(role, user) ident.method_delete.assert_called_once_with(exp_uri)
def test_clt_delete_message(self): clt = self.client q = self.queue msg_id = utils.random_unicode() claim_id = utils.random_unicode() q.delete_message = Mock() clt.delete_message(q, msg_id, claim_id=claim_id) q.delete_message.assert_called_once_with(msg_id, claim_id=claim_id)
def test_clt_set_metadata(self): clt = self.client clt._manager.set_metadata = Mock() q = utils.random_unicode() metadata = utils.random_unicode() clear = random.choice((True, False)) clt.set_metadata(q, metadata, clear=clear) clt._manager.set_metadata.assert_called_once_with(q, metadata, clear=clear)
def test_ep_get_client_exists(self): svc = self.service ep_dict = {"publicURL": "http://example.com", "tenantId": "aa"} rgn = utils.random_unicode().upper() ep = fakes.FakeEndpoint(ep_dict, svc, rgn, self.identity) clt = utils.random_unicode() ep._client = clt ret = ep._get_client() self.assertEqual(ret, clt)
def test_queue_update_claim(self): q = self.queue q._claim_manager.update = Mock() claim = utils.random_unicode() ttl = utils.random_unicode() grace = utils.random_unicode() q.update_claim(claim, ttl=ttl, grace=grace) q._claim_manager.update.assert_called_once_with(claim, ttl=ttl, grace=grace)
def test_queue_msg_mgr_delete_claim(self): q = self.queue mgr = q._message_manager msg = utils.random_unicode() claim_id = utils.random_unicode() mgr._delete = Mock() expected_uri = "/%s/%s?claim_id=%s" % (mgr.uri_base, msg, claim_id) mgr.delete(msg, claim_id=claim_id) mgr._delete.assert_called_once_with(expected_uri)
def test_queue_msg_mgr_delete_by_ids(self): q = self.queue mgr = q._message_manager mgr.api.method_delete = Mock() id1 = utils.random_unicode() id2 = utils.random_unicode() mgr.delete_by_ids([id1, id2]) expected = "/%s?ids=%s" % (mgr.uri_base, ",".join([id1, id2])) mgr.api.method_delete.assert_called_once_with(expected)
def test_clt_create_backup(self): clt = self.client inst = self.instance name = utils.random_unicode() description = utils.random_unicode() inst.create_backup = Mock() clt.create_backup(inst, name, description=description) inst.create_backup.assert_called_once_with(name, description=description)
def test_list_users_for_instance(self): clt = self.client inst = self.instance limit = utils.random_unicode() marker = utils.random_unicode() inst.list_users = Mock(return_value=["user"]) ret = clt.list_users(inst, limit=limit, marker=marker) self.assertEqual(ret, ["user"]) inst.list_users.assert_called_once_with(limit=limit, marker=marker)
def test_clt_update_claim(self): clt = self.client q = self.queue claim = utils.random_unicode() ttl = utils.random_unicode() grace = utils.random_unicode() q.update_claim = Mock() clt.update_claim(q, claim, ttl=ttl, grace=grace) q.update_claim.assert_called_once_with(claim, ttl=ttl, grace=grace)
def test_clt_claim_messages(self): clt = self.client q = self.queue ttl = utils.random_unicode() grace = utils.random_unicode() count = utils.random_unicode() q.claim_messages = Mock() clt.claim_messages(q, ttl, grace, count=count) q.claim_messages.assert_called_once_with(ttl, grace, count=count)