當前位置: 首頁>>代碼示例>>Python>>正文


Python Message.get方法代碼示例

本文整理匯總了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')
開發者ID:0x19,項目名稱:flask-peewee,代碼行數:28,代碼來源:rest.py

示例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)
開發者ID:0x19,項目名稱:flask-peewee,代碼行數:15,代碼來源:rest.py

示例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)
開發者ID:0x19,項目名稱:flask-peewee,代碼行數:19,代碼來源:rest.py


注:本文中的flask_peewee.tests.test_app.Message.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。