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


Python TestApp.post方法代碼示例

本文整理匯總了Python中flask.ext.webtest.TestApp.post方法的典型用法代碼示例。如果您正苦於以下問題:Python TestApp.post方法的具體用法?Python TestApp.post怎麽用?Python TestApp.post使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在flask.ext.webtest.TestApp的用法示例。


在下文中一共展示了TestApp.post方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestSQLAlchemyFeatures

# 需要導入模塊: from flask.ext.webtest import TestApp [as 別名]
# 或者: from flask.ext.webtest.TestApp import post [as 別名]
class TestSQLAlchemyFeatures(unittest.TestCase):
    def setUp(self):
        self.app = create_app()
        self.w_without_scoping = TestApp(self.app)
        self.w = TestApp(self.app, db=db, use_session_scopes=True)

        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()

    def tearDown(self):
        db.drop_all()
        self.app_context.pop()

    def test_1(self):
        user = User(name='Anton')
        db.session.add(user)
        db.session.commit()

        r = self.w.get('/user/%i/' % user.id)
        self.assertEqual(r.body, 'Hello, Anton!')

        # Note: we did not commit the change to `user`!
        user.name = 'Petr'

        r = self.w_without_scoping.get('/user/%i/' % user.id)
        self.assertEqual(r.body, 'Hello, Petr!')

        r = self.w.get('/user/%i/' % user.id)
        self.assertEqual(r.body, 'Hello, Anton!')

    def test_2(self):
        user = User(name='Anton')
        db.session.add(user)
        db.session.commit()

        r = self.w.get('/user/%i/' % user.id)
        self.assertEqual(r.body, 'Hello, Anton!')

        r = self.w.post('/user/%i/preview/' % user.id, {
            'greeting': 'Hi, %s.',
        })
        self.assertEqual(r.body, 'Hi, Anton.')
        db.session.refresh(user)

        r = self.w_without_scoping.post('/user/%i/preview/' % user.id, {
            'greeting': 'Hi, %s.',
        })
        self.assertEqual(r.body, 'Hi, Anton.')
        self.assertRaises(
            sqlalchemy.exc.InvalidRequestError,
            lambda: db.session.refresh(user))
開發者ID:liushaochan,項目名稱:cn486,代碼行數:54,代碼來源:test.py

示例2: TestMainFeatures

# 需要導入模塊: from flask.ext.webtest import TestApp [as 別名]
# 或者: from flask.ext.webtest.TestApp import post [as 別名]
class TestMainFeatures(unittest.TestCase):
    def setUp(self):
        self.app = create_app()
        self.w = TestApp(self.app)
        self.app.config['TESTING'] = True

    def login(self, username, password):
        return self.w.post('/account/login', {
            'email': username,
            'password': password
        })

    def logout(self):
        return self.w.get('/account/logout')

    def test_home(self):
        r = self.w.get('/entry/')
        self.assertFalse(r.flashes)
        self.assertEqual(r.json, {u'code': ResultCode.SUCCESS})

    def test_curd(self):
        # add

        # 登錄
        # r = self.login('[email protected]', 'admin888')
        # print r
        # assert 'You were logged in' in r.data

        r = self.w.post('/entry/v1/create?category_id=1', {
            'creater_id': 1,
            'modifier_id': 1,

            'entry_type': EntryType.software,

            'title': '文章測試123',
            'content': '文章測試內容123',
            'summary': '123',
            'tags': 'tag1,tag2,tag3',

            'logo': '/1.gif',
            'feature_image': '/1.png',

            'source_title': '',
            'source_url': '',

            'source_type': EntrySourceType.original,

            'slug': 'ar/1',

            'recommend': 1

        })

        if r.json['code'] != ResultCode.SUCCESS:
            print r.json['message']

        print r

        self.assertFalse(r.flashes)
        self.assertIn(r.json['code'], [ResultCode.SUCCESS, ResultCode.DATA_EXISTED])

        # update
        r = self.w.post('/entry/v1/edit?category_id=1&entry_id=1', {
            'title': '文章測試123, edit',
        })

        print r
        if r.json['code'] != ResultCode.SUCCESS:
            print r.json['message']

        self.assertFalse(r.flashes)
        self.assertIn(r.json['code'], [ResultCode.SUCCESS, ResultCode.DATA_EXISTED])

        return
        # get
        r = self.w.get('/device/%s' % device_id)

        self.assertFalse(r.flashes)
        self.assertEqual(r.json['code'], ResultCode.SUCCESS)
        self.assertTrue(r.json['metadata'])

        # get_list
        r = self.w.get('/device/list?search=%s' % 'len')

        self.assertFalse(r.flashes)
        self.assertEqual(r.json['code'], ResultCode.SUCCESS)
        self.assertTrue(r.json['device_total'] >= 0)

        # del
        r = self.w.post('/device/delete', {
            'device_id': device_id, })

        self.assertFalse(r.flashes)
        self.assertIn(r.json['code'], [ResultCode.SUCCESS, ResultCode.DATA_EXISTED])
開發者ID:liushaochan,項目名稱:cn486,代碼行數:96,代碼來源:test_entry.py


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