def test_deny_access_access_rule_not_found(self): share = db_utils.create_share(mount_snapshot_support=True) snapshot = db_utils.create_snapshot( status=constants.STATUS_AVAILABLE, share_id=share['id']) access = db_utils.create_snapshot_access( share_snapshot_id=snapshot['id']) wrong_access = { 'access_type': 'fake_type', 'access_to': 'fake_IP', 'share_snapshot_id': 'fake_id' } get = self.mock_object(share_api.API, 'get', mock.Mock(return_value=share)) get_snapshot = self.mock_object(share_api.API, 'get_snapshot', mock.Mock(return_value=snapshot)) access_get = self.mock_object(share_api.API, 'snapshot_access_get', mock.Mock(return_value=wrong_access)) body = {'deny_access': {'access_id': access.id}} req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'], version='2.32') self.assertRaises(webob.exc.HTTPBadRequest, self.controller.deny_access, req, snapshot['id'], body) get.assert_called_once_with(utils.IsAMatcher(context.RequestContext), share['id']) get_snapshot.assert_called_once_with( utils.IsAMatcher(context.RequestContext), snapshot['id']) access_get.assert_called_once_with( utils.IsAMatcher(context.RequestContext), body['deny_access']['access_id'])
def test_deny_access_access_rule_not_found(self): share = db_utils.create_share(mount_snapshot_support=True) snapshot = db_utils.create_snapshot( status=constants.STATUS_AVAILABLE, share_id=share['id']) access = db_utils.create_snapshot_access( share_snapshot_id=snapshot['id']) wrong_access = { 'access_type': 'fake_type', 'access_to': 'fake_IP', 'share_snapshot_id': 'fake_id' } get = self.mock_object(share_api.API, 'get', mock.Mock(return_value=share)) get_snapshot = self.mock_object(share_api.API, 'get_snapshot', mock.Mock(return_value=snapshot)) access_get = self.mock_object(share_api.API, 'snapshot_access_get', mock.Mock(return_value=wrong_access)) body = {'deny_access': {'access_id': access.id}} req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'], version='2.32') self.assertRaises(webob.exc.HTTPBadRequest, self.controller.deny_access, req, snapshot['id'], body) get.assert_called_once_with(utils.IsAMatcher(context.RequestContext), share['id']) get_snapshot.assert_called_once_with( utils.IsAMatcher(context.RequestContext), snapshot['id']) access_get.assert_called_once_with( utils.IsAMatcher(context.RequestContext), body['deny_access']['access_id'])
def test_deny_access(self): share = db_utils.create_share(mount_snapshot_support=True) snapshot = db_utils.create_snapshot( status=constants.STATUS_AVAILABLE, share_id=share['id']) access = db_utils.create_snapshot_access( share_snapshot_id=snapshot['id']) get = self.mock_object(share_api.API, 'get', mock.Mock(return_value=share)) get_snapshot = self.mock_object(share_api.API, 'get_snapshot', mock.Mock(return_value=snapshot)) access_get = self.mock_object(share_api.API, 'snapshot_access_get', mock.Mock(return_value=access)) deny_access = self.mock_object(share_api.API, 'snapshot_deny_access') body = {'deny_access': {'access_id': access.id}} req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'], version='2.32') resp = self.controller.deny_access(req, snapshot['id'], body) self.assertEqual(202, resp.status_int) get.assert_called_once_with(utils.IsAMatcher(context.RequestContext), share['id']) get_snapshot.assert_called_once_with( utils.IsAMatcher(context.RequestContext), snapshot['id']) access_get.assert_called_once_with( utils.IsAMatcher(context.RequestContext), body['deny_access']['access_id']) deny_access.assert_called_once_with( utils.IsAMatcher(context.RequestContext), snapshot, access)
def test_deny_access(self): share = db_utils.create_share(mount_snapshot_support=True) snapshot = db_utils.create_snapshot( status=constants.STATUS_AVAILABLE, share_id=share['id']) access = db_utils.create_snapshot_access( share_snapshot_id=snapshot['id']) get = self.mock_object(share_api.API, 'get', mock.Mock(return_value=share)) get_snapshot = self.mock_object(share_api.API, 'get_snapshot', mock.Mock(return_value=snapshot)) access_get = self.mock_object(share_api.API, 'snapshot_access_get', mock.Mock(return_value=access)) deny_access = self.mock_object(share_api.API, 'snapshot_deny_access') body = {'deny_access': {'access_id': access.id}} req = fakes.HTTPRequest.blank('/snapshots/%s/action' % snapshot['id'], version='2.32') resp = self.controller.deny_access(req, snapshot['id'], body) self.assertEqual(202, resp.status_int) get.assert_called_once_with(utils.IsAMatcher(context.RequestContext), share['id']) get_snapshot.assert_called_once_with( utils.IsAMatcher(context.RequestContext), snapshot['id']) access_get.assert_called_once_with( utils.IsAMatcher(context.RequestContext), body['deny_access']['access_id']) deny_access.assert_called_once_with( utils.IsAMatcher(context.RequestContext), snapshot, access)