本文整理汇总了Python中swaggerpy.client.SwaggerClient类的典型用法代码示例。如果您正苦于以下问题:Python SwaggerClient类的具体用法?Python SwaggerClient怎么用?Python SwaggerClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SwaggerClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_alllow_null_as_response_if_allow_null_is_given
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_path_query_and_body_params
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)
示例3: test_error_if_response_is_null_and_allow_null_not_given
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)
示例4: test_success_on_post_with_form_params_with_files
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)
示例5: test_none_value_response_if_response_not_OK
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)
示例6: test_correct_route_with_basePath_as_slash
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)
示例7: test_success_on_returning_anything_for_type_void
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)
示例8: test_success_on_passing_default_value_if_param_not_passed
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'])
示例9: test_alllow_null_in_response_body_if_allow_null_is_given
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))
示例10: test_success_on_date_type
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))
示例11: test_append_base_path_if_base_path_isnt_absolute
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'])
示例12: test_error_on_incorrect_array_type_returned
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)
示例13: test_api_base_path_if_passed_is_always_used_as_base_path
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'])
示例14: test_success_on_returning_raw_response_if_given_in_parameter
def test_success_on_returning_raw_response_if_given_in_parameter(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?",
body='{"some_foo": "bar"}')
resource = SwaggerClient(u'http://localhost/api-docs').api_test
resp = resource.testHTTP(test_param="foo").result(raw_response=True)
self.assertEqual({"some_foo": "bar"}, resp)
示例15: test_success_on_complex_operation_response_type
def test_success_on_complex_operation_response_type(self):
self.register_urls()
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()
User = resource.models.User
School = resource.models.School
self.assertTrue(isinstance(resp, User))
[self.assertTrue(isinstance(x, School)) for x in resp.schools]
self.assertEqual(User(id=42, schools=[School(
name="School1"), School(name="School2")]), resp)