當前位置: 首頁>>代碼示例>>Python>>正文


Python RESTServerSetup.DefaultConfig類代碼示例

本文整理匯總了Python中WMQuality.WebTools.RESTServerSetup.DefaultConfig的典型用法代碼示例。如果您正苦於以下問題:Python DefaultConfig類的具體用法?Python DefaultConfig怎麽用?Python DefaultConfig使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了DefaultConfig類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: FakeRESTServer

class FakeRESTServer(RESTBaseUnitTest):
    """
    Loads a the CRABRESTModelMock REST interface which emulates the CRABRESTModel class.
    When testing a command which requires an interaction with the server wi will contact
    this class.
    """

    def initialize(self):
        self.config = DefaultConfig('CRABRESTModelMock')
        self.config.Webtools.environment = 'development'
        self.config.Webtools.error_log_level = logging.ERROR
        self.config.Webtools.access_log_level = logging.ERROR
        self.config.Webtools.port = 8518
        self.config.Webtools.host = '127.0.0.1'
        self.config.UnitTests.object = 'CRABRESTModelMock'
        #self.config.UnitTests.views.active.rest.logLevel = 'DEBUG'

        self.urlbase = self.config.getServerUrl()


    def setUp(self):
        """
        _setUp_
        """
        RESTBaseUnitTest.setUp(self)


    def tearDown(self):
        RESTBaseUnitTest.tearDown(self)
開發者ID:AndresTanasijczuk,項目名稱:CRABClient,代碼行數:29,代碼來源:FakeRESTServer.py

示例2: initialize

 def initialize(self):
     self.config = DefaultConfig()
     self.config.UnitTests.templates = getWMBASE() + '/src/templates/WMCore/WebTools'
     self.config.Webtools.section_('server')
     self.config.Webtools.server.socket_timeout = 1
     self.urlbase = self.config.getServerUrl()
     self.cache_path = tempfile.mkdtemp()
開發者ID:alexanderrichards,項目名稱:WMCore,代碼行數:7,代碼來源:Requests_t.py

示例3: testRepeatCalls

class testRepeatCalls(RESTBaseUnitTest):
    def initialize(self):
        self.config = DefaultConfig()
        self.config.UnitTests.templates = getWMBASE() + '/src/templates/WMCore/WebTools'
        self.config.Webtools.section_('server')
        self.config.Webtools.server.socket_timeout = 1
        self.urlbase = self.config.getServerUrl()
        self.cache_path = tempfile.mkdtemp()

    def tearDown(self):
        shutil.rmtree(self.cache_path, ignore_errors = True)
        self.rt.stop()

    def test10Calls(self):
        fail_count = 0
        req = Requests.Requests(self.urlbase, {'req_cache_path': self.cache_path})

        for i in range(0, 5):
            time.sleep(i)
            print 'test %s starting at %s' % (i, time.time())
            try:
                result = req.get('/', incoming_headers={'Cache-Control':'no-cache'})
                self.assertEqual(False, result[3])
                self.assertEqual(200, result[1])
            except HTTPException, he:
                print 'test %s raised a %s error' % (i, he.status)
                fail_count += 1
            except Exception, e:
                print 'test %s raised an unexpected exception of type %s' % (i, type(e))
                print e
                fail_count += 1
開發者ID:,項目名稱:,代碼行數:31,代碼來源:

示例4: initialize

 def initialize(self):
     self.config = DefaultConfig(
             'WMCore.HTTPFrontEnd.WMBS.WMBSRESTModel')
     dbUrl = os.environ.get("DATABASE", None)
     self.config.setDBUrl(dbUrl)
     # mysql example
     #self.config.setDBUrl('mysql://[email protected]:3306/TestDB')
     #self.config.setDBSocket('/var/lib/mysql/mysql.sock')
     self.schemaModules = ["WMCore.WMBS", "WMCore.ResourceControl", "BossAir"]
開發者ID:AndrewLevin,項目名稱:WMCore,代碼行數:9,代碼來源:WMBS_t.py

示例5: NestedModelTest

