当前位置: 首页>>代码示例>>Python>>正文


Python TestApp.post_json方法代码示例

本文整理汇总了Python中webtest.TestApp.post_json方法的典型用法代码示例。如果您正苦于以下问题:Python TestApp.post_json方法的具体用法?Python TestApp.post_json怎么用?Python TestApp.post_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webtest.TestApp的用法示例。


在下文中一共展示了TestApp.post_json方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GetCompletions_ClangCompleter_NoCompletionsWhenAutoTriggerOff_test

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import post_json [as 别名]
def GetCompletions_ClangCompleter_NoCompletionsWhenAutoTriggerOff_test():
    ChangeSpecificOptions({"auto_trigger": False})
    app = TestApp(handlers.app)
    app.post_json("/ignore_extra_conf_file", {"filepath": PathToTestFile(".ycm_extra_conf.py")})
    contents = """
struct Foo {
  int x;
  int y;
  char c;
};

int main()
{
  Foo foo;
  foo.
}
"""

    completion_data = BuildRequest(
        filepath="/foo.cpp",
        filetype="cpp",
        contents=contents,
        line_num=11,
        column_num=7,
        compilation_flags=["-x", "c++"],
    )

    results = app.post_json("/completions", completion_data).json["completions"]
    assert_that(results, empty())
开发者ID:nikklassen,项目名称:ycmd,代码行数:31,代码来源:get_completions_test.py

示例2: _RunCompleterCommand_StopServer_CsCompleter_KeepLogFiles

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import post_json [as 别名]
def _RunCompleterCommand_StopServer_CsCompleter_KeepLogFiles( keeping_log_files ):
  ChangeSpecificOptions( { 'server_keep_logfiles': keeping_log_files } )
  app = TestApp( handlers.app )
  app.post_json( '/ignore_extra_conf_file',
                 { 'filepath': PathToTestFile( '.ycm_extra_conf.py' ) } )
  filepath = PathToTestFile( 'testy', 'GotoTestCase.cs' )
  contents = open( filepath ).read()
  event_data = BuildRequest( filepath = filepath,
                             filetype = 'cs',
                             contents = contents,
                             event_name = 'FileReadyToParse' )

  app.post_json( '/event_notification', event_data )
  WaitUntilOmniSharpServerReady( app, filepath )

  event_data = BuildRequest( filetype = 'cs', filepath = filepath )

  debuginfo = app.post_json( '/debug_info', event_data ).json

  log_files_match = re.search( "^OmniSharp logfiles:\n(.*)\n(.*)", debuginfo, re.MULTILINE )
  stdout_logfiles_location = log_files_match.group( 1 )
  stderr_logfiles_location = log_files_match.group( 2 )

  try:
    assert os.path.exists( stdout_logfiles_location ), "Logfile should exist at " + stdout_logfiles_location
    assert os.path.exists( stderr_logfiles_location ), "Logfile should exist at " + stderr_logfiles_location
  finally:
    StopOmniSharpServer( app, filepath )

  if ( keeping_log_files ):
    assert os.path.exists( stdout_logfiles_location ), "Logfile should still exist at " + stdout_logfiles_location
    assert os.path.exists( stderr_logfiles_location ), "Logfile should still exist at " + stderr_logfiles_location
  else:
    assert not os.path.exists( stdout_logfiles_location ), "Logfile should no longer exist at " + stdout_logfiles_location
    assert not os.path.exists( stderr_logfiles_location ), "Logfile should no longer exist at " + stderr_logfiles_location
开发者ID:ballercat,项目名称:ycmd,代码行数:37,代码来源:subcommands_test.py

示例3: RunCompleterCommand_GoToImplementationElseDeclaration_CsCompleter_MultipleImplementations_test

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import post_json [as 别名]
def RunCompleterCommand_GoToImplementationElseDeclaration_CsCompleter_MultipleImplementations_test():
  app = TestApp( handlers.app )
  app.post_json( '/ignore_extra_conf_file',
                 { 'filepath': PathToTestFile( '.ycm_extra_conf.py' ) } )
  filepath = PathToTestFile( 'testy', 'GotoTestCase.cs' )
  contents = open( filepath ).read()
  event_data = BuildRequest( filepath = filepath,
                             filetype = 'cs',
                             contents = contents,
                             event_name = 'FileReadyToParse' )

  app.post_json( '/event_notification', event_data )
  WaitUntilOmniSharpServerReady( app, filepath )

  goto_data = BuildRequest( completer_target = 'filetype_default',
                            command_arguments = ['GoToImplementationElseDeclaration'],
                            line_num = 21,
                            column_num = 13,
                            contents = contents,
                            filetype = 'cs',
                            filepath = filepath )

  eq_( [{
        'filepath': PathToTestFile( 'testy', 'GotoTestCase.cs' ),
        'line_num': 43,
        'column_num': 3
      }, {
        'filepath': PathToTestFile( 'testy', 'GotoTestCase.cs' ),
        'line_num': 48,
        'column_num': 3
      }],
      app.post_json( '/run_completer_command', goto_data ).json )

  StopOmniSharpServer( app, filepath )
