Python webapp2.WSGIApplication() Examples

The following are 30 code examples for showing how to use webapp2.WSGIApplication(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module webapp2 , or try the search function .

Example 1
Project: clusterfuzz   Author: google   File: update_issue_test.py    License: Apache License 2.0 6 votes vote down vote up
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 2
Project: clusterfuzz   Author: google   File: update_from_trunk_test.py    License: Apache License 2.0 6 votes vote down vote up
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 3
Project: clusterfuzz   Author: google   File: create_issue_test.py    License: Apache License 2.0 6 votes vote down vote up
def setUp(self):
    test_helpers.patch(self, [
        'handlers.testcase_detail.show.get_testcase_detail',
        'libs.access.has_access',
        'libs.auth.get_current_user',
        'libs.issue_management.issue_filer.file_issue',
        'libs.issue_management.issue_tracker_utils.'
        'get_issue_tracker_for_testcase',
    ])
    self.mock.has_access.return_value = True
    self.mock.get_testcase_detail.return_value = {'testcase': 'yes'}
    self.mock.get_current_user().email = 'test@user.com'

    self.app = webtest.TestApp(
        webapp2.WSGIApplication([('/', create_issue.Handler)]))

    self.testcase = data_types.Testcase()
    self.testcase.put() 
Example 4
Project: clusterfuzz   Author: google   File: download_testcase_test.py    License: Apache License 2.0 6 votes vote down vote up
def _test_download(self, handler_class):
    """Test download."""
    testcase = data_types.Testcase()
    testcase.minimized_keys = 'key'
    testcase.put()

    self.mock.check_access_and_get_testcase.return_value = testcase

    app = webtest.TestApp(webapp2.WSGIApplication([('/', handler_class)]))
    resp = app.get('/?id=%s' % testcase.key.id())

    self.assertEqual(302, resp.status_int)
    # pylint: disable=line-too-long
    # According to https://cloud.google.com/appengine/docs/go/how-requests-are-handled
    # Appengine replaces X-AppEngine-BlobKey with the blob content.
    self.assertEqual(
        'https://SIGNED_URL&response-content-disposition=attachment'
        '%3B+filename%3Dtestcase-1-file.tar.gz', resp.location) 
Example 5
Project: clusterfuzz   Author: google   File: find_similar_issues_test.py    License: Apache License 2.0 6 votes vote down vote up
def setUp(self):
    test_helpers.patch(self, [
        'libs.access.check_access_and_get_testcase',
        'libs.issue_management.issue_tracker_utils.'
        'get_issue_tracker_for_testcase',
        'libs.issue_management.issue_tracker_utils.get_issue_url',
        'libs.issue_management.issue_tracker_utils.get_search_keywords',
        'libs.issue_management.issue_tracker_utils.get_similar_issues',
        'libs.issue_management.issue_tracker_utils.get_similar_issues_url',
    ])
    self.app = webtest.TestApp(
        webapp2.WSGIApplication([('/', find_similar_issues.Handler)]))

    self.testcase = data_types.Testcase()
    self.testcase.put()
    self.mock.check_access_and_get_testcase.return_value = self.testcase

    self.invalid_testcase_id = self.testcase.key.id() + 1 
Example 6
Project: clusterfuzz   Author: google   File: oss_fuzz_build_status_test.py    License: Apache License 2.0 6 votes vote down vote up
def setUp(self):
    self.app = webtest.TestApp(
        webapp2.WSGIApplication([('/build-status',
                                  oss_fuzz_build_status.Handler)]))

    test_helpers.patch(self, [
        'base.utils.utcnow',
        'handlers.base_handler.Handler.is_cron',
        'libs.issue_management.issue_tracker_utils.get_issue_tracker',
        'metrics.logs.log_error',
        'requests.get',
    ])

    self.mock.utcnow.return_value = datetime.datetime(2018, 2, 1)
    self.mock.is_cron.return_value = True

    self.itm = IssueTrackerManager('oss-fuzz')
    self.mock.get_issue_tracker.return_value = monorail.IssueTracker(self.itm)

    self.maxDiff = None  # pylint: disable=invalid-name 
Example 7
Project: clusterfuzz   Author: google   File: oss_fuzz_generate_certs_test.py    License: Apache License 2.0 6 votes vote down vote up
def setUp(self):
    test_helpers.patch_environ(self)
    test_helpers.patch(self, [
        'handlers.base_handler.Handler.is_cron',
    ])

    self.mock.is_cron.return_value = True
    self.app = webtest.TestApp(
        webapp2.WSGIApplication([('/generate-certs',
                                  oss_fuzz_generate_certs.Handler)]))

    data_types.OssFuzzProject(name='project1').put()
    data_types.OssFuzzProject(name='project2').put()

    data_types.WorkerTlsCert(
        id='project2',
        project_name='project2',
        cert_contents=b'cert_contents',
        key_contents=b'key_contents').put() 
Example 8
Project: clusterfuzz   Author: google   File: load_bigquery_stats_test.py    License: Apache License 2.0 6 votes vote down vote up
def setUp(self):
    self.app = webtest.TestApp(
        webapp2.WSGIApplication([('/load-bigquery-stats',
                                  load_bigquery_stats.Handler)]))

    data_types.Fuzzer(name='fuzzer', jobs=['job']).put()
    data_types.Job(name='job').put()

    test_helpers.patch(self, [
        'google_cloud_utils.big_query.get_api_client',
        'handlers.base_handler.Handler.is_cron',
        'handlers.cron.load_bigquery_stats.Handler._utc_now',
    ])

    self.mock._utc_now.return_value = datetime.datetime(2016, 9, 8)  # pylint: disable=protected-access
    self.mock_bigquery = mock.MagicMock()
    self.mock.get_api_client.return_value = self.mock_bigquery 
Example 9
Project: clusterfuzz   Author: google   File: testcase_list_test.py    License: Apache License 2.0 6 votes vote down vote up
def setUp(self):
    test_helpers.patch(self, [
        'base.external_users._allowed_entities_for_user',
        'base.external_users._get_permissions_query_for_user',
        'libs.access.get_user_job_type',
        'libs.access.has_access',
        'libs.helpers.get_user_email',
    ])
    self.app = webtest.TestApp(
        webapp2.WSGIApplication([('/', testcase_list.JsonHandler)]))

    self.testcases = []
    for i in range(10):
      t = data_types.Testcase()
      t.crash_type = ''
      t.crash_state = ''
      t.status = 'Processed'
      t.security_flag = True
      t.is_a_duplicate_flag = False
      t.one_time_crasher_flag = False
      t.open = True
      t.is_leader = True
      t.timestamp = datetime.datetime.fromtimestamp(100 - i)
      t.put()
      self.testcases.append(t) 
Example 10
Project: googleapps-message-recall   Author: google   File: auth.py    License: Apache License 2.0 6 votes vote down vote up
def get_store(factory=AuthStore, key=_store_registry_key, app=None):
    """Returns an instance of :class:`AuthStore` from the app registry.

    It'll try to get it from the current app registry, and if it is not
    registered it'll be instantiated and registered. A second call to this
    function will return the same instance.

    :param factory:
        The callable used to build and register the instance if it is not yet
        registered. The default is the class :class:`AuthStore` itself.
    :param key:
        The key used to store the instance in the registry. A default is used
        if it is not set.
    :param app:
        A :class:`webapp2.WSGIApplication` instance used to store the instance.
        The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    store = app.registry.get(key)
    if not store:
        store = app.registry[key] = factory(app)

    return store 
Example 11
Project: googleapps-message-recall   Author: google   File: jinja2.py    License: Apache License 2.0 6 votes vote down vote up
def get_jinja2(factory=Jinja2, key=_registry_key, app=None):
    """Returns an instance of :class:`Jinja2` from the app registry.

    It'll try to get it from the current app registry, and if it is not
    registered it'll be instantiated and registered. A second call to this
    function will return the same instance.

    :param factory:
        The callable used to build and register the instance if it is not yet
        registered. The default is the class :class:`Jinja2` itself.
    :param key:
        The key used to store the instance in the registry. A default is used
        if it is not set.
    :param app:
        A :class:`webapp2.WSGIApplication` instance used to store the instance.
        The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    jinja2 = app.registry.get(key)
    if not jinja2:
        jinja2 = app.registry[key] = factory(app)

    return jinja2 
Example 12
Project: googleapps-message-recall   Author: google   File: i18n.py    License: Apache License 2.0 6 votes vote down vote up
def __init__(self, app, config=None):
        """Initializes the i18n store.

        :param app:
            A :class:`webapp2.WSGIApplication` instance.
        :param config:
            A dictionary of configuration values to be overridden. See
            the available keys in :data:`default_config`.
        """
        config = app.config.load_config(self.config_key,
            default_values=default_config, user_values=config,
            required_keys=None)
        self.translations = {}
        self.translations_path = config['translations_path']
        self.domains = config['domains']
        self.default_locale = config['default_locale']
        self.default_timezone = config['default_timezone']
        self.date_formats = config['date_formats']
        self.set_locale_selector(config['locale_selector'])
        self.set_timezone_selector(config['timezone_selector']) 
Example 13
Project: googleapps-message-recall   Author: google   File: i18n.py    License: Apache License 2.0 6 votes vote down vote up
def get_store(factory=I18nStore, key=_store_registry_key, app=None):
    """Returns an instance of :class:`I18nStore` from the app registry.

    It'll try to get it from the current app registry, and if it is not
    registered it'll be instantiated and registered. A second call to this
    function will return the same instance.

    :param factory:
        The callable used to build and register the instance if it is not yet
        registered. The default is the class :class:`I18nStore` itself.
    :param key:
        The key used to store the instance in the registry. A default is used
        if it is not set.
    :param app:
        A :class:`webapp2.WSGIApplication` instance used to store the instance.
        The active app is used if it is not set.
    """
    app = app or webapp2.get_app()
    store = app.registry.get(key)
    if not store:
        store = app.registry[key] = factory(app)

    return store 
Example 14
Project: gae-secure-scaffold-python   Author: google   File: handlers_test.py    License: Apache License 2.0 5 votes vote down vote up
def setUp(self):
    self.testbed = testbed.Testbed()
    self.testbed.activate()
    self.testbed.init_datastore_v3_stub()
    self.testbed.init_memcache_stub()
    self.app = webapp2.WSGIApplication([('/', DummyHandler),
                                        ('/ajax', DummyAjaxHandler),
                                        ('/cron', DummyCronHandler),
                                        ('/task', DummyTaskHandler)]) 
Example 15
Project: pledgeservice   Author: MayOneUS   File: test_e2e.py    License: Apache License 2.0 5 votes vote down vote up
def setUp(self):
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    self.testbed.init_datastore_v3_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_urlfetch_stub()

    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)

    self.mockery = mox.Mox()
    self.stripe = self.mockery.CreateMock(handlers.StripeBackend)
    self.mailing_list_subscriber = self.mockery.CreateMock(
      handlers.MailingListSubscriber)
    self.mail_sender = env.MailSender(defer=False)

    self.env = handlers.Environment(
      app_name='unittest',
      stripe_public_key='pubkey1234',
      stripe_backend=self.stripe,
      mailing_list_subscriber=self.mailing_list_subscriber,
      mail_sender=self.mail_sender)

    from main import HANDLERS  # main import must come after other init
    self.wsgi_app = webapp2.WSGIApplication(HANDLERS + handlers.HANDLERS,
                                            config=dict(env=self.env))

    self.app = webtest.TestApp(self.wsgi_app) 
