本文整理匯總了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)