class NestedModelTest(RESTBaseUnitTest):

    def initialize(self):
        self.config = DefaultConfig('WMCore_t.WebTools_t.DummyNestedModel')
        do_debug = True

        self.config.Webtools.environment = 'development'
        if do_debug:
            self.config.Webtools.error_log_level = logging.DEBUG
            self.config.Webtools.access_log_level = logging.DEBUG
        else:
            self.config.Webtools.error_log_level = logging.WARNING
            self.config.Webtools.access_log_level = logging.WARNING

        self.urlbase = self.config.getServerUrl()

    def testOuterFooPass(self):
        verb ='GET'
        url = self.urlbase + 'foo'
        output={'code':200, 'data':'"foo"'}
        expireTime =3600
        methodTest(verb, url, output=output, expireTime=expireTime)

        url = self.urlbase + 'foo/test'
        output={'code':200, 'data':'"foo test"'}
        methodTest(verb, url, output=output, expireTime=expireTime)

        url = self.urlbase + 'foo'
        request_input = {'message': 'test'}
        output={'code':200, 'data':'"foo test"'}
        methodTest(verb, url, request_input=request_input, output=output, expireTime=expireTime)

    def testInnerPingPass(self):
        verb ='GET'
        url = self.urlbase + 'foo/ping'
        output={'code':200, 'data':'"ping"'}
        expireTime =3600

        methodTest(verb, url, output=output, expireTime=expireTime)

    def testOuterFooError(self):
        verb ='GET'
        url = self.urlbase + 'foo/123/567'
        output={'code':400}
        methodTest(verb, url, output=output)

    def testInnerPingError(self):
        verb ='GET'
        url = self.urlbase + 'foo/123/ping'
        output={'code':400}
        methodTest(verb, url, output=output)

        url = self.urlbase + 'foo/ping/123'
        methodTest(verb, url, output=output)
開發者ID:BrunoCoimbra,項目名稱:WMCore,代碼行數:54,代碼來源:NestedModel_t.py

示例6: initialize

    def initialize(self):
        self.config = DefaultConfig('CRABRESTModelMock')
        self.config.Webtools.environment = 'development'
        self.config.Webtools.error_log_level = logging.ERROR
        self.config.Webtools.access_log_level = logging.ERROR
        self.config.Webtools.port = 8518
        self.config.Webtools.host = '127.0.0.1'
        self.config.UnitTests.object = 'CRABRESTModelMock'
        #self.config.UnitTests.views.active.rest.logLevel = 'DEBUG'

        self.urlbase = self.config.getServerUrl()
開發者ID:AndresTanasijczuk,項目名稱:CRABClient,代碼行數:11,代碼來源:FakeRESTServer.py

示例7: initialize

    def initialize(self):
        self.config = DefaultConfig('WMCore_t.WebTools_t.DummyNestedModel')
        do_debug = True

        self.config.Webtools.environment = 'development'
        if do_debug:
            self.config.Webtools.error_log_level = logging.DEBUG
            self.config.Webtools.access_log_level = logging.DEBUG
        else:
            self.config.Webtools.error_log_level = logging.WARNING
            self.config.Webtools.access_log_level = logging.WARNING

        self.urlbase = self.config.getServerUrl()
開發者ID:BrunoCoimbra,項目名稱:WMCore,代碼行數:13,代碼來源:NestedModel_t.py

示例8: WorkQueueTest

class WorkQueueTest(RESTBaseUnitTest):
    """
    Test WorkQueue Service client
    It will start WorkQueue RESTService
    Server DB sets from environment variable.
    Client DB sets from environment variable.

    This checks whether DS call makes without error and return the results.
    Not the correctness of functions. That will be tested in different module.
    """
    def initialize(self):
        self.config = DefaultConfig(
                'WMCore.HTTPFrontEnd.WMBS.WMBSRESTModel')
        dbUrl = os.environ.get("DATABASE", None)
        self.config.setDBUrl(dbUrl)
        # mysql example
        #self.config.setDBUrl('mysql://[email protected]:3306/TestDB')
        #self.config.setDBSocket('/var/lib/mysql/mysql.sock')
        self.schemaModules = ["WMCore.WMBS", "WMCore.ResourceControl", "BossAir"]

    def setUp(self):
        """
        setUP global values
        """
        RESTBaseUnitTest.setUp(self)
        self.params = {}
        self.params['endpoint'] = self.config.getServerUrl()

    def tearDown(self):
        RESTBaseUnitTest.tearDown(self)

    def testWorkQueueService(self):

        # test getWork

        wmbsApi = WMBS(self.params)
        self.assertEqual(wmbsApi.getResourceInfo(), [])
        self.assertEqual(wmbsApi.getResourceInfo(tableFormat = False), {})
開發者ID:AndrewLevin,項目名稱:WMCore,代碼行數:38,代碼來源:WMBS_t.py

