本文整理汇总了Python中main.app方法的典型用法代码示例。如果您正苦于以下问题:Python main.app方法的具体用法?Python main.app怎么用?Python main.app使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类main
的用法示例。
在下文中一共展示了main.app方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_app
# 需要导入模块: import main [as 别名]
# 或者: from main import app [as 别名]
def test_app(testbed):
key_name = 'foo'
testbed.init_taskqueue_stub(root_path=os.path.dirname(__file__))
app = webtest.TestApp(main.app)
app.post('/', {'key': key_name})
tq_stub = testbed.get_stub(gaetestbed.TASKQUEUE_SERVICE_NAME)
tasks = tq_stub.get_filtered_tasks()
assert len(tasks) == 1
assert tasks[0].name == 'task1'
with mock.patch('main.update_counter') as mock_update:
# Force update to fail, otherwise the loop will go forever.
mock_update.side_effect = RuntimeError()
app.get('/_ah/start', status=500)
assert mock_update.called
示例2: firestore
# 需要导入模块: import main [as 别名]
# 或者: from main import app [as 别名]
def firestore():
import firestore
"""This fixture provides a modified version of the app's Firebase model that
tracks all created items and deletes them at the end of the test.
Any tests that directly or indirectly interact with the database should use
this to ensure that resources are properly cleaned up.
"""
# Ensure no books exist before running the tests. This typically helps if
# tests somehow left the database in a bad state.
delete_all_books(firestore)
yield firestore
# Delete all books that we created during tests.
delete_all_books(firestore)
示例3: test_add
# 需要导入模块: import main [as 别名]
# 或者: from main import app [as 别名]
def test_add(app):
data = {
'title': 'Test Book',
'author': 'Test Author',
'publishedDate': 'Test Date Published',
'description': 'Test Description'
}
with app.test_client() as c:
rv = c.post('books/add', data=data, follow_redirects=True)
assert rv.status == '200 OK'
body = rv.data.decode('utf-8')
assert 'Test Book' in body
assert 'Test Author' in body
assert 'Test Date Published' in body
assert 'Test Description' in body
示例4: test_upload_image
# 需要导入模块: import main [as 别名]
# 或者: from main import app [as 别名]
def test_upload_image(app):
data = {
'title': 'Test Book',
'author': 'Test Author',
'publishedDate': 'Test Date Published',
'description': 'Test Description',
'image': (BytesIO(b'hello world'), 'hello.jpg')
}
with app.test_client() as c:
rv = c.post('books/add', data=data, follow_redirects=True)
assert rv.status == '200 OK'
body = rv.data.decode('utf-8')
img_tag = re.search('<img.*?src="(.*)"', body).group(1)
r = requests.get(img_tag)
assert r.status_code == 200
assert r.text == 'hello world'
示例5: setUp
# 需要导入模块: import main [as 别名]
# 或者: from main import app [as 别名]
def setUp(self):
# Wrap the app with WebTest's TestApp.
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_memcache_stub()
self.testbed.init_datastore_v3_stub()
from main import app
self.testapp = TestApp(app)
示例6: test_app
# 需要导入模块: import main [as 别名]
# 或者: from main import app [as 别名]
def test_app(testbed):
app = webtest.TestApp(main.app)
response = app.get('/')
assert response.status_int == 200
示例7: send_request
# 需要导入模块: import main [as 别名]
# 或者: from main import app [as 别名]
def send_request(self, path, post=None, json_data=None, headers=None,
method=None):
"""
Send request to main app. Returns response object.
If json_data is given (dict) it is encoded and sent as post payload.
"""
if headers is None:
headers = {}
if json_data is not None:
post = json.dumps(json_data)
headers['Content-Type'] = 'application/json'
request = webapp2.Request.blank(path, POST=post, headers=headers)
if method:
request.method = method
return request.get_response(main.app)
示例8: test_app
# 需要导入模块: import main [as 别名]
# 或者: from main import app [as 别名]
def test_app(testbed):
app = webtest.TestApp(main.app)
app.get('/')
示例9: test_get
# 需要导入模块: import main [as 别名]
# 或者: from main import app [as 别名]
def test_get():
app = webtest.TestApp(main.app)
try:
response = app.get('/')
assert response.status_int == 403
except webtest.app.AppError as e:
assert '403 Forbidden' in str(e)
示例10: app
# 需要导入模块: import main [as 别名]
# 或者: from main import app [as 别名]
def app():
return webtest.TestApp(main.app)
示例11: test_get_module_info
# 需要导入模块: import main [as 别名]
# 或者: from main import app [as 别名]
def test_get_module_info(modules_mock, app):
modules_mock.get_current_module_name.return_value = "default"
modules_mock.get_current_instance_id.return_value = 1
response = app.get('/')
assert response.status_int == 200
results = response.body.split('&')
assert results[0].split('=')[1] == 'default'
assert results[1].split('=')[1] == '1'
示例12: test_get_backend
# 需要导入模块: import main [as 别名]
# 或者: from main import app [as 别名]
def test_get_backend(url_open_mock, modules_mock, app):
url_read_mock = mock.Mock(read=mock.Mock(return_value='hello world'))
url_open_mock.return_value = url_read_mock
response = app.get('/access_backend')
assert response.status_int == 200
assert response.body == 'Got response hello world'
示例13: test_background
# 需要导入模块: import main [as 别名]
# 或者: from main import app [as 别名]
def test_background(thread, app):
app.get('/dog')
response = app.get('/')
assert response.status_int == 200
assert response.body == 'Dog'
app.get('/cat')
# no stub for system so manually set
main.val = 'Cat'
response = app.get('/')
assert response.status_int == 200
assert response.body == 'Cat'
示例14: test_background_auto_start
# 需要导入模块: import main [as 别名]
# 或者: from main import app [as 别名]
def test_background_auto_start(thread, app):
app.get('/dog')
response = app.get('/')
assert response.status_int == 200
assert response.body == 'Dog'
app.get('/cat?auto=True')
# no stub for system so manually set
main.val = 'Cat'
response = app.get('/')
assert response.status_int == 200
assert response.body == 'Cat'
示例15: test_app
# 需要导入模块: import main [as 别名]
# 或者: from main import app [as 别名]
def test_app(testbed):
app = webtest.TestApp(main.app)
response = app.get('/')
assert response.status_int == 200
assert 'Logging example' in response.text