开发者ID:ballercat,项目名称:ycmd,代码行数:36,代码来源:subcommands_test.py

示例4: RunCompleterCommand_GoTo_CsCompleter_Works_test

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import post_json [as 别名]
def RunCompleterCommand_GoTo_CsCompleter_Works_test():
  app = TestApp( handlers.app )
  app.post_json( '/ignore_extra_conf_file',
                 { 'filepath': PathToTestFile( '.ycm_extra_conf.py' ) } )
  filepath = PathToTestFile( 'testy/GotoTestCase.cs' )
  contents = open( filepath ).read()
  event_data = BuildRequest( filepath = filepath,
                             filetype = 'cs',
                             contents = contents,
                             event_name = 'FileReadyToParse' )

  app.post_json( '/event_notification', event_data )
  WaitUntilOmniSharpServerReady( app )

  goto_data = BuildRequest( completer_target = 'filetype_default',
                            command_arguments = ['GoTo'],
                            line_num = 9,
                            column_num = 15,
                            contents = contents,
                            filetype = 'cs',
                            filepath = filepath )

  eq_( {
        'filepath': PathToTestFile( 'testy/Program.cs' ),
        'line_num': 7,
        'column_num': 3
      },
      app.post_json( '/run_completer_command', goto_data ).json )

  StopOmniSharpServer( app )
开发者ID:Lekensteyn,项目名称:ycmd,代码行数:32,代码来源:subcommands_test.py

示例5: GetCompletions_CsCompleter_StartsWithUnambiguousMultipleSolutions_test

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import post_json [as 别名]
def GetCompletions_CsCompleter_StartsWithUnambiguousMultipleSolutions_test():
  app = TestApp( handlers.app )
  filepath = PathToTestFile( ('testy-multiple-solutions/'
                              'solution-named-like-folder/'
                              'testy/Program.cs') )
  contents = open( filepath ).read()
  event_data = BuildRequest( filepath = filepath,
                             filetype = 'cs',
                             contents = contents,
                             event_name = 'FileReadyToParse' )

  # Here the server will raise an exception if it can't start
  app.post_json( '/event_notification', event_data )

  # Now for some cleanup: wait for the server to start then shut it down
  while True:
    result = app.post_json( '/run_completer_command',
                            BuildRequest( completer_target = 'filetype_default',
                                          command_arguments = ['ServerRunning'],
                                          filetype = 'cs' ) ).json
    if result:
      break
    time.sleep( 0.2 )

  # We need to turn off the CS server so that it doesn't stick around
  app.post_json( '/run_completer_command',
                 BuildRequest( completer_target = 'filetype_default',
                               command_arguments = ['StopServer'],
                               filetype = 'cs' ) )
开发者ID:nop00,项目名称:YouCompleteMe,代码行数:31,代码来源:get_completions_test.py

示例6: GetCompletions_ClangCompleter_WorksWithExplicitFlags_test

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import post_json [as 别名]
def GetCompletions_ClangCompleter_WorksWithExplicitFlags_test():
  app = TestApp( handlers.app )
  app.post_json( '/ignore_extra_conf_file',
                 { 'filepath': PathToTestFile( '.ycm_extra_conf.py' ) } )
  contents = """
struct Foo {
  int x;
  int y;
  char c;
};

int main()
{
  Foo foo;
  foo.
}
"""

  completion_data = BuildRequest( filepath = '/foo.cpp',
                                  filetype = 'cpp',
                                  contents = contents,
                                  line_num = 11,
                                  column_num = 7,
                                  compilation_flags = ['-x', 'c++'] )

  response_data = app.post_json( '/completions', completion_data ).json
  assert_that( response_data[ 'completions'],
               has_items( CompletionEntryMatcher( 'c' ),
                          CompletionEntryMatcher( 'x' ),
                          CompletionEntryMatcher( 'y' ) ) )
  eq_( 7, response_data[ 'completion_start_column' ] )
