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


Python DefaultConfig.getModelConfig方法代码示例

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


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

示例1: RESTTest

# 需要导入模块: from WMQuality.WebTools.RESTServerSetup import DefaultConfig [as 别名]
# 或者: from WMQuality.WebTools.RESTServerSetup.DefaultConfig import getModelConfig [as 别名]

#.........这里部分代码省略.........
        urllib_data = urllib.urlopen(url)
        if self.do_production:
            #production mode returns 403 error
            self.assertEquals(urllib_data.getcode(), 403)
        else:
            response_data = urllib_data.read()
            response_data = json.loads(response_data)
            self.assertEquals(response_data['type'], expected_data['type'])
            self.assertEquals(response_data['message'], expected_data['message'])
            self.assertEquals(urllib_data.getcode(), 400)

    def testList(self):
        verb ='GET'
        url = self.urlbase + 'list/'
        request_input = {'input_int':123, 'input_str':'abc'}
        output={'code':200, 'type':'text/json'}
        result = json.loads(methodTest(verb, url, request_input=request_input, output=output)[0])
        for i in result.keys():
            self.assertEqual(result[i], request_input[i], '%s does not match response' % i)


    def testA(self):
        for t in ['GET', 'POST', 'PUT', 'DELETE', 'UPDATE']:
            response = makeRequest(url=self.urlbase + '/', values={'value':1234})
            assert response[1] == 200, 'Got a return code != 200 (got %s)' % response[1]

    def testSanitisePass(self):
        """
        Emulate how CherryPy passes arguments to a method, check that the data
        returned is correct.

        No server setup required
        """
        drm = DummyRESTModel(self.config.getModelConfig())

        def func(*args, **kwargs):
           sanitised_input = drm._sanitise_input(args, kwargs, "list")
           return drm.list(**sanitised_input)

        # 2 positional args (e.g. url/arg1/arg2)
        result = func(123, 'abc')
        assert result == {'input_int':123, 'input_str':'abc'},\
                                'list with 2 positional args failed: %s' % result
        # 2 query string args (e.g. url?int=arg1&str=arg2)
        result = func(input_int=123, input_str='abc')
        assert result == {'input_int':123, 'input_str':'abc'},\
                               'list with 2 query string args failed: %s' % result

        # 1 positional, 1 keyword  (e.g. url/arg1/?str=arg2)
        result = func(123, input_str='abc')
        assert result == {'input_int':123, 'input_str':'abc'},\
               'list with 1 positional, 1 keyword failed: %s' % result

    def testSanitisePassHTTP(self):
        """
        Same as testSanitisePass but do it over http and check the returned http
        codes.
        """
        # 2 positional args (e.g. url/arg1/arg2)
        url = self.urlbase + 'list/123/abc'
        response = makeRequest(url=url)
        assert response[1] == 200, \
             'list with 2 positional args failed: ' +\
             '. Got a return code != 200 (got %s)' % response[1] +\
             '. Returned data: %s' % response[0]
              # 2 query string args (e.g. url?int=arg1&str=arg2)
开发者ID:,项目名称:,代码行数:70,代码来源:


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