def test_list_user_access_not_found(self): inst = self.instance mgr = inst._user_manager mgr.api.method_get = Mock(side_effect=exc.NotFound("")) username = utils.random_unicode() user = fakes.FakeDatabaseUser(mgr, info={"name": username}) self.assertRaises(exc.NoSuchDatabaseUser, mgr.list_user_access, user)
def test_base_list(self): clt = self.client mgr = clt._manager mgr.api.method_get = Mock(side_effect=exc.NotFound("")) uri = utils.random_unicode() ret = mgr.list(uri) self.assertEqual(ret, [])
def test_clt_queue_not_exists(self): clt = self.client clt._manager.head = Mock(side_effect=exc.NotFound("")) name = utils.random_unicode() ret = clt.queue_exists(name) self.assertFalse(ret) clt._manager.head.assert_called_once_with(name)
def test_grant_user_access_not_found(self): inst = self.instance mgr = inst._user_manager mgr.api.method_put = Mock(side_effect=exc.NotFound("")) username = utils.random_unicode() user = fakes.FakeDatabaseUser(mgr, info={"name": username}) db_names = utils.random_unicode() mgr._get_db_names = Mock(return_value=[]) self.assertRaises(exc.NoSuchDatabaseUser, mgr.grant_user_access, user, db_names)
def test_imgmgr_update_member_not_found(self): clt = self.client mgr = clt._manager img = self.image status = random.choice(("pending", "accepted", "rejected")) project_id = utils.random_unicode() clt.identity.tenant_id = project_id exp_uri = "/%s/%s/members/%s" % (mgr.uri_base, img.id, project_id) exp_body = {"status": status} mgr.api.method_put = Mock(side_effect=exc.NotFound("")) self.assertRaises(exc.InvalidImageMember, mgr.update_image_member, img.id, status)
def test_list_ptr_records_not_found(self): clt = self.client mgr = clt._manager dvc = fakes.FakeDNSDevice() href = "%s/%s" % (example_uri, dvc.id) svc_name = "cloudServersOpenStack" uri = "/rdns/%s?href=%s" % (svc_name, href) mgr._get_ptr_details = Mock(return_value=(href, svc_name)) clt.method_get = Mock(side_effect=exc.NotFound("")) ret = clt.list_ptr_records(dvc) clt.method_get.assert_called_once_with(uri) self.assertEqual(ret, [])
def test_assure_domain_name(self): @assure_domain def test(self, domain): return domain clt = self.client dom = self.domain clt._manager._get = Mock(side_effect=exc.NotFound("")) clt._manager._list = Mock(return_value=[dom]) d3 = test(clt, dom.name) self.assertEqual(d3, dom) self.assertTrue(isinstance(d3, CloudDNSDomain))
def get(self, id_): """ Need to customize, since Queues are not returned with normal response bodies. """ if self.api.queue_exists(id_): return Queue(self, {"queue": { "name": id_, "id_": id_ }}, key="queue") raise exc.NotFound("The queue '%s' does not exist." % id_)
def test_get_flavor_ref_not_found(self): clt = self.client info = { "id": 1, "name": "test_flavor", "ram": 42, "links": [{ "href": example_uri, "rel": "self" }] } flavor_obj = CloudDatabaseFlavor(clt._manager, info) clt.get_flavor = Mock(side_effect=exc.NotFound("")) clt.list_flavors = Mock(return_value=[flavor_obj]) self.assertRaises(exc.FlavorNotFound, clt._get_flavor_ref, "nonsense")
def test_get_flavor_ref_for_ram(self): clt = self.client info = { "id": 1, "name": "test_flavor", "ram": 42, "links": [{ "href": example_uri, "rel": "self" }] } flavor_obj = CloudDatabaseFlavor(clt._manager, info) clt.get_flavor = Mock(side_effect=exc.NotFound("")) clt.list_flavors = Mock(return_value=[flavor_obj]) ret = clt._get_flavor_ref(42) self.assertEqual(ret, example_uri)
def find(self, **kwargs): """ Finds a single item with attributes matching ``**kwargs``. This isn't very efficient: it loads the entire list then filters on the Python side. """ matches = self.findall(**kwargs) num_matches = len(matches) if not num_matches: msg = "No %s matching: %s." % (self.resource_class.__name__, kwargs) raise exc.NotFound(404, msg) if num_matches > 1: msg = "More than one %s matching: %s." % ( self.resource_class.__name__, kwargs) raise exc.NoUniqueMatch(400, msg) else: return matches[0]
def test_get_user_fail(self): inst = self.instance bad_name = utils.random_unicode() inst._user_manager.get = Mock(side_effect=exc.NotFound("")) self.assertRaises(exc.NoSuchDatabaseUser, inst.get_user, bad_name)