开发者ID:Xiol,项目名称:ycmd,代码行数:33,代码来源:get_completions_test.py

示例7: GetCompletions_ClangCompleter_UnknownExtraConfException_test

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import post_json [as 别名]
def GetCompletions_ClangCompleter_UnknownExtraConfException_test():
  app = TestApp( handlers.app )
  filepath = PathToTestFile( 'basic.cpp' )
  completion_data = BuildRequest( filepath = filepath,
                                  filetype = 'cpp',
                                  contents = open( filepath ).read(),
                                  line_num = 11,
                                  column_num = 7,
                                  force_semantic = True )

  response = app.post_json( '/completions',
                            completion_data,
                            expect_errors = True )

  eq_( response.status_code, httplib.INTERNAL_SERVER_ERROR )
  assert_that( response.json,
               has_entry( 'exception',
                          has_entry( 'TYPE', UnknownExtraConf.__name__ ) ) )

  app.post_json( '/ignore_extra_conf_file',
                 { 'filepath': PathToTestFile( '.ycm_extra_conf.py' ) } )

  response = app.post_json( '/completions',
                            completion_data,
                            expect_errors = True )

  eq_( response.status_code, httplib.INTERNAL_SERVER_ERROR )
  assert_that( response.json,
               has_entry( 'exception',
                          has_entry( 'TYPE', NoExtraConfDetected.__name__ ) ) )
开发者ID:Xiol,项目名称:ycmd,代码行数:32,代码来源:get_completions_test.py

示例8: RunCompleterCommand_GoToImplementationElseDeclaration_CsCompleter_NoImplementation_test

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import post_json [as 别名]
def RunCompleterCommand_GoToImplementationElseDeclaration_CsCompleter_NoImplementation_test():
  app = TestApp( handlers.app )
  filepath = PathToTestFile( 'testy/GotoTestCase.cs' )
  contents = open( filepath ).read()
  event_data = BuildRequest( filepath = filepath,
                             filetype = 'cs',
                             contents = contents,
                             event_name = 'FileReadyToParse' )

  app.post_json( '/event_notification', event_data )
  WaitUntilOmniSharpServerReady( app )

  goto_data = BuildRequest( completer_target = 'filetype_default',
                            command_arguments = ['GoToImplementationElseDeclaration'],
                            line_num = 17,
                            column_num = 13,
                            contents = contents,
                            filetype = 'cs',
                            filepath = filepath )

  eq_( {
        'filepath': PathToTestFile( 'testy/GotoTestCase.cs' ),
        'line_num': 35,
        'column_num': 3
      },
      app.post_json( '/run_completer_command', goto_data ).json )

  StopOmniSharpServer( app )
开发者ID:Logicalmars,项目名称:ycmd,代码行数:30,代码来源:subcommands_test.py

示例9: Detalle

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import post_json [as 别名]
class Detalle(TestCase):
    """
    NOTA: Sobre la validación de datos, testar directamente nuestra pequeña clase 
    """

    @classmethod
    def setUpClass(self):

        # Cargamos los datos
        entidad = cargar_datos('usuario')[1]
        self.uid = entidad['uid']
        self.datos = {'corpus': entidad}

        # Trabajamos en obtener un token
        self.token = cargar_credenciales()
        
        # Creamos nuestro objeto para pruebas
        from justine import main
        from webtest import TestApp

        app = main({})
        self.testapp = TestApp(app)

        res = self.testapp.post_json('/usuarios', status=201, params=self.datos, headers=self.token)

    @classmethod
    def tearDownClass(self):
        res = self.testapp.head('/usuarios/' + self.uid, status="*", headers=self.token)
        if res.status_int == 200:
            self.testapp.delete('/usuarios/' + self.uid, status=200, headers=self.token)

    def test_detalle_usuario(self):
        res = self.testapp.get('/usuarios/' + self.uid, status=200, headers=self.token) 
        respuesta = res.json_body['mensaje'][0]['givenName']
        datos = self.datos['corpus']['givenName']
        
        self.assertEqual(respuesta, datos)

    def test_detalle_claves(self):
        claves = ['dn', 'givenName', 'cn']

        res = self.testapp.get('/usuarios/' + self.uid, params={'claves': ','.join(claves)}, headers=self.token)
        respuesta = res.json_body['mensaje'][0].keys()
        self.assertListEqual(respuesta, claves)

    def test_detalle_claves_noexistentes(self):
        claves = ['dn', 'givenName', 'cn', 'noexistente']

        res = self.testapp.get('/usuarios/' + self.uid, params={'claves': ','.join(claves)}, headers=self.token)
        respuesta = res.json_body['mensaje'][0].keys()
        del claves[claves.index('noexistente')]
        
        self.assertListEqual(respuesta, claves)
    
    def test_detalle_noexistente(self):
        uid = 'fitzcarraldo'
        self.testapp.get('/usuarios/' + uid, status=404, headers=self.token)
        
    def test_detalle_unauth(self):
        self.testapp.post_json('/usuarios' + self.uid, status=404)