示例9: initialize

    def initialize(self):
        self.config = DefaultConfig('WMCore_t.WebTools_t.DummyRESTModel')
        self.do_debug = False
        self.do_production = False

        if self.do_production:
            self.config.Webtools.environment = 'production'
            self.config.SecurityModule.dangerously_insecure = False
            # not real keyfile but for the test.
            # file will be deleted automaticall when garbage collected.
            self.tempFile = NamedTemporaryFile()
            self.config.SecurityModule.key_file = self.tempFile.name
            self.config.SecurityModule.section_("default")
            self.config.SecurityModule.default.role = ""
            self.config.SecurityModule.default.group = ""
            self.config.SecurityModule.default.site = ""

        if not self.do_debug:
            self.config.Webtools.error_log_level = logging.WARNING
            self.config.Webtools.access_log_level = logging.WARNING

        self.urlbase = self.config.getServerUrl()
開發者ID:,項目名稱:,代碼行數:22,代碼來源:

示例10: RESTTest

class RESTTest(RESTBaseUnitTest):
    def initialize(self):
        self.config = DefaultConfig('WMCore_t.WebTools_t.DummyRESTModel')
        self.do_debug = False
        self.do_production = False

        if self.do_production:
            self.config.Webtools.environment = 'production'
            self.config.SecurityModule.dangerously_insecure = False
            # not real keyfile but for the test.
            # file will be deleted automaticall when garbage collected.
            self.tempFile = NamedTemporaryFile()
            self.config.SecurityModule.key_file = self.tempFile.name
            self.config.SecurityModule.section_("default")
            self.config.SecurityModule.default.role = ""
            self.config.SecurityModule.default.group = ""
            self.config.SecurityModule.default.site = ""

        if not self.do_debug:
            self.config.Webtools.error_log_level = logging.WARNING
            self.config.Webtools.access_log_level = logging.WARNING

        self.urlbase = self.config.getServerUrl()

    def testUnsupportedFormat(self):
        # test not accepted type should return 406 error
        url = self.urlbase + 'ping'
        methodTest('GET', url, accept='text/das', output={'code':406})

    def testGoodEcho(self):
        verb ='POST'
        url = self.urlbase + 'echo'
        input_data={'message': 'unit test'}
        output={'code':200, 'type':'text/json',
              'data':'{"message": "unit test"}'}

        methodTest(verb, url, input_data, output=output)

    def testBadEchoWithPosArg(self):
        "Echo takes one argument (message), with the positional argument it should fail"
        verb ='POST'
        url = self.urlbase + 'echo/stuff'
        input_data={'message': 'unit test'}
        output={'code':400, 'type':'text/json'}
        methodTest(verb, url, input_data, output=output)

    def testBadMethodEcho(self):
        """
        The echo method isn't supported by GET, so should raise a 405
        """
        verb ='GET'
        url = self.urlbase + 'echo'
        input={'data': 'unit test'}
        output={'code':405, 'type':'text/json'}

        methodTest(verb, url, input, output=output)

    def testBadVerbEcho(self):
        "echo is only available to GET and POST, so should raise a 501"
        url = self.urlbase + 'echo'
        input={'data': 'unit test'}
        output={'code':501, 'type':'text/json'}

        for verb in ['DELETE']:
          methodTest(verb, url, input, output=output)

    def testPing(self):
        verb ='GET'
        url = self.urlbase + 'ping'
        output={'code':200, 'type':'text/json', 'data':'"ping"'}
        expireTime =3600

        methodTest(verb, url, output=output, expireTime=expireTime)

    def testBadPing(self):
        verb ='GET'

        url = self.urlbase + 'wrong'
        output={'code':404}
        methodTest(verb, url, output=output)

        url = self.urlbase + 'echo'
        output={'code':405}
        methodTest(verb, url, output=output)


        url = self.urlbase + 'ping/wrong'
        output={'code':400}
        methodTest(verb, url, output=output)

    def testException(self):
        """
        list takes a single integer argument, querying with a string
        """
        url = self.urlbase + 'list?int=a'
        self.assertRaises(urllib2.HTTPError, urllib2.urlopen, url)
        # urllib2,urlopen raise the error but not urllib.urlopen
        url = self.urlbase + 'list1?int=a'
        expected_data = {"exception": 400, "type": "HTTPError", "message": "Invalid input"}
        urllib_data = urllib.urlopen(url)
#.........這裏部分代碼省略.........
開發者ID:,項目名稱:,代碼行數:101,代碼來源:

示例11: testRepeatCalls

