本文整理汇总了Python中flask_peewee.tests.test_app.Message.get方法的典型用法代码示例。如果您正苦于以下问题:Python Message.get方法的具体用法?Python Message.get怎么用?Python Message.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_peewee.tests.test_app.Message
的用法示例。
在下文中一共展示了Message.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_auth_edit
# 需要导入模块: from flask_peewee.tests.test_app import Message [as 别名]
# 或者: from flask_peewee.tests.test_app.Message import get [as 别名]
def test_auth_edit(self):
self.create_messages()
message_data = {'content': 'edited'}
serialized = json.dumps(message_data)
url = '/api/message/%s/' % self.normal_message.id
# this request is not authorized
resp = self.app.put(url, data=serialized)
self.assertEqual(resp.status_code, 401)
# authorized, but user does not exist in database
resp = self.app.put(url, data=serialized, headers=self.auth_headers('xxx', 'xxx'))
self.assertEqual(resp.status_code, 401)
# authorized, user in database, but not owner
resp = self.app.put(url, data=serialized, headers=self.auth_headers('admin', 'admin'))
self.assertEqual(resp.status_code, 403)
# authorized, user in database, is owner
resp = self.app.put(url, data=serialized, headers=self.auth_headers('normal', 'normal'))
self.assertEqual(resp.status_code, 200)
obj = Message.get(id=self.normal_message.id)
self.assertEqual(obj.content, 'edited')
示例2: test_create
# 需要导入模块: from flask_peewee.tests.test_app import Message [as 别名]
# 或者: from flask_peewee.tests.test_app.Message import get [as 别名]
def test_create(self):
message_data = {'content': 'test'}
serialized = json.dumps(message_data)
# authorized as an admin
resp = self.app.post('/api/message/', data=serialized, headers=self.auth_headers('normal', 'normal'))
self.assertEqual(resp.status_code, 200)
new_message = Message.get(content='test')
self.assertEqual(new_message.user, self.normal)
resp_json = self.response_json(resp)
self.assertAPIMessage(resp_json, new_message)
示例3: test_edit
# 需要导入模块: from flask_peewee.tests.test_app import Message [as 别名]
# 或者: from flask_peewee.tests.test_app.Message import get [as 别名]
def test_edit(self):
self.create_messages()
message_data = {'content': 'edited'}
serialized = json.dumps(message_data)
url = '/api/message/%s/' % self.normal_message.id
# authorized as normal
resp = self.app.put(url, data=serialized, headers=self.auth_headers('normal', 'normal'))
self.assertEqual(resp.status_code, 200)
message = Message.get(id=self.normal_message.id)
self.assertEqual(message.content, 'edited')
resp_json = self.response_json(resp)
self.assertAPIMessage(resp_json, message)