开发者ID:VTacius,项目名称:justine,代码行数:62,代码来源:testDetalle.py

示例10: GetCompletions_CsCompleter_NonForcedReturnsNoResults_test

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import post_json [as 别名]
def GetCompletions_CsCompleter_NonForcedReturnsNoResults_test():
  app = TestApp( handlers.app )
  app.post_json( '/ignore_extra_conf_file',
                 { 'filepath': PathToTestFile( '.ycm_extra_conf.py' ) } )
  filepath = PathToTestFile( 'testy', 'ContinuousTest.cs' )
  contents = open( filepath ).read()
  event_data = BuildRequest( filepath = filepath,
                             filetype = 'cs',
                             contents = contents,
                             event_name = 'FileReadyToParse' )

  app.post_json( '/event_notification', event_data )
  WaitUntilOmniSharpServerReady( app, filepath )

  completion_data = BuildRequest( filepath = filepath,
                                  filetype = 'cs',
                                  contents = contents,
                                  line_num = 9,
                                  column_num = 21,
                                  force_semantic = False,
                                  query = 'Date' )
  results = app.post_json( '/completions', completion_data ).json

  # there are no semantic completions. However, we fall back to identifier
  # completer in this case.
  assert_that( results, has_entries( {
    'completions' : has_item( has_entries( {
      'insertion_text' : 'String',
      'extra_menu_info': '[ID]',
    } ) ),
    'errors' : empty(),
  } ) )
  StopOmniSharpServer( app, filepath )
开发者ID:Wouterbeets,项目名称:ycmd,代码行数:35,代码来源:get_completions_test.py

示例11: RunCompleterCommand_GoToImplementation_CsCompleter_InvalidLocation_test

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import post_json [as 别名]
def RunCompleterCommand_GoToImplementation_CsCompleter_InvalidLocation_test():
  app = TestApp( handlers.app )
  filepath = PathToTestFile( 'testy/GotoTestCase.cs' )
  contents = open( filepath ).read()
  event_data = BuildRequest( filepath = filepath,
                             filetype = 'cs',
                             contents = contents,
                             event_name = 'FileReadyToParse' )

  app.post_json( '/event_notification', event_data )
  WaitUntilOmniSharpServerReady( app )

  goto_data = BuildRequest( completer_target = 'filetype_default',
                            command_arguments = ['GoToImplementation'],
                            line_num = 2,
                            column_num = 1,
                            contents = contents,
                            filetype = 'cs',
                            filepath = filepath )

  try:
    app.post_json( '/run_completer_command', goto_data ).json
    raise Exception('Expected a "Can\\\'t jump to implementation" error')
  except AppError as e:
    if 'Can\\\'t jump to implementation' in str(e):
      pass
    else:
      raise
  finally:
    StopOmniSharpServer( app )
开发者ID:Logicalmars,项目名称:ycmd,代码行数:32,代码来源:subcommands_test.py

示例12: RunCompleterCommand_GoToImplementationElseDeclaration_CsCompleter_MultipleImplementations_test

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import post_json [as 别名]
def RunCompleterCommand_GoToImplementationElseDeclaration_CsCompleter_MultipleImplementations_test():
    app = TestApp(handlers.app)
    app.post_json("/ignore_extra_conf_file", {"filepath": PathToTestFile(".ycm_extra_conf.py")})
    filepath = PathToTestFile("testy", "GotoTestCase.cs")
    contents = open(filepath).read()
    event_data = BuildRequest(filepath=filepath, filetype="cs", contents=contents, event_name="FileReadyToParse")

    app.post_json("/event_notification", event_data)
    WaitUntilOmniSharpServerReady(app, filepath)

    goto_data = BuildRequest(
        completer_target="filetype_default",
        command_arguments=["GoToImplementationElseDeclaration"],
        line_num=21,
        column_num=13,
        contents=contents,
        filetype="cs",
        filepath=filepath,
    )

    eq_(
        [
            {"filepath": PathToTestFile("testy", "GotoTestCase.cs"), "line_num": 43, "column_num": 3},
            {"filepath": PathToTestFile("testy", "GotoTestCase.cs"), "line_num": 48, "column_num": 3},
        ],
        app.post_json("/run_completer_command", goto_data).json,
    )

    StopOmniSharpServer(app, filepath)