class testRepeatCalls(RESTBaseUnitTest):
    def initialize(self):
        self.config = DefaultConfig()
        self.config.UnitTests.templates = getWMBASE() + '/src/templates/WMCore/WebTools'
        self.config.Webtools.section_('server')
        self.config.Webtools.server.socket_timeout = 1
        self.urlbase = self.config.getServerUrl()
        self.cache_path = tempfile.mkdtemp()

    def tearDown(self):
        shutil.rmtree(self.cache_path, ignore_errors = True)
        self.rt.stop()

    def test10Calls(self):
        fail_count = 0
        req = Requests.Requests(self.urlbase, {'req_cache_path': self.cache_path})

        for i in range(0, 5):
            time.sleep(i)
            print('test %s starting at %s' % (i, time.time()))
            try:
                result = req.get('/', incoming_headers={'Cache-Control':'no-cache'})
                self.assertEqual(False, result[3])
                self.assertEqual(200, result[1])
            except HTTPException as he:
                print('test %s raised a %s error' % (i, he.status))
                fail_count += 1
            except Exception as e:
                print('test %s raised an unexpected exception of type %s' % (i, type(e)))
                print(e)
                fail_count += 1
        if fail_count > 0:
            raise Exception('Test did not pass!')

    def test10Calls_with_pycurl(self):
        fail_count = 0
        idict = {'req_cache_path': self.cache_path, 'pycurl':1}
        req = Requests.Requests(self.urlbase, idict)

        for i in range(0, 5):
            time.sleep(i)
            print('test %s starting at %s' % (i, time.time()))
            try:
                result = req.get('/', incoming_headers={'Cache-Control':'no-cache'}, decode=False)
                self.assertEqual(False, result[3])
                self.assertEqual(200, result[1])
            except HTTPException as he:
                print('test %s raised a %s error' % (i, he.status))
                fail_count += 1
            except Exception as e:
                print('test %s raised an unexpected exception of type %s' % (i, type(e)))
                print(e)
                fail_count += 1
        if fail_count > 0:
            raise Exception('Test did not pass!')

    def testRecoveryFromConnRefused(self):
        """Connections succeed after server down"""
        import socket
        self.rt.stop()
        req = Requests.Requests(self.urlbase, {'req_cache_path': self.cache_path})
        headers = {'Cache-Control':'no-cache'}
        self.assertRaises(socket.error, req.get, '/', incoming_headers=headers)

        # now restart server and hope we can connect
        self.rt.start(blocking=False)
        result = req.get('/', incoming_headers=headers)
        self.assertEqual(result[3], False)
        self.assertEqual(result[1], 200)

    def testRecoveryFromConnRefused_with_pycurl(self):
        """Connections succeed after server down"""
        import pycurl
        self.rt.stop()
        idict = {'req_cache_path': self.cache_path, 'pycurl':1}
        req = Requests.Requests(self.urlbase, idict)
        headers = {'Cache-Control':'no-cache'}
        self.assertRaises(pycurl.error, req.get, '/', incoming_headers=headers, decode=False)

        # now restart server and hope we can connect
        self.rt.start(blocking=False)
        result = req.get('/', incoming_headers=headers, decode=False)
        self.assertEqual(result[3], False)
        self.assertEqual(result[1], 200)
開發者ID:alexanderrichards,項目名稱:WMCore,代碼行數:84,代碼來源:Requests_t.py

示例12: RESTFormatTest

class RESTFormatTest(RESTBaseUnitTest):

    def initialize(self):
        self.config = DefaultConfig('WMCore_t.WebTools_t.DummyRESTModel')
        do_debug = False

        self.config.Webtools.environment = 'development'
        if do_debug:
            self.config.Webtools.error_log_level = logging.DEBUG
            self.config.Webtools.access_log_level = logging.DEBUG
        else:
            self.config.Webtools.error_log_level = logging.WARNING
            self.config.Webtools.access_log_level = logging.WARNING

        self.urlbase = self.config.getServerUrl()

    def testUnsupportedFormat(self):
        # test not accepted type should return 406 error
        url = self.urlbase +'list1/'
        methodTest('GET', url, accept='text/das', output={'code':406})

    def testSupportedFormat(self):
        rf = RESTFormatter(config=self.config.Webtools)
        url = self.urlbase +'list1/'

        for type in rf.supporttypes.keys():
            # test accepted type should return 200 error
            methodTest('GET', url, accept=type, output={'code':200})

    def testEncodedInput(self):
        type = 'text/plain'

        url = self.urlbase + 'list3?a=a%&b=b'
        methodTest('GET', url, accept=type,
                         output={'code':200, 'data':"{'a': 'a%', 'b': 'b'}"})

        request_input={'a':'%', 'b':'b'}

        #methodTest encoded input with urlencode
        url = self.urlbase +'list3'
        methodTest('GET', url, accept=type, request_input=request_input,
                 output={'code':200, 'data':"{'a': '%', 'b': 'b'}"})

    def testReturnFormat(self):
        return_type = 'application/json'

        url = self.urlbase +'list3?a=a%&b=b'
        methodTest('GET', url, accept=return_type,
                         output={'code':200, 'data':'{"a": "a%", "b": "b"}'})

        url = self.urlbase + 'list?input_int=a&input_str=a'
        expected_data = '''{"exception": 400, "message": "Invalid input", "type": "HTTPError"}'''
        methodTest('GET', url, accept=return_type,
                         output={'code':400, 'data':expected_data})

    def testNoArgMethods(self):
        """
        list1 takes no arguments, it should raise an error if called with one. Require json output.
        """
        return_type = 'application/json'
        url = self.urlbase + 'list1?int=a'
        expected_data = """{"exception": 400, "message": "Invalid input", "type": "HTTPError"}"""
        methodTest('GET', url, accept=return_type, output={'code':400, 'data':expected_data})
