本文整理汇总了Python中webtest.TestApp.delete_json方法的典型用法代码示例。如果您正苦于以下问题:Python TestApp.delete_json方法的具体用法?Python TestApp.delete_json怎么用?Python TestApp.delete_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webtest.TestApp
的用法示例。
在下文中一共展示了TestApp.delete_json方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_users_delete
# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import delete_json [as 别名]
def test_users_delete(self):
"""
register a username, get an auth token, delete user again
idea: register second user to check
"""
app = TestApp(main({}))
_name = "mary"
res = app.put("/users", _name, status=200)
self.assertTrue("application/json; charset=UTF-8" in res.headers["Content-Type"])
# store the body as json
_json = json.loads(res.body)
# print(_json['token'])
self.assertTrue("0.1dev" in _json["api-version"])
self.assertTrue(_name in str(_json["token"]))
_token = _json["token"]
# print("the token from res: " + _token)
# try using an invalid token: get coverage for the valid_token function
_invalid_token = _token.replace("-", "") # removing the '-'
# print("_invalid_token: " + _invalid_token)
_auth_header = {"X-Messaging-Token": str(_invalid_token)}
# calling with the invalid_token we expect 401: Unauthorized
res2 = app.delete_json("/users", params=_name, headers=_auth_header, status=401)
_auth_header = {"X-Messaging-Token": str(_token)}
# now we have a token and can authenticate... and delete the user
# delete the user
# res2 = app.delete('/users', params=_name,
res2 = app.delete_json("/users", params=_name, headers=_auth_header, status=200)
# print(res2)
self.assertTrue("goodbye" in json.loads(res2.body).keys())
self.assertTrue(_name in json.loads(res2.body).values())
示例2: ApplicationTestMixin
# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import delete_json [as 别名]
class ApplicationTestMixin(object):
def setUp(self):
super(ApplicationTestMixin, self).setUp()
self.config = {"db" : {"url" : "sqlite://"}}
self.great = create_app(config=self.config)
self.app = TestApp(wsgi.create_app(self.great))
METADATA.create_all(self.great.bin.provide("db"))
def create(self, **params):
return self.app.post_json(self.URL, params=params).json
def delete(self, **params):
return self.app.delete_json(self.URL, params=params)
def list(self, **params):
return self.app.get(self.URL, params=params).json