本文整理汇总了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))
示例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])