本文整理汇总了Python中webtest.TestApp类的典型用法代码示例。如果您正苦于以下问题:Python TestApp类的具体用法?Python TestApp怎么用?Python TestApp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestApp类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_enforce_https_wrong
def test_enforce_https_wrong(self):
config = copy.deepcopy(SHARED_DEFAULTS)
config["enforce_https"] = True
application = RoutingApplication(config)
app = TestApp(application, extra_environ={"REMOTE_ADDR": "127.0.0.1"})
app.get("/", status=406)
app.post("/connect", status=406)
开发者ID:AppEnlight,项目名称:channelstream,代码行数:7,代码来源:tests_integration.py
示例2: IntegrationTests
class IntegrationTests(unittest.TestCase):
def setUp(self):
from webtest import TestApp
from pyramid.paster import get_app
app = get_app('development.ini')
self.app = TestApp(app)
def tearDown(self):
testing.tearDown()
def test_login_view(self):
self.app.authorization = ('Basic', ('user', 'password'))
response = self.app.get('/login')
self.assertEqual(response.status_int, 200)
def test_logout_view(self):
# run login to start session
self.app.authorization = ('Basic', ('user', 'password'))
self.app.get('/login')
response = self.app.get('/logout')
self.assertEqual(response.status_int, 200)
def test_logout_not_loggedin(self):
# expect 403 when trying to log out again
from pyramid.httpexceptions import HTTPForbidden
response = self.app.get('/logout', expect_errors=True)
self.assertEqual(response.status_int, 401)
开发者ID:T0MASD,项目名称:keel,代码行数:31,代码来源:test_views_auth.py
示例3: GetCompletions_ClangCompleter_ForceSemantic_OnlyFileteredCompletions_test
def GetCompletions_ClangCompleter_ForceSemantic_OnlyFileteredCompletions_test():
app = TestApp( handlers.app )
contents = """
int main()
{
int foobar;
int floozar;
int gooboo;
int bleble;
fooar
}
"""
# 0-based line and column!
completion_data = BuildRequest( filepath = '/foo.cpp',
filetype = 'cpp',
force_semantic = True,
contents = contents,
line_num = 8,
column_num = 7,
start_column = 7,
query = 'fooar',
compilation_flags = ['-x', 'c++'] )
results = app.post_json( '/completions', completion_data ).json
assert_that( results,
contains_inanyorder( CompletionEntryMatcher( 'foobar' ),
CompletionEntryMatcher( 'floozar' ) ) )
开发者ID:nop00,项目名称:YouCompleteMe,代码行数:29,代码来源:get_completions_test.py
示例4: _RunCompleterCommand_Message_Clang
def _RunCompleterCommand_Message_Clang(filename, test, command):
contents = open( PathToTestFile( filename ) ).read()
app = TestApp( handlers.app )
common_args = {
'completer_target' : 'filetype_default',
'command_arguments' : command,
'compilation_flags' : ['-x',
'c++',
'-std=c++11'],
'line_num' : 10,
'column_num' : 3,
'contents' : contents,
'filetype' : 'cpp'
}
args = test[0]
expected = test[1];
request = common_args
request.update( args )
request_data = BuildRequest( **request )
eq_( {'message': expected},
app.post_json( '/run_completer_command', request_data ).json )
开发者ID:ballercat,项目名称:ycmd,代码行数:26,代码来源:subcommands_test.py
示例5: test_create_hosted_zone_xml
def test_create_hosted_zone_xml():
app = TestApp(api.api)
request = open('createhostedzone.xml', 'r').read()
response = app.post('/hostedzone', request)
#reply = open('createhostedzone_response.xml', 'r').read()
assert response.status == '201 Created'
print response.body
开发者ID:chiradeep,项目名称:tirpunn,代码行数:7,代码来源:test_create_hosted_zone.py
示例6: test_simple_generic
def test_simple_generic(self):
class RootController(object):
@expose(generic=True)
def index(self):
pass
@index.when(method="POST", template="json")
def do_post(self):
return dict(result="POST")
@index.when(method="GET")
def do_get(self):
return "GET"
app = TestApp(Pecan(RootController()))
r = app.get("/")
assert r.status_int == 200
assert r.body == "GET"
r = app.post("/")
assert r.status_int == 200
assert r.body == dumps(dict(result="POST"))
r = app.get("/do_get", status=404)
assert r.status_int == 404
开发者ID:johnmontero,项目名称:pecan,代码行数:25,代码来源:test_generic.py
示例7: test_pull_task
def test_pull_task():
test_app = TestApp(app)
session = create_session()
task1 = Task()
task1.uuid = 'de305d54-75b4-431b-adb2-eb6b9e546018'
task1.test_id = 'de305d54-75b4-431b-adb2-eb6b9e546018'
task1.claimed = datetime.utcnow()
task1.data = json.dumps({'wait_time': 123})
session.add(task1)
task2 = Task()
task2.uuid = 'de305d54-75b4-431b-adb2-eb6b9e546019'
task2.test_id = 'de305d54-75b4-431b-adb2-eb6b9e546019'
task2.claimed = datetime.utcnow()
task2.completed = datetime.utcnow()
task2.result_data = json.dumps({'result': 'epic success'})
session.add(task2)
task3 = Task()
task3.uuid = 'de305d54-75b4-431b-adb2-eb6b9e546020'
task3.test_id = 'de305d54-75b4-431b-adb2-eb6b9e546020'
task3.claimed = datetime.utcnow()
task3.failed = datetime.utcnow()
task3.error = 'unknown error'
session.add(task3)
session.commit()
test_app.get('/task/de305d54-75b4-431b-adb2-eb6b9e546018')
test_app.get('/task/de305d54-75b4-431b-adb2-eb6b9e546019')
test_app.get('/task/de305d54-75b4-431b-adb2-eb6b9e546020')
开发者ID:SLAMon,项目名称:SLAMon,代码行数:32,代码来源:bpms_routes_tests.py
示例8: RunCompleterCommand_GoTo_Clang_ZeroBasedLineAndColumn_test
def RunCompleterCommand_GoTo_Clang_ZeroBasedLineAndColumn_test():
app = TestApp( handlers.app )
contents = """
struct Foo {
int x;
int y;
char c;
};
int main()
{
Foo foo;
return 0;
}
"""
goto_data = BuildRequest( completer_target = 'filetype_default',
command_arguments = ['GoToDefinition'],
compilation_flags = ['-x', 'c++'],
line_num = 10,
column_num = 3,
contents = contents,
filetype = 'cpp' )
eq_( {
'filepath': '/foo',
'line_num': 2,
'column_num': 8
},
app.post_json( '/run_completer_command', goto_data ).json )
开发者ID:Lekensteyn,项目名称:ycmd,代码行数:30,代码来源:subcommands_test.py
示例9: ImperativeIncludeConfigurationTest
class ImperativeIncludeConfigurationTest(unittest.TestCase):
def setUp(self):
from pyramid.config import Configurator
config = Configurator()
from pyramid.tests.pkgs.includeapp1.root import configure
configure(config)
app = config.make_wsgi_app()
from webtest import TestApp
self.testapp = TestApp(app)
self.config = config
def tearDown(self):
self.config.end()
def test_root(self):
res = self.testapp.get('/', status=200)
self.assertTrue(b'root' in res.body)
def test_two(self):
res = self.testapp.get('/two', status=200)
self.assertTrue(b'two' in res.body)
def test_three(self):
res = self.testapp.get('/three', status=200)
self.assertTrue(b'three' in res.body)
开发者ID:HorizonXP,项目名称:pyramid,代码行数:25,代码来源:test_integration.py
示例10: test_disconnect_hooks_multiple_listener
def test_disconnect_hooks_multiple_listener(self):
hook1_has_been_called = []
def hook1_listener():
hook1_has_been_called.append(True)
hook2_has_been_called = []
def hook2_listener():
hook2_has_been_called.append(True)
class RootController(TGController):
@expose()
def test(self):
tg.hooks.notify('custom_hook', controller=RootController.test)
return 'HI!'
conf = AppConfig(minimal=True, root_controller=RootController())
tg.hooks.register('custom_hook', hook1_listener)
tg.hooks.register('custom_hook', hook2_listener)
conf.package = PackageWithModel()
app = conf.make_wsgi_app()
app = TestApp(app)
app.get('/test')
app.get('/test')
tg.hooks.disconnect('custom_hook', hook2_listener)
app.get('/test')
# Disconnecting an unregistered hook should do nothing.
tg.hooks.disconnect('unregistered', hook1_listener)
assert len(hook1_has_been_called) == 3, hook1_has_been_called
assert len(hook2_has_been_called) == 2, hook2_has_been_called
开发者ID:984958198,项目名称:tg2,代码行数:32,代码来源:test_hooks.py
示例11: TestResource
class TestResource(unittest.TestCase):
def setUp(self):
from pyramid.renderers import JSONP
self.config = testing.setUp()
self.config.add_renderer("jsonp", JSONP(param_name="callback"))
self.config.include("cornice")
self.config.scan("cornice.tests.test_resource")
self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))
def tearDown(self):
testing.tearDown()
def test_basic_resource(self):
self.assertEquals(self.app.get("/users").json, {"status": "ok", "result": {"users": [1, 2]}})
self.assertEquals(self.app.get("/users/1").json, {"status": "ok", "result": {"name": "gawel"}})
resp = self.app.get("/users/1?callback=test")
self.assertEquals(resp.body, 'test({"status": "ok", "result": {"name": "gawel"}})', resp.body)
def test_accept_headers(self):
# the accept headers should work even in case they're specified in a
# resource method
self.assertEquals(
self.app.post("/users", headers={"Accept": "text/json"}, params=json.dumps({"test": "yeah"})).json,
{"status": "ok", "result": {"test": "yeah"}},
)
开发者ID:gulp-swe,项目名称:cornice,代码行数:28,代码来源:test_resource.py
示例12: test_config_hooks
def test_config_hooks(self):
class RootController(TGController):
@expose()
def test(self):
return 'HI!'
visited_hooks = []
def before_config_hook(app):
visited_hooks.append('before_config')
return app
def after_config_hook(app):
visited_hooks.append('after_config')
return app
def configure_new_app_hook(app):
assert isinstance(app, TGApp)
visited_hooks.append('configure_new_app')
conf = AppConfig(minimal=True, root_controller=RootController())
conf.register_hook('before_config', before_config_hook)
conf.register_hook('after_config', after_config_hook)
conf.register_hook('configure_new_app', configure_new_app_hook)
app = conf.make_wsgi_app()
app = TestApp(app)
assert 'HI!' in app.get('/test')
assert 'before_config' in visited_hooks
assert 'after_config' in visited_hooks
assert 'configure_new_app' in visited_hooks
开发者ID:984958198,项目名称:tg2,代码行数:28,代码来源:test_hooks.py
示例13: GetCompletions_ClangCompleter_WorksWithExplicitFlags_test
def GetCompletions_ClangCompleter_WorksWithExplicitFlags_test():
app = TestApp( handlers.app )
contents = """
struct Foo {
int x;
int y;
char c;
};
int main()
{
Foo foo;
foo.
}
"""
# 0-based line and column!
completion_data = BuildRequest( filepath = '/foo.cpp',
filetype = 'cpp',
contents = contents,
line_num = 10,
column_num = 6,
start_column = 6,
compilation_flags = ['-x', 'c++'] )
results = app.post_json( '/completions', completion_data ).json
assert_that( results, has_items( CompletionEntryMatcher( 'c' ),
CompletionEntryMatcher( 'x' ),
CompletionEntryMatcher( 'y' ) ) )
开发者ID:nop00,项目名称:YouCompleteMe,代码行数:29,代码来源:get_completions_test.py
示例14: get
def get(self, url, headers):
app = TestApp(wsgi.create_app(self.minion))
response = app.get(
url,
headers=[(k, ",".join(v)) for k , v in headers.canonicalized()],
)
return response.body
开发者ID:pombreda,项目名称:Minion,代码行数:7,代码来源:test_wsgi.py
示例15: RunCompleterCommand_GetType_TypescriptCompleter_test
def RunCompleterCommand_GetType_TypescriptCompleter_test():
app = TestApp( handlers.app )
filepath = PathToTestFile( 'test.ts' )
contents = open( filepath ).read()
event_data = BuildRequest( filepath = filepath,
filetype = 'typescript',
contents = contents,
event_name = 'BufferVisit' )
app.post_json( '/event_notification', event_data )
gettype_data = BuildRequest( completer_target = 'filetype_default',
command_arguments = ['GetType'],
line_num = 12,
column_num = 1,
contents = contents,
filetype = 'typescript',
filepath = filepath )
eq_( {
'message': 'var foo: Foo'
},
app.post_json( '/run_completer_command', gettype_data ).json )
开发者ID:ballercat,项目名称:ycmd,代码行数:25,代码来源:subcommands_test.py
示例16: test_get_with_var_args
def test_get_with_var_args(self):
class OthersController(object):
@expose()
def index(self, one, two, three):
return 'NESTED: %s, %s, %s' % (one, two, three)
class ThingsController(RestController):
others = OthersController()
@expose()
def get_one(self, *args):
return ', '.join(args)
class RootController(object):
things = ThingsController()
# create the app
app = TestApp(make_app(RootController()))
# test get request
r = app.get('/things/one/two/three')
assert r.status_int == 200
assert r.body == b_('one, two, three')
# test nested get request
r = app.get('/things/one/two/three/others/')
assert r.status_int == 200
assert r.body == b_('NESTED: one, two, three')
开发者ID:alex-devops,项目名称:pecan,代码行数:31,代码来源:test_rest.py
示例17: _RunCompleterCommand_GoTo_all_Clang
def _RunCompleterCommand_GoTo_all_Clang(filename, command, test):
contents = open( PathToTestFile( filename ) ).read()
app = TestApp( handlers.app )
common_request = {
'completer_target' : 'filetype_default',
'command_arguments' : command,
'compilation_flags' : ['-x',
'c++',
'-std=c++11'],
'line_num' : 10,
'column_num' : 3,
'contents' : contents,
'filetype' : 'cpp'
}
common_response = {
'filepath' : os.path.abspath( '/foo' ),
}
request = common_request
request.update({
'line_num' : test['request'][0],
'column_num': test['request'][1],
})
response = common_response
response.update({
'line_num' : test['response'][0],
'column_num': test['response'][1],
})
goto_data = BuildRequest( **request )
eq_( response,
app.post_json( '/run_completer_command', goto_data ).json )
开发者ID:ballercat,项目名称:ycmd,代码行数:33,代码来源:subcommands_test.py
示例18: test_404_with_lookup
def test_404_with_lookup(self):
class LookupController(RestController):
def __init__(self, _id):
self._id = _id
@expose()
def get_all(self):
return 'ID: %s' % self._id
class ThingsController(RestController):
@expose()
def _lookup(self, _id, *remainder):
return LookupController(_id), remainder
class RootController(object):
things = ThingsController()
# create the app
app = TestApp(make_app(RootController()))
# these should 404
for path in ('/things', '/things/'):
r = app.get(path, expect_errors=True)
assert r.status_int == 404
r = app.get('/things/foo')
assert r.status_int == 200
assert r.body == b_('ID: foo')
开发者ID:alex-devops,项目名称:pecan,代码行数:31,代码来源:test_rest.py
示例19: test_magical_methods
def test_magical_methods(self):
class MyKule(Kule):
def get_documents_list(self):
return {"foo": "bar"}
kule = MyKule(database="kule_test", collections=["documents"])
app = TestApp(kule.get_bottle_app())
self.assertEqual(app.get("/documents").json, {"foo": "bar"})
开发者ID:Jaykul,项目名称:kule,代码行数:7,代码来源:tests.py
示例20: test_post_task_invalid
def test_post_task_invalid():
test_app = TestApp(app)
assert test_app.post_json('/task', expect_errors=True).status_int == 400
assert test_app.post_json('/task', {
'task_id': 'de305d54-75b4-431b-adb2-eb6b9e546013',
'test_id': 'de305d54-75b4-431b-adb2-eb6b9e546013',
'task_type': 'wait',
'task_version': 'invalid_version',
'task_data': {
'wait_time': 3600
}
}, expect_errors=True).status_int == 400
assert test_app.post_json('/task', {
'task_id': 'de305d54-75b4-431b-adb2-eb6b9e546013_not_valid',
'test_id': 'de305d54-75b4-431b-adb2-eb6b9e546013',
'task_type': 'wait',
'task_version': 1,
'task_data': {
'wait_time': 3600
}
}, expect_errors=True).status_int == 400
assert test_app.post_json('/task', {
'test_id': 'de305d54-75b4-431b-adb2-eb6b9e546013',
'task_type': 'wait',
'task_version': 1,
'task_data': {
'wait_time': 3600
}
}, expect_errors=True).status_int == 400
开发者ID:SLAMon,项目名称:SLAMon,代码行数:33,代码来源:bpms_routes_tests.py
注:本文中的webtest.TestApp类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论