Example 16
Project: clusterfuzz   Author: google   File: handler_test.py    License: Apache License 2.0 5 votes vote down vote up
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 17
Project: clusterfuzz   Author: google   File: handler_test.py    License: Apache License 2.0 5 votes vote down vote up
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']) 
Example 18
Project: clusterfuzz   Author: google   File: handler_test.py    License: Apache License 2.0 5 votes vote down vote up
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 19
Project: clusterfuzz   Author: google   File: handler_test.py    License: Apache License 2.0 5 votes vote down vote up
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 20
Project: clusterfuzz   Author: google   File: handler_test.py    License: Apache License 2.0 5 votes vote down vote up
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 21
Project: clusterfuzz   Author: google   File: handler_test.py    License: Apache License 2.0 5 votes vote down vote up
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 22
Project: clusterfuzz   Author: google   File: handler_test.py    License: Apache License 2.0 5 votes vote down vote up
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 23
Project: clusterfuzz   Author: google   File: handler_test.py    License: Apache License 2.0 5 votes vote down vote up
def test_deny(self):
    """Test deny access."""
    self.mock.has_access.return_value = False
    self.mock.get_user_email.return_value = 'test@test.com'
    self.app = webtest.TestApp(
        webapp2.WSGIApplication([('/', WithoutNeedsPrivilegeAccessHandler)]))

    resp = self.app.get('/', expect_errors=True)
    self.assertEqual(403, resp.status_int)
    self.assertEqual('', resp.json['message'])
    self.assertEqual('test@test.com', resp.json['email'])
    self.mock.has_access.assert_called_once_with(need_privileged_access=False) 
