def __init__(self, cfg, statedir, testName): self.server = RESTMain(cfg, statedir) self.testName = testName self.config = cfg self.port = cfg.main.port self.host = '127.0.0.1' self.serverUrl = "http://%s:%s/%s/" % (self.host, self.port, cfg.main.application) ## test authentication using fake filepermission self.test_authz_key = fake_authz_key_file(False) self.config.main.tools.cms_auth.key_file = self.test_authz_key.name #self.header = fake_authz_headers(test_authz_key.data, roles = {"Admin": {'group': ['ReqMgr']}}) self.jsonSender = JSONRequests(self.serverUrl)
def setup_server(): """Create and set up an internal REST server for admin operations.""" global server, authz_key authz_key = fake_authz_key_file() cfg = Config(authkey = authz_key.name) delattr(cfg.views, 'ui') cfg.main.index = 'data' cfg.main.silent = True cfg.views.data.object = "SiteDB.Admin.AdminServer" cfg.views.data.db = "SiteDB.Admin.AUTH" server = RESTMain(cfg, os.getcwd()) server.validate_config() server.setup_server() server.install_application() cherrypy.config.update({'server.socket_port': 8888}) cherrypy.config.update({'server.socket_host': '127.0.0.1'}) cherrypy.config.update({'request.show_tracebacks': True}) cherrypy.config.update({'environment': 'test_suite'}) cherrypy.config.update({'log.screen': 'True'})
def setup_server(): """Create and set up an internal REST server for admin operations.""" global server, authz_key authz_key = fake_authz_key_file() cfg = Config(authkey=authz_key.name) delattr(cfg.views, 'ui') cfg.main.index = 'data' cfg.main.silent = True cfg.views.data.object = "SiteDB.Admin.AdminServer" cfg.views.data.db = "SiteDB.Admin.AUTH" server = RESTMain(cfg, os.getcwd()) server.validate_config() server.setup_server() server.install_application() cherrypy.config.update({'server.socket_port': 8888}) cherrypy.config.update({'server.socket_host': '127.0.0.1'}) cherrypy.config.update({'request.show_tracebacks': True}) cherrypy.config.update({'environment': 'test_suite'}) cherrypy.config.update({'log.screen': 'True'})
# system modules import cherrypy from cheroot.test import webtest from cherrypy import expose from multiprocessing import Process # WMCore modules from WMCore.REST.Auth import user_info_from_headers from WMCore.REST.Test import setup_dummy_server, fake_authz_headers from WMCore.REST.Test import fake_authz_key_file from WMCore.REST.Tools import tools FAKE_FILE = fake_authz_key_file() PORT = 8888 class Root: def __init__(self, *args): pass @expose def default(self): return "foo" @expose @tools.cms_auth(role="Global Admin", group="global") def global_admin(self): return "ok" class SimpleTest(webtest.WebCase):
from __future__ import print_function # system modules import cherrypy from multiprocessing import Process from cherrypy.test import webtest from cherrypy import process from threading import Thread, Condition import time, random # WMCore modules from WMCore.REST.Test import setup_test_server, fake_authz_headers from WMCore.REST.Test import fake_authz_key_file from WMCore.REST.Server import RESTApi, RESTEntity, restcall FAKE_FILE = fake_authz_key_file() PORT = 8888 class Task(Thread): """A pseudo-task which runs in a separate thread. Provides standard functionality to start and stop with CherryPy engine transitions, and to get a "daemon state" object. In this case the status is just a series of time stamps when the daemon pretended to last do work.""" def __init__(self): Thread.__init__(self, name = "Task") self._cv = Condition() self._status = {} self._stopme = False cherrypy.engine.subscribe("stop", self.stop) if cherrypy.engine.state == process.wspbus.states.STOPPED: cherrypy.engine.subscribe("start", self.start)
from WMCore.REST.Main import ProfiledApp from WMCore.REST.Main import Logger from WMCore.REST.Main import RESTMain from WMCore.REST.Main import RESTDaemon from WMCore.REST.Test import fake_authz_key_file from WMCore.Configuration import Configuration from cherrypy import Application import os def dummy(): return "" import os authz_key = fake_authz_key_file() cfg = Configuration() main = cfg.section_('main') main.application = 'test' main.silent = True main.index = 'top' main.authz_defaults = { 'role': None, 'group': None, 'site': None } main.section_('tools').section_('cms_auth').key_file = authz_key.name app = cfg.section_('test') app.admin = '*****@*****.**' app.description = app.title = 'Test' views = cfg.section_('views') top = views.section_('top') top.object = os.path.abspath(__file__).rsplit("/", 1)[-1].split(".")[0] + ".Test" ProfiledApp(Application(dummy, "/", {"/": {}}), ".") Logger()