def testLocalhost(self):

    @api_config.api(name='root', hostname='localhost:8080', version='v1',
                    description='This is an API')
    class RootService(remote.Service):
      """Describes RootService."""

      @api_config.method(message_types.VoidMessage, message_types.VoidMessage,
                         path='foo', http_method='GET', name='foo')
      def foo(self, unused_request):
        """Blank endpoint."""
        return message_types.VoidMessage()

    @api_config.api(name='myapi', hostname='localhost:8081', version='v1',
                    description='This is my API')
    class MyService(remote.Service):
      """Describes MyService."""

      @api_config.method(message_types.VoidMessage, message_types.VoidMessage,
                         path='foo', http_method='GET', name='foo')
      def foo(self, unused_request):
        """Blank endpoint."""
        return message_types.VoidMessage()

    api_server = apiserving.api_server([RootService, MyService])
    api_config_response = api_server.get_api_configs()
    if api_config_response:
      api_server.config_manager.process_api_config_response(api_config_response)
    else:
      raise Exception('Could not process API config response')

    configs = []
    for config in api_server.config_manager.configs.itervalues():
      if config != API_CONFIG:
        configs.append(config)

    environ = test_util.create_fake_environ(
        'http', 'localhost', path='/_ah/api/discovery/v1/apis')
    request = api_request.ApiRequest(environ, base_paths=['/_ah/api'])
    generator = directory_list_generator.DirectoryListGenerator(request)

    directory = json.loads(generator.pretty_print_config_to_json(configs))

    try:
      pwd = os.path.dirname(os.path.realpath(__file__))
      test_file = os.path.join(pwd, 'testdata', 'directory_list',
                               'localhost.json')
      with open(test_file) as f:
        expected_directory = json.loads(f.read())
    except IOError as e:
      print 'Could not find expected output file ' + test_file
      raise e

    test_util.AssertDictEqual(expected_directory, directory, self)
  def testLocalhost(self):

    @api_config.api(name='root', hostname='localhost:8080', version='v1',
                    description='This is an API')
    class RootService(remote.Service):
      """Describes RootService."""

      @api_config.method(message_types.VoidMessage, message_types.VoidMessage,
                         path='foo', http_method='GET', name='foo')
      def foo(self, unused_request):
        """Blank endpoint."""
        return message_types.VoidMessage()

    @api_config.api(name='myapi', hostname='localhost:8081', version='v1',
                    description='This is my API')
    class MyService(remote.Service):
      """Describes MyService."""

      @api_config.method(message_types.VoidMessage, message_types.VoidMessage,
                         path='foo', http_method='GET', name='foo')
      def foo(self, unused_request):
        """Blank endpoint."""
        return message_types.VoidMessage()

    api_server = apiserving.api_server([RootService, MyService])
    api_config_response = api_server.get_api_configs()
    if api_config_response:
      api_server.config_manager.process_api_config_response(api_config_response)
    else:
      raise Exception('Could not process API config response')

    configs = []
    for config in api_server.config_manager.configs.itervalues():
      if config != API_CONFIG:
        configs.append(config)

    environ = test_util.create_fake_environ(
        'http', 'localhost', path='/_ah/api/discovery/v1/apis')
    request = api_request.ApiRequest(environ, base_paths=['/_ah/api'])
    generator = directory_list_generator.DirectoryListGenerator(request)

    directory = json.loads(generator.pretty_print_config_to_json(configs))

    try:
      pwd = os.path.dirname(os.path.realpath(__file__))
      test_file = os.path.join(pwd, 'testdata', 'directory_list',
                               'localhost.json')
      with open(test_file) as f:
        expected_directory = json.loads(f.read())
    except IOError as e:
      print 'Could not find expected output file ' + test_file
      raise e

    test_util.AssertDictEqual(expected_directory, directory, self)
Example #3
0
  def testGetApiConfigs(self):
    my_app = apiserving.api_server([TestServiceCustomUrl])

    # 200 with X-Appengine-Peer: apiserving header
    configs = my_app.get_api_configs()
    self.assertEqual(TEST_SERVICE_CUSTOM_URL_API_CONFIG, configs)
Example #4
0
 def setUp(self):
     api = apiserving.api_server([V1Service, V2Service])
     self.app = webtest.TestApp(api)
  def testGetApiConfigs(self):
    my_app = apiserving.api_server([TestServiceCustomUrl])

    # 200 with X-Appengine-Peer: apiserving header
    configs = my_app.get_api_configs()
    self.assertEqual(TEST_SERVICE_CUSTOM_URL_API_CONFIG, configs)