コード例 #1
0
ファイル: basetest.py プロジェクト: shaunstanislauslau/upvote
  def setUp(self, wsgi_app=None, patch_generate_token=True):
    super(UpvoteTestCase, self).setUp()

    # Require index.yaml be observed so tests will fail if indices are absent.
    index_yaml_dir = os.path.join(
        os.path.dirname('.'), 'upvote/gae')
    policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=1)
    self.testbed.init_datastore_v3_stub(
        consistency_policy=policy, require_indexes=True,
        root_path=index_yaml_dir)
    self.testbed.init_memcache_stub()

    if wsgi_app is not None:
      # Workaround for lack of "runtime" variable in test env.
      adapter = lambda r, h: webapp2.Webapp2HandlerAdapter(h)
      wsgi_app.router.set_adapter(adapter)
      handlers.CreateErrorHandlersForApplications([wsgi_app])
      self.testapp = webtest.TestApp(wsgi_app)
    else:
      self.testapp = None

    self.secret_key = 'test-secret'
    xsrf_utils.SiteXsrfSecret.SetInstance(secret=self.secret_key.encode('hex'))

    self._env_patcher = None

    if patch_generate_token:
      self.Patch(xsrfutil, 'generate_token', return_value='token')

    self.PatchEnv(settings.ProdEnv)
コード例 #2
0
ファイル: basetest.py プロジェクト: crudbug/upvote
  def setUp(
      self, wsgi_app=None, patch_generate_token=True,
      patch_send_to_bigquery=True):

    super(UpvoteTestCase, self).setUp()

    # Require index.yaml be observed so tests will fail if indices are absent.
    index_yaml_dir = os.path.join(
        os.path.dirname('.'), 'upvote/gae')
    policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=1)
    self.testbed.init_datastore_v3_stub(
        consistency_policy=policy, require_indexes=True,
        root_path=index_yaml_dir)
    self.testbed.init_memcache_stub()

    if wsgi_app is not None:
      # Workaround for lack of "runtime" variable in test env.
      adapter = lambda r, h: webapp2.Webapp2HandlerAdapter(h)
      wsgi_app.router.set_adapter(adapter)

      # Make note of the routes being registered for easier debugging.
      for route in _ExtractRoutes(wsgi_app):
        logging.info('Registering route %s', route.template)

      handlers.CreateErrorHandlersForApplications([wsgi_app])
      self.testapp = webtest.TestApp(wsgi_app)
    else:
      self.testapp = None

    self.secret_key = 'test-secret'
    xsrf_utils.SiteXsrfSecret.SetInstance(secret=self.secret_key.encode('hex'))

    self._env_patcher = None

    if patch_generate_token:
      self.Patch(xsrfutil, 'generate_token', return_value='token')

    self.PatchEnv(settings.ProdEnv, ENABLE_BIGQUERY_STREAMING=True)

    # Patch out the call that streams to BigQuery so it can be verified in
    # assertBigQueryInsertions() below.
    if patch_send_to_bigquery:
      self.mock_send_to_bigquery = self.Patch(tables, '_SendToBigQuery')
コード例 #3
0
UUID_RE = r'[0-9A-F]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}'

app = webapp2.WSGIApplication([
    # Warmup
    webapp2.Route(r'/_ah/warmup', handlers.AckHandler),
    routes.PathPrefixRoute(
        r'/api/santa',
        [
            # Verifies the module is reachable.
            webapp2.Route(r'/ack', handlers.AckHandler),

            # Santa API. All handlers expect a UUID in the URL
            webapp2.Route(r'/xsrf/<:%s>' % UUID_RE, sync.XsrfHandler),
            webapp2.Route(r'/preflight/<:%s>' % UUID_RE,
                          sync.PreflightHandler),
            webapp2.Route(r'/logupload/<:%s>' % UUID_RE,
                          sync.LogUploadHandler),
            webapp2.Route(r'/eventupload/<:%s>' % UUID_RE,
                          sync.EventUploadHandler),
            webapp2.Route(r'/binaryupload/<:%s>' % UUID_RE,
                          sync.BinaryUploadHandler),
            webapp2.Route(r'/ruledownload/<:%s>' % UUID_RE,
                          sync.RuleDownloadHandler),
            webapp2.Route(r'/postflight/<:%s>' % UUID_RE,
                          sync.PostflightHandler),
        ]),
])

handlers.CreateErrorHandlersForApplications([app])