示例#1
0
def setup_test_env():
  """Sets up App Engine/Django test environment."""
  global _INITIALIZED
  if _INITIALIZED:
    raise Exception('Do not call test_env.setup_test_env() twice.')
  _INITIALIZED = True

  # For 'from components import ...' and 'from test_support import ...'.
  sys.path.insert(0, ROOT_DIR)
  sys.path.insert(0, os.path.join(ROOT_DIR, '..', 'third_party_local'))

  from tool_support import gae_sdk_utils
  gae_sdk_utils.setup_gae_env()
  gae_sdk_utils.setup_env(None, 'sample-app', 'v1a', None)
示例#2
0
def setup_test_env():
  """Sets up App Engine/Django test environment."""
  global _INITIALIZED
  if _INITIALIZED:
    raise Exception('Do not call test_env.setup_test_env() twice.')
  _INITIALIZED = True

  # For 'from components import ...' and 'from test_support import ...'.
  sys.path.insert(0, ROOT_DIR)
  sys.path.insert(0, os.path.join(ROOT_DIR, '..', 'third_party_local'))

  from tool_support import gae_sdk_utils
  gae_sdk_utils.setup_gae_env()
  gae_sdk_utils.setup_env(None, 'sample-app', 'v1a', None)
示例#3
0
def setup_test_env(app_id='sample-app'):
    """Sets up App Engine test environment."""
    global _INITIALIZED
    if _INITIALIZED:
        raise Exception('Do not call test_env.setup_test_env() twice.')
    _INITIALIZED = True

    # For depot_tools.
    sys.path.insert(
        0, os.path.join(ROOT_DIR, '..', '..', 'client', 'third_party'))
    # For 'from components import ...' and 'from test_support import ...'.
    sys.path.insert(0, ROOT_DIR)
    sys.path.insert(0, os.path.join(ROOT_DIR, '..', 'third_party_local'))

    from tool_support import gae_sdk_utils
    gae_sdk_utils.setup_gae_env()
    gae_sdk_utils.setup_env(None, app_id, 'v1a', None)

    from components import utils
    utils.fix_protobuf_package()
示例#4
0
    try:
      self.replica.client.login_as_admin('*****@*****.**')
      # Without delegation token seen as a@.
      resp = get_self_id()
      self.assertEqual('user:[email protected]', resp.body['identity'])
      # With delegation token seen as test@.
      resp = get_self_id({'X-Delegation-Token-V1': delegation_token})
      self.assertEqual('user:[email protected]', resp.body['identity'])
      # Attempting to use as b@ doesn't work (wrong audience).
      self.replica.client.login_as_admin('*****@*****.**')
      resp = get_self_id({'X-Delegation-Token-V1': delegation_token})
      self.assertEqual(403, resp.http_code)
      self.assertEqual({
        u'text': u'Bad delegation token: user:[email protected] '
            u'is not allowed to use the token'
        }, resp.body)
    finally:
      # Restore the original state.
      self.replica.client.login_as_admin('*****@*****.**')


if __name__ == '__main__':
  gae_sdk_utils.setup_gae_env()
  if '-v' in sys.argv:
    unittest.TestCase.maxDiff = None
    logging.basicConfig(level=logging.DEBUG)
  else:
    logging.basicConfig(level=logging.FATAL)
  unittest.main()
        return not self._resultForDoCleanups.wasSuccessful()

    def test_smoke(self):
        self.check_who_anonymous()
        self.check_who_authenticated()
        self.check_forbidden()

    def check_who_anonymous(self):
        response = self.app.client.json_request(
            '/_ah/api/testing_service/v1/who')
        self.assertEqual(200, response.http_code)
        self.assertEqual('anonymous:anonymous', response.body.get('identity'))
        self.assertIn(response.body.get('ip'),
                      ('127.0.0.1', '0:0:0:0:0:0:0:1'))

    def check_who_authenticated(self):
        # TODO(vadimsh): Testing this requires interacting with real OAuth2 service
        # to get OAuth2 token. It's doable, but the service account secrets had to
        # be hardcoded into the source code. I'm not sure it's a good idea.
        pass

    def check_forbidden(self):
        response = self.app.client.json_request(
            '/_ah/api/testing_service/v1/forbidden')
        self.assertEqual(403, response.http_code)


if __name__ == '__main__':
    gae_sdk_utils.setup_gae_env()
    unittest.main()