当前位置: 首页>>代码示例>>Python>>正文


Python DefaultConfig.getServerUrl方法代码示例

本文整理汇总了Python中WMQuality.WebTools.RESTServerSetup.DefaultConfig.getServerUrl方法的典型用法代码示例。如果您正苦于以下问题:Python DefaultConfig.getServerUrl方法的具体用法?Python DefaultConfig.getServerUrl怎么用?Python DefaultConfig.getServerUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WMQuality.WebTools.RESTServerSetup.DefaultConfig的用法示例。


在下文中一共展示了DefaultConfig.getServerUrl方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testRepeatCalls

# 需要导入模块: from WMQuality.WebTools.RESTServerSetup import DefaultConfig [as 别名]
# 或者: from WMQuality.WebTools.RESTServerSetup.DefaultConfig import getServerUrl [as 别名]
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:,项目名称:,代码行数:33,代码来源:

示例2: FakeRESTServer

# 需要导入模块: from WMQuality.WebTools.RESTServerSetup import DefaultConfig [as 别名]
# 或者: from WMQuality.WebTools.RESTServerSetup.DefaultConfig import getServerUrl [as 别名]
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,代码行数:31,代码来源:FakeRESTServer.py

示例3: NestedModelTest

# 需要导入模块: from WMQuality.WebTools.RESTServerSetup import DefaultConfig [as 别名]
# 或者: from WMQuality.WebTools.RESTServerSetup.DefaultConfig import getServerUrl [as 别名]
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,代码行数:56,代码来源:NestedModel_t.py

示例4: WorkQueueTest

# 需要导入模块: from WMQuality.WebTools.RESTServerSetup import DefaultConfig [as 别名]
# 或者: from WMQuality.WebTools.RESTServerSetup.DefaultConfig import getServerUrl [as 别名]
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,代码行数:40,代码来源:WMBS_t.py

示例5: RESTTest

# 需要导入模块: from WMQuality.WebTools.RESTServerSetup import DefaultConfig [as 别名]
# 或者: from WMQuality.WebTools.RESTServerSetup.DefaultConfig import getServerUrl [as 别名]
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:,项目名称:,代码行数:103,代码来源:

示例6: testRepeatCalls

# 需要导入模块: from WMQuality.WebTools.RESTServerSetup import DefaultConfig [as 别名]
# 或者: from WMQuality.WebTools.RESTServerSetup.DefaultConfig import getServerUrl [as 别名]
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,代码行数:86,代码来源:Requests_t.py

示例7: RESTFormatTest

# 需要导入模块: from WMQuality.WebTools.RESTServerSetup import DefaultConfig [as 别名]
# 或者: from WMQuality.WebTools.RESTServerSetup.DefaultConfig import getServerUrl [as 别名]
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,代码行数:65,代码来源:RESTFormat_t.py

示例8: RESTFormatTest

# 需要导入模块: from WMQuality.WebTools.RESTServerSetup import DefaultConfig [as 别名]
# 或者: from WMQuality.WebTools.RESTServerSetup.DefaultConfig import getServerUrl [as 别名]
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,代码行数:82,代码来源:RESTFormat_t.py


注:本文中的WMQuality.WebTools.RESTServerSetup.DefaultConfig.getServerUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。