Example 24
Project: clusterfuzz   Author: google   File: handler_test.py    License: Apache License 2.0 5 votes vote down vote up
def test_no_testcase_id(self):
    """Test no testcase id."""
    self.mock.check_access_and_get_testcase.side_effect = (
        helpers.AccessDeniedException())
    self.app = webtest.TestApp(
        webapp2.WSGIApplication([('/', CheckTestcaseAccessHandler)]))

    resp = self.app.post_json('/', {}, expect_errors=True)
    self.assertEqual(400, resp.status_int)
    self.assertRegex(resp.json['message'], '.*not a number.*') 
Example 25
Project: clusterfuzz   Author: google   File: handler_test.py    License: Apache License 2.0 5 votes vote down vote up
def test_invalid_testcase_id(self):
    """Test invalid testcase id."""
    self.mock.check_access_and_get_testcase.side_effect = (
        helpers.AccessDeniedException())
    self.app = webtest.TestApp(
        webapp2.WSGIApplication([('/', CheckTestcaseAccessHandler)]))

    resp = self.app.post_json('/', {'testcaseId': 'aaa'}, expect_errors=True)
    self.assertEqual(400, resp.status_int)
    self.assertRegex(resp.json['message'], '.*not a number.*') 
Example 26
Project: clusterfuzz   Author: google   File: handler_test.py    License: Apache License 2.0 5 votes vote down vote up
def test_allow(self):
    """Test allow."""
    testcase = data_types.Testcase()
    testcase.crash_state = 'state_value'
    self.mock.check_access_and_get_testcase.return_value = testcase
    self.app = webtest.TestApp(
        webapp2.WSGIApplication([('/', CheckTestcaseAccessHandler)]))

    resp = self.app.post_json('/', {'testcaseId': '123'}, expect_errors=True)
    self.assertEqual(200, resp.status_int)
    self.assertEqual('state_value', resp.json['state']) 
