本文整理汇总了Python中swaggerpy.client.SwaggerClient.testHTTP方法的典型用法代码示例。如果您正苦于以下问题:Python SwaggerClient.testHTTP方法的具体用法?Python SwaggerClient.testHTTP怎么用?Python SwaggerClient.testHTTP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swaggerpy.client.SwaggerClient
的用法示例。
在下文中一共展示了SwaggerClient.testHTTP方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_alllow_null_as_response_if_allow_null_is_given
# 需要导入模块: from swaggerpy.client import SwaggerClient [as 别名]
# 或者: from swaggerpy.client.SwaggerClient import testHTTP [as 别名]
def test_alllow_null_as_response_if_allow_null_is_given(self):
self.register_urls()
httpretty.register_uri(
httpretty.GET, "http://localhost/test_http",
body=json.dumps(None))
resource = SwaggerClient(u'http://localhost/api-docs').api_test
resource.testHTTP().result(allow_null=True)
示例2: test_success_on_post_with_form_params_with_files
# 需要导入模块: from swaggerpy.client import SwaggerClient [as 别名]
# 或者: from swaggerpy.client.SwaggerClient import testHTTP [as 别名]
def test_success_on_post_with_form_params_with_files(self):
form_parameter_1 = {
"paramType": "form",
"name": "param_id",
"type": "integer"
}
form_parameter_2 = {
"paramType": "form",
"name": "file_name",
"type": "File"
}
self.response["apis"][0]["operations"][0]["method"] = "POST"
self.response["apis"][0]["operations"][0]["parameters"] = [
form_parameter_1, form_parameter_2]
self.register_urls()
httpretty.register_uri(
httpretty.POST, "http://localhost/test_http?", body='')
resource = SwaggerClient(u'http://localhost/api-docs').api_test
with open("test-data/1.2/simple/simple.json", "rb") as f:
resource.testHTTP(param_id=42, file_name=f).result()
content_type = httpretty.last_request().headers['content-type']
self.assertTrue(content_type.startswith('multipart/form-data'))
self.assertTrue("42" in httpretty.last_request().body)
# instead of asserting the contents, just assert filename is there
self.assertTrue("simple.json" in httpretty.last_request().body)
示例3: test_success_on_passing_default_value_if_param_not_passed
# 需要导入模块: from swaggerpy.client import SwaggerClient [as 别名]
# 或者: from swaggerpy.client.SwaggerClient import testHTTP [as 别名]
def test_success_on_passing_default_value_if_param_not_passed(self):
self.parameter['defaultValue'] = 'testString'
self.register_urls()
httpretty.register_uri(httpretty.GET,
"http://localhost/test_http?", body='')
resource = SwaggerClient(u'http://localhost/api-docs').api_test
resource.testHTTP().result()
self.assertEqual(['testString'],
httpretty.last_request().querystring['test_param'])
示例4: test_api_base_path_if_passed_is_always_used_as_base_path
# 需要导入模块: from swaggerpy.client import SwaggerClient [as 别名]
# 或者: from swaggerpy.client.SwaggerClient import testHTTP [as 别名]
def test_api_base_path_if_passed_is_always_used_as_base_path(self):
httpretty.register_uri(
httpretty.GET, "http://foo/test_http?", body='')
self.response["basePath"] = "http://localhost"
self.register_urls()
resource = SwaggerClient(u'http://localhost/api-docs',
api_base_path='http://foo').api_test
resource.testHTTP(test_param="foo").result()
self.assertEqual(["foo"],
httpretty.last_request().querystring['test_param'])
示例5: test_append_base_path_if_base_path_isnt_absolute
# 需要导入模块: from swaggerpy.client import SwaggerClient [as 别名]
# 或者: from swaggerpy.client.SwaggerClient import testHTTP [as 别名]
def test_append_base_path_if_base_path_isnt_absolute(self):
self.response["basePath"] = "/append"
httpretty.register_uri(
httpretty.GET, "http://localhost/append/test_http?",
body='[]')
self.register_urls()
resource = SwaggerClient(u'http://localhost/api-docs').api_test
resource.testHTTP(test_param="foo").result()
self.assertEqual(["foo"],
httpretty.last_request().querystring['test_param'])
示例6: test_success_on_post_with_path_query_and_body_params
# 需要导入模块: from swaggerpy.client import SwaggerClient [as 别名]
# 或者: from swaggerpy.client.SwaggerClient import testHTTP [as 别名]
def test_success_on_post_with_path_query_and_body_params(self):
query_parameter = self.parameter
path_parameter = {
"paramType": "path",
"name": "param_id",
"type": "string"
}
body_parameter = {
"paramType": "body",
"name": "body",
"type": "string"
}
self.response["apis"][0]["path"] = "/params/{param_id}/test_http"
operations = self.response["apis"][0]["operations"]
operations[0]["method"] = "POST"
operations[0]["parameters"] = [query_parameter,
path_parameter,
body_parameter]
self.register_urls()
httpretty.register_uri(
httpretty.POST,
"http://localhost/params/42/test_http?test_param=foo", body='')
resource = SwaggerClient(u'http://localhost/api-docs').api_test
resp = resource.testHTTP(test_param="foo", param_id="42",
body="some_test").result()
self.assertEqual('some_test', httpretty.last_request().body)
self.assertEqual(None, resp)
示例7: test_error_if_response_is_null_and_allow_null_not_given
# 需要导入模块: from swaggerpy.client import SwaggerClient [as 别名]
# 或者: from swaggerpy.client.SwaggerClient import testHTTP [as 别名]
def test_error_if_response_is_null_and_allow_null_not_given(self):
self.register_urls()
httpretty.register_uri(
httpretty.GET, "http://localhost/test_http",
body=json.dumps(None))
resource = SwaggerClient(u'http://localhost/api-docs').api_test
self.assertRaises(TypeError, resource.testHTTP().result)
示例8: test_none_value_response_if_response_not_OK
# 需要导入模块: from swaggerpy.client import SwaggerClient [as 别名]
# 或者: from swaggerpy.client.SwaggerClient import testHTTP [as 别名]
def test_none_value_response_if_response_not_OK(self):
self.register_urls()
httpretty.register_uri(
httpretty.GET, "http://localhost/test_http?test_param=foo",
status=500)
resource = SwaggerClient(u'http://localhost/api-docs').api_test
self.assertRaises(HTTPError,
resource.testHTTP(test_param="foo").result)
示例9: test_correct_route_with_basePath_as_slash
# 需要导入模块: from swaggerpy.client import SwaggerClient [as 别名]
# 或者: from swaggerpy.client.SwaggerClient import testHTTP [as 别名]
def test_correct_route_with_basePath_as_slash(self):
httpretty.register_uri(
httpretty.GET, "http://localhost/test_http?query=foo",
body='[]')
self.register_urls()
resource = SwaggerClient(u'http://localhost/api-docs').api_test
resp = resource.testHTTP(test_param="foo").result()
self.assertEqual([], resp)
示例10: test_success_on_passing_datetime_in_param
# 需要导入模块: from swaggerpy.client import SwaggerClient [as 别名]
# 或者: from swaggerpy.client.SwaggerClient import testHTTP [as 别名]
def test_success_on_passing_datetime_in_param(self):
query_parameter = {
"paramType": "query",
"name": "test_param",
"type": "string",
"format": "date-time"
}
self.response["apis"][0]["operations"][0]["parameters"] = [
query_parameter]
httpretty.register_uri(
httpretty.GET, "http://localhost/test_http", body='')
self.register_urls()
resource = SwaggerClient(u'http://localhost/api-docs').api_test
some_date = datetime(2014, 6, 10, 23, 49, 54, 728000, tzinfo=tzutc())
resource.testHTTP(test_param=some_date).result()
self.assertEqual(['2014-06-10 23:49:54.728000 00:00'],
httpretty.last_request().querystring['test_param'])
示例11: test_success_on_returning_anything_for_type_void
# 需要导入模块: from swaggerpy.client import SwaggerClient [as 别名]
# 或者: from swaggerpy.client.SwaggerClient import testHTTP [as 别名]
def test_success_on_returning_anything_for_type_void(self):
# default operation type is void
self.register_urls()
httpretty.register_uri(
httpretty.GET, "http://localhost/test_http?test_param=foo",
body='{"some_foo": "bar"}')
resource = SwaggerClient(u'http://localhost/api-docs').api_test
resp = resource.testHTTP(test_param="foo").result()
self.assertEqual({"some_foo": "bar"}, resp)
示例12: test_content_type_as_json_if_complex_type_in_body
# 需要导入模块: from swaggerpy.client import SwaggerClient [as 别名]
# 或者: from swaggerpy.client.SwaggerClient import testHTTP [as 别名]
def test_content_type_as_json_if_complex_type_in_body(self):
query_parameter = {
"paramType": "body",
"name": "body",
"type": "School",
}
school = {"name": "temp"}
self.response["apis"][0]["operations"][0]["type"] = "School"
self.response["apis"][0]["operations"][0]["parameters"] = [
query_parameter]
self.register_urls()
httpretty.register_uri(
httpretty.GET, "http://localhost/test_http",
body=json.dumps(school))
resource = SwaggerClient(u'http://localhost/api-docs').api_test
resource.testHTTP(body=school).result()
self.assertEqual("application/json", httpretty.last_request().headers[
'content-type'])
示例13: test_alllow_null_in_response_body_if_allow_null_is_given
# 需要导入模块: from swaggerpy.client import SwaggerClient [as 别名]
# 或者: from swaggerpy.client.SwaggerClient import testHTTP [as 别名]
def test_alllow_null_in_response_body_if_allow_null_is_given(self):
self.register_urls()
self.sample_model["schools"].append(None)
httpretty.register_uri(
httpretty.GET, "http://localhost/test_http",
body=json.dumps(self.sample_model))
resource = SwaggerClient(u'http://localhost/api-docs').api_test
resp = resource.testHTTP().result(allow_null=True)
self.assertTrue(isinstance(resp, resource.models.User))
示例14: test_success_on_date_type
# 需要导入模块: from swaggerpy.client import SwaggerClient [as 别名]
# 或者: from swaggerpy.client.SwaggerClient import testHTTP [as 别名]
def test_success_on_date_type(self):
self.response["apis"][0]["operations"][0]["type"] = "string"
self.response["apis"][0]["operations"][0]["format"] = "date"
self.register_urls()
httpretty.register_uri(
httpretty.GET, "http://localhost/test_http?test_param=foo",
body='"2014-06-10"')
resource = SwaggerClient(u'http://localhost/api-docs').api_test
resp = resource.testHTTP(test_param="foo").result()
self.assertEqual(resp, datetime.date(2014, 6, 10))
示例15: test_error_on_incorrect_array_type_returned
# 需要导入模块: from swaggerpy.client import SwaggerClient [as 别名]
# 或者: from swaggerpy.client.SwaggerClient import testHTTP [as 别名]
def test_error_on_incorrect_array_type_returned(self):
self.response["apis"][0]["operations"][0]["type"] = "array"
self.response["apis"][0]["operations"][0]["items"] = {"type": "string"}
self.register_urls()
httpretty.register_uri(
httpretty.GET, "http://localhost/test_http?test_param=foo",
body="123.32")
resource = SwaggerClient(u'http://localhost/api-docs').api_test
future = resource.testHTTP(test_param="foo")
self.assertRaises(TypeError, future)