開發者ID:zhiwenuil,項目名稱:WMCore,代碼行數:63,代碼來源:RESTFormat_t.py

示例13: RESTFormatTest

class RESTFormatTest(RESTBaseUnitTest):

    def initialize(self):
        self.config = DefaultConfig('WMCore_t.WebTools_t.DummyRESTModel')
        do_debug = False

        self.config.Webtools.environment = 'development'
        if do_debug:
            self.config.Webtools.error_log_level = logging.DEBUG
            self.config.Webtools.access_log_level = logging.DEBUG
        else:
            self.config.Webtools.error_log_level = logging.WARNING
            self.config.Webtools.access_log_level = logging.WARNING

        self.urlbase = self.config.getServerUrl()

    def testUnsupportedFormat(self):
        # test not accepted type should return 406 error
        url = self.urlbase +'list1/'
        methodTest('GET', url, accept='text/das', output={'code':406})

    def testSupportedFormat(self):
        rf = RESTFormatter(config=self.config.Webtools)
        url = self.urlbase +'list1/'

        for textType in rf.supporttypes.keys():
            # test accepted type should return 200 error
            methodTest('GET', url, accept=textType, output={'code':200})

    # This test is flipping back and forth in Jenkins. Perhaps due to port 8888 not being available.
    # Disabling for now
    @attr("integration")
    def testEncodedInput(self):
        textType = 'text/plain'

        url = self.urlbase + 'list3?a=a%&b=b'
        data = json.dumps({'a': 'a%', 'b': 'b'})
        methodTest('GET', url, accept=textType,
                         output={'code':200, 'data':data})

        request_input={'a':'%', 'b':'b'}

        #methodTest encoded input with urlencode
        url = self.urlbase +'list3'
        data = json.dumps({'a': '%', 'b': 'b'})
        methodTest('GET', url, accept=textType, request_input=request_input,
                 output={'code':200, 'data':data})

    def testReturnFormat(self):
        return_type = 'application/json'

        url = self.urlbase +'list3?a=a%&b=b'
        methodTest('GET', url, accept=return_type,
                         output={'code':200, 'data':'{"a": "a%", "b": "b"}'})

        url = self.urlbase + 'list?input_int=a&input_str=a'
        expected_data = '''{"exception": 400, "message": "Invalid input: Input data failed validation.", "type": "HTTPError"}'''
        methodTest('GET', url, accept=return_type,
                         output={'code':400, 'data':expected_data})

    def testNoArgMethods(self):
        """
        list1 takes no arguments, it should raise an error if called with one. Require json output.
        """
        return_type = 'application/json'
        url = self.urlbase + 'list1?int=a'
        expected_data = """{"exception": 400, "message": "Invalid input: Arguments added where none allowed", "type": "HTTPError"}"""
        methodTest('GET', url, accept=return_type, output={'code':400, 'data':expected_data})

    def testGenerator(self):
        rf = RESTFormatter(config=self.config.Webtools)
        url = self.urlbase +'gen'
        # gen method from DummyRESTModel will return this generator
        gen = ({'idx':i} for i in range(10))
        # the WMCore should convert it into list regardless of accept type
        data = rf.json(gen)
        methodTest('GET', url, accept='application/json',
                         output={'code':200, 'data':data})
        methodTest('GET', url, accept='*/*',
                         output={'code':200, 'data':data})
開發者ID:BrunoCoimbra,項目名稱:WMCore,代碼行數:80,代碼來源:RESTFormat_t.py


注:本文中的WMQuality.WebTools.RESTServerSetup.DefaultConfig類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。