當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。