开发者ID:JasonOldWoo,项目名称:ycmd,代码行数:31,代码来源:subcommands_test.py

示例13: GetDetailedDiagnostic_CsCompleter_Works_test

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import post_json [as 别名]
def GetDetailedDiagnostic_CsCompleter_Works_test():
  app = TestApp( handlers.app )
  filepath = PathToTestFile( 'testy/Program.cs' )
  contents = open( filepath ).read()
  event_data = BuildRequest( filepath = filepath,
                             filetype = 'cs',
                             contents = contents,
                             event_name = 'FileReadyToParse' )

  app.post_json( '/event_notification', event_data )
  WaitUntilOmniSharpServerReady( app )
  app.post_json( '/event_notification', event_data )

  diag_data = BuildRequest( filepath = filepath,
                                  filetype = 'cs',
                                  contents = contents,
                                  line_num = 10,
                                  column_num = 2,
                                  start_column = 2 )

  results = app.post_json( '/detailed_diagnostic', diag_data ).json
  assert_that( results,
               has_entry(
                  'message',
                  contains_string(
                     "Unexpected symbol `}'', expecting identifier" ) ) )

  StopOmniSharpServer( app )
开发者ID:fblackburn,项目名称:ycmd,代码行数:30,代码来源:diagnostics_test.py

示例14: GetCompletions_CsCompleter_ReloadSolution_MultipleSolution_Works_test

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import post_json [as 别名]
def GetCompletions_CsCompleter_ReloadSolution_MultipleSolution_Works_test():
  app = TestApp( handlers.app )
  app.post_json( '/ignore_extra_conf_file',
                 { 'filepath': PathToTestFile( '.ycm_extra_conf.py' ) } )
  filepaths = [ PathToTestFile( 'testy/Program.cs' ),
                PathToTestFile( 'testy-multiple-solutions/'
                                'solution-named-like-folder/'
                                'testy/'
                                'Program.cs' ) ]
  for filepath in filepaths:
    contents = open( filepath ).read()
    event_data = BuildRequest( filepath = filepath,
                               filetype = 'cs',
                               contents = contents,
                               event_name = 'FileReadyToParse' )

    app.post_json( '/event_notification', event_data )
    WaitUntilOmniSharpServerReady( app, filepath )
    result = app.post_json( '/run_completer_command',
                            BuildRequest( completer_target = 'filetype_default',
                                          command_arguments = [ 'ReloadSolution' ],
                                          filepath = filepath,
                                          filetype = 'cs' ) ).json

    StopOmniSharpServer( app, filepath )
    eq_( result, True )
开发者ID:Xiol,项目名称:ycmd,代码行数:28,代码来源:get_completions_test.py

示例15: test_good_gotoassignment_do_not_follow_imports

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import post_json [as 别名]
def test_good_gotoassignment_do_not_follow_imports():
    app = TestApp(handlers.app)
    filepath = fixture_filepath('follow_imports', 'importer.py')
    request_data = {
        'source': read_file(filepath),
        'line': 3,
        'col': 9,
        'source_path': filepath
    }
    expected_definition = {
        'module_path': filepath,
        'name': 'imported_function',
        'type': 'function',
        'in_builtin_module': False,
        'line': 1,
        'column': 21,
        'docstring': 'imported_function()\n\n',
        'description': 'def imported_function',
        'full_name': 'imported.imported_function',
        'is_keyword': False
    }

    definitions = app.post_json('/gotoassignment',
                                request_data).json['definitions']

    assert_that(definitions, contains(expected_definition))

    request_data['follow_imports'] = False

    definitions = app.post_json('/gotoassignment',
                                request_data).json['definitions']

    assert_that(definitions, contains(expected_definition))
开发者ID:Jim-tech,项目名称:windows-vim,代码行数:35,代码来源:handlers_test.py


注:本文中的webtest.TestApp.post_json方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。