Python webtest.TestApp() Examples
The following are 30
code examples of webtest.TestApp().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
webtest
, or try the search function
.
Example #1
Source File: test_extract_errors.py From pyramid_openapi3 with MIT License | 6 votes |
def _testapp(self) -> TestApp: """Start up the app so that tests can send requests to it.""" from webtest import TestApp with tempfile.NamedTemporaryFile() as document: document.write(self.OPENAPI_YAML.encode()) document.seek(0) with Configurator() as config: config.include("pyramid_openapi3") config.pyramid_openapi3_spec(document.name) config.pyramid_openapi3_add_formatter("unique-name", self.UniqueName()) config.add_route("hello", "/hello") config.add_view( openapi=True, renderer="json", view=self.hello, route_name="hello" ) app = config.make_wsgi_app() return TestApp(app)
Example #2
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_wrong_component(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) include = components.includer(environ) with pytest.raises(bowerstatic.Error): include('nonexistent/nonexistent.js') return [b'<html><head></head><body>Hello!</body></html>'] injector = bower.injector(wsgi) c = Client(injector) c.get('/')
Example #3
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_endpoint_path(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) include = components.includer(environ) include('jquery') return [b'<html><head></head><body>Hello!</body></html>'] injector = bower.injector(wsgi) c = Client(injector) response = c.get('/') assert response.body == ( b'<html><head>' b'<script type="text/javascript" ' b'src="/bowerstatic/components/jquery/2.1.1/dist/jquery.js">' b'</script></head><body>Hello!</body></html>')
Example #4
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_specific_path_wrong_file(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) include = components.includer(environ) with pytest.raises(bowerstatic.Error): include('jquery/nonexistent.js') return [b'<html><head></head><body>Hello!</body></html>'] injector = bower.injector(wsgi) c = Client(injector) c.get('/')
Example #5
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_specific_path(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) include = components.includer(environ) include('jquery/dist/jquery.js') return [b'<html><head></head><body>Hello!</body></html>'] injector = bower.injector(wsgi) c = Client(injector) response = c.get('/') assert response.body == ( b'<html><head>' b'<script type="text/javascript" ' b'src="/bowerstatic/components/jquery/2.1.1/dist/jquery.js">' b'</script></head><body>Hello!</body></html>')
Example #6
Source File: update_issue_test.py From clusterfuzz with Apache License 2.0 | 6 votes |
def setUp(self): test_helpers.patch(self, [ 'datastore.data_handler.get_issue_description', 'datastore.data_handler.get_issue_summary', 'datastore.data_handler.get_stacktrace', 'datastore.data_handler.update_group_bug', 'libs.helpers.get_issue_tracker_for_testcase', 'libs.auth.get_current_user', 'handlers.testcase_detail.show.get_testcase_detail', 'libs.access.get_access', 'libs.issue_management.issue_tracker_policy.get', 'libs.issue_management.issue_filer.get_memory_tool_labels', ]) self.mock.get_access.return_value = access.UserAccess.Allowed self.mock.get_testcase_detail.return_value = {'testcase': 'yes'} self.mock.get_current_user().email = 'test@test.com' self.mock.get.return_value = CHROMIUM_POLICY self.app = webtest.TestApp( webapp2.WSGIApplication([('/', update_issue.Handler)])) self.testcase = data_types.Testcase() self.testcase.bug_information = '' self.testcase.crash_state = 'fake_crash_state' self.testcase.put()
Example #7
Source File: test_core.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_wrap(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) include = components.includer(environ) include('jquery/dist/jquery.js') return [b'<html><head></head><body>Hello!</body></html>'] wrapped = bower.wrap(wsgi) c = Client(wrapped) response = c.get('/') assert response.body == ( b'<html><head>' b'<script type="text/javascript" ' b'src="/bowerstatic/components/jquery/2.1.1/dist/jquery.js">' b'</script></head><body>Hello!</body></html>') response = c.get('/bowerstatic/components/jquery/2.1.1/dist/jquery.js') assert response.body == b'/* jquery.js 2.1.1 */\n'
Example #8
Source File: test_publisher.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_different_publisher_signature(): bower = bowerstatic.Bower(publisher_signature='static') bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) return [b'Hello!'] publisher = bower.publisher(wsgi) c = Client(publisher) response = c.get('/') assert response.body == b'Hello!' response = c.get( '/static/components/jquery/2.1.1/dist/jquery.js') assert response.body == b'/* jquery.js 2.1.1 */\n'
Example #9
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_specific_resource(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) jquery = components.resource('jquery/dist/jquery.js') def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) include = components.includer(environ) include(jquery) return [b'<html><head></head><body>Hello!</body></html>'] injector = bower.injector(wsgi) c = Client(injector) response = c.get('/') assert response.body == ( b'<html><head>' b'<script type="text/javascript" ' b'src="/bowerstatic/components/jquery/2.1.1/dist/jquery.js">' b'</script></head><body>Hello!</body></html>')
Example #10
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_endpoint_depends_on_main_missing(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) include = components.includer(environ) include('depends_on_missing_main') return [b'<html><head></head><body>Hello!</body></html>'] injector = bower.injector(wsgi) c = Client(injector) response = c.get('/') # without a main, it should just include nothing assert response.body == ( b'<html><head><script type="text/javascript" ' b'src="/bowerstatic/components/depends_on_missing_main/' b'2.1.1/resource.js"></script></head><body>Hello!</body></html>')
Example #11
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_missing_version_bower_components(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) include = components.includer(environ) include('missing-version-in-dot-bower-json') return [b'<html><head></head><body>Hello!</body></html>'] injector = bower.injector(wsgi) c = Client(injector) response = c.get('/') # without a main, it should just include nothing assert response.body == ( b'<html><head>' b'<script type="text/javascript" ' b'src="/bowerstatic/components/missing-version-in-dot-bower-json/' b'1.0/example.js"></script>' b'</head><body>Hello!</body></html>')
Example #12
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_endpoint_resource(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) jquery = components.resource('jquery') def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) include = components.includer(environ) include(jquery) return [b'<html><head></head><body>Hello!</body></html>'] injector = bower.injector(wsgi) c = Client(injector) response = c.get('/') assert response.body == ( b'<html><head>' b'<script type="text/javascript" ' b'src="/bowerstatic/components/jquery/2.1.1/dist/jquery.js">' b'</script></head><body>Hello!</body></html>')
Example #13
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_multiple_identical_inclusions(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) include = components.includer(environ) include('jquery') include('jquery') return [b'<html><head></head><body>Hello!</body></html>'] injector = bower.injector(wsgi) c = Client(injector) response = c.get('/') assert response.body == ( b'<html><head>' b'<script type="text/javascript" ' b'src="/bowerstatic/components/jquery/2.1.1/dist/jquery.js">' b'</script></head><body>Hello!</body></html>')
Example #14
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_no_head_to_inject(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) include = components.includer(environ) include('jquery/dist/jquery.js') return [b'<html><body>Hello!</body></html>'] injector = bower.injector(wsgi) c = Client(injector) response = c.get('/') assert response.body == b'<html><body>Hello!</body></html>'
Example #15
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_not_html_no_effect(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) include = components.includer(environ) include('jquery/dist/jquery.js') return [b'Hello!'] injector = bower.injector(wsgi) c = Client(injector) response = c.get('/') assert response.body == b'Hello!'
Example #16
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_PUT_no_effect(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) include = components.includer(environ) include('jquery/dist/jquery.js') return [b'<html><head></head><body>Hello!</body></html>'] injector = bower.injector(wsgi) c = Client(injector) response = c.put('/') assert response.body == b'<html><head></head><body>Hello!</body></html>'
Example #17
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_missing_renderer(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) include = components.includer(environ) include('jquery/dist/resource.foo') return [b'<html><head></head><body>Hello!</body></html>'] injector = bower.injector(wsgi) c = Client(injector) with pytest.raises(bowerstatic.Error): c.get('/')
Example #18
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_custom_renderer_string_format(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) include = components.includer(environ) include('jquery', '<link src="{url}">') return [b'<html><head></head><body>Hello!</body></html>'] injector = bower.injector(wsgi) c = Client(injector) response = c.get('/') assert response.body == ( b'<html><head>' b'<link src="/bowerstatic/components/jquery/2.1.1/dist/jquery.js">' b'</head><body>Hello!</body></html>')
Example #19
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_custom_renderer_callable(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def custom_renderer(resource): return '<link src="%s">' % resource.url() def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) include = components.includer(environ) include('jquery', custom_renderer) return [b'<html><head></head><body>Hello!</body></html>'] injector = bower.injector(wsgi) c = Client(injector) response = c.get('/') assert response.body == ( b'<html><head>' b'<link src="/bowerstatic/components/jquery/2.1.1/dist/jquery.js">' b'</head><body>Hello!</body></html>')
Example #20
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_inline_renderer(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) include = components.includer(environ) include('jquery', bowerstatic.renderer.render_inline_js) return [b'<html><head></head><body>Hello!</body></html>'] injector = bower.injector(wsgi) c = Client(injector) response = c.get('/') assert response.body == ( b'<html><head><script type="text/javascript">/* jquery.js 2.1.1 */\n' b'</script></head><body>Hello!</body></html>')
Example #21
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_no_inclusions(): bower = bowerstatic.Bower() bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html;charset=UTF-8')]) return [b'<html><head></head><body>Hello!</body></html>'] injector = bower.injector(wsgi) c = Client(injector) response = c.get('/') assert response.body == b'<html><head></head><body>Hello!</body></html>'
Example #22
Source File: test_injector.py From bowerstatic with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_injector_no_content_type_set(): bower = bowerstatic.Bower() components = bower.components('components', os.path.join( os.path.dirname(__file__), 'bower_components')) def wsgi(environ, start_response): start_response('200 OK', []) include = components.includer(environ) include('jquery/dist/jquery.js') return [b'SOME-BINARY-OR-NOT-HTML-DATA'] injector = bower.injector(wsgi) c = Client(injector) response = c.get('/') assert response.body == (b'SOME-BINARY-OR-NOT-HTML-DATA')
Example #23
Source File: update_from_trunk_test.py From clusterfuzz with Apache License 2.0 | 6 votes |
def setUp(self): test_helpers.patch(self, [ 'base.tasks.add_task', 'base.tasks.queue_for_job', 'libs.auth.get_current_user', 'handlers.testcase_detail.show.get_testcase_detail', 'libs.access.check_access_and_get_testcase', ]) self.app = webtest.TestApp( webapp2.WSGIApplication([('/', update_from_trunk.Handler)])) self.testcase = data_types.Testcase(queue='old-queue') self.testcase.put() self.mock.check_access_and_get_testcase.return_value = self.testcase self.mock.get_testcase_detail.return_value = {'testcase': 'yes'} self.mock.get_current_user().email = 'test@user.com'
Example #24
Source File: handler_test.py From clusterfuzz with Apache License 2.0 | 5 votes |
def test_without_needs_privilege(self): """Test without needs_previlege_access.""" self.mock.has_access.return_value = True self.app = webtest.TestApp( webapp2.WSGIApplication([('/', WithoutNeedsPrivilegeAccessHandler)])) resp = self.app.get('/') self.assertEqual(200, resp.status_int) self.assertEqual('without', resp.json['data']) self.mock.has_access.assert_called_once_with(need_privileged_access=False)
Example #25
Source File: handler_test.py From clusterfuzz with Apache License 2.0 | 5 votes |
def test_with_needs_privilege_access(self): """Test with needs_previlege_access.""" self.mock.has_access.return_value = True self.app = webtest.TestApp( webapp2.WSGIApplication([('/', NeedsPrivilegeAccessHandler)])) resp = self.app.get('/') self.assertEqual(200, resp.status_int) self.assertEqual('with', resp.json['data']) self.mock.has_access.assert_called_once_with(need_privileged_access=True)
Example #26
Source File: handler_test.py From clusterfuzz with Apache License 2.0 | 5 votes |
def test_get_json(self): """Get and receive JSON.""" self.app = webtest.TestApp(webapp2.WSGIApplication([('/', JsonGetHandler)])) resp = self.app.get('/', {'test': 123}) self.assertEqual(_JSON_CONTENT_TYPE, resp.headers['Content-Type']) self.assertEqual('123', resp.json['data'])
Example #27
Source File: handler_test.py From clusterfuzz with Apache License 2.0 | 5 votes |
def test_post_form_html(self): """Post Form-data and receive Html.""" self.app = webtest.TestApp( webapp2.WSGIApplication([('/', FormHtmlPostHandler)])) resp = self.app.post('/', {'test': 123}) self.assertNotEqual('application/json', resp.headers['Content-Type']) self.assertEqual(b'123', resp.body)
Example #28
Source File: handler_test.py From clusterfuzz with Apache License 2.0 | 5 votes |
def test_post_json_json_failure(self): """Fail to post JSON.""" self.app = webtest.TestApp( webapp2.WSGIApplication([('/', JsonJsonPostHandler)])) resp = self.app.post('/', {'test': 123}, expect_errors=True) self.assertEqual(_JSON_CONTENT_TYPE, resp.headers['Content-Type']) self.assertEqual(400, resp.status_int)
Example #29
Source File: handler_test.py From clusterfuzz with Apache License 2.0 | 5 votes |
def setUp(self): test_helpers.patch(self, [ 'config.db_config.get_value', 'libs.form.generate_csrf_token', 'libs.auth.is_current_user_admin', 'libs.auth.get_current_user', ]) self.mock.generate_csrf_token.return_value = 'csrf_token' self.mock.is_current_user_admin.return_value = False self.mock.get_current_user.return_value = auth.User('test@test.com') self.app = webtest.TestApp(webapp2.WSGIApplication([('/', CronHandler)]))
Example #30
Source File: handler_test.py From clusterfuzz with Apache License 2.0 | 5 votes |
def test_post_json_json(self): """Post JSON and receive JSON.""" self.app = webtest.TestApp( webapp2.WSGIApplication([('/', JsonJsonPostHandler)])) resp = self.app.post_json('/', {'test': 123}) self.assertEqual(_JSON_CONTENT_TYPE, resp.headers['Content-Type']) self.assertEqual(123, resp.json['data'])