Example 27
Project: clusterfuzz   Author: google   File: handler_test.py    License: Apache License 2.0 5 votes vote down vote up
def test_allowed(self):
    """Test allowing admin."""
    self.mock.is_current_user_admin.return_value = True
    self.app = webtest.TestApp(
        webapp2.WSGIApplication([('/', CheckAdminAccessHandler)]))

    resp = self.app.post_json('/', {})
    self.assertEqual(200, resp.status_int)
    self.assertEqual('admin', resp.json['data']) 
Example 28
Project: clusterfuzz   Author: google   File: handler_test.py    License: Apache License 2.0 5 votes vote down vote up
def test_forbidden(self):
    """Test allowing admin."""
    self.mock.is_current_user_admin.return_value = False
    self.app = webtest.TestApp(
        webapp2.WSGIApplication([('/', CheckAdminAccessHandler)]))

    resp = self.app.post_json('/', {}, expect_errors=True)
    self.assertEqual(403, resp.status_int) 
Example 29
Project: clusterfuzz   Author: google   File: handler_test.py    License: Apache License 2.0 5 votes vote down vote up
def test_allowed_internal(self):
    """Test allowing non-admin and admin in internal."""
    self.mock.is_current_user_admin.return_value = False
    self.app = webtest.TestApp(
        webapp2.WSGIApplication([('/', CheckAdminAccessIfOssFuzzHandler)]))

    resp = self.app.post_json('/', {})
    self.assertEqual(200, resp.status_int)

    self.mock.is_current_user_admin.return_value = True
    resp = self.app.post_json('/', {})
    self.assertEqual(200, resp.status_int) 
Example 30
Project: clusterfuzz   Author: google   File: handler_test.py    License: Apache License 2.0 5 votes vote down vote up
def test_allowed_oss_fuzz(self):
    """Test allowing admin in OSS-Fuzz."""
    self.mock.is_oss_fuzz.return_value = True
    self.mock.is_current_user_admin.return_value = True
    self.app = webtest.TestApp(
        webapp2.WSGIApplication([('/', CheckAdminAccessIfOssFuzzHandler)]))

    resp = self.app.post_json('/', {})
    self.assertEqual(200, resp.status_int)