Skip to content

Commit

Permalink
Merge 0f738de into 89a6afb
Browse files Browse the repository at this point in the history
  • Loading branch information
micbou committed Jun 11, 2016
2 parents 89a6afb + 0f738de commit a62e154
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 69 deletions.
5 changes: 2 additions & 3 deletions ycmd/completers/javascript/tern_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from future import standard_library
standard_library.install_aliases()

import http.client
import logging
import os
import requests
Expand Down Expand Up @@ -269,7 +268,7 @@ def ServerIsReady( self, request_data = {} ):
try:
target = self._GetServerAddress() + '/ping'
response = requests.get( target )
return response.status_code == http.client.OK
return response.status_code == requests.codes.ok
except requests.ConnectionError:
return False

Expand Down Expand Up @@ -321,7 +320,7 @@ def MakeIncompleteFile( name, file_data ):
response = requests.post( self._GetServerAddress(),
json = full_request )

if response.status_code != http.client.OK:
if response.status_code != requests.codes.ok:
raise RuntimeError( response.text )

return response.json()
Expand Down
3 changes: 1 addition & 2 deletions ycmd/completers/rust/rust_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import logging
import urllib.parse
import requests
import http.client
import json
import tempfile
import base64
Expand Down Expand Up @@ -172,7 +171,7 @@ def _GetResponse( self, handler, request_data = None,

response.raise_for_status()

if response.status_code == http.client.NO_CONTENT:
if response.status_code == requests.codes.no_content:
return None

return response.json()
Expand Down
6 changes: 3 additions & 3 deletions ycmd/hmac_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from builtins import * # noqa

import logging
import http.client
import requests
from urllib.parse import urlparse
from base64 import b64decode, b64encode
from bottle import request, abort
Expand Down Expand Up @@ -59,15 +59,15 @@ def __call__( self, callback ):
def wrapper( *args, **kwargs ):
if not HostHeaderCorrect( request ):
self._logger.info( 'Dropping request with bad Host header.' )
abort( http.client.UNAUTHORIZED,
abort( requests.codes.unauthorized,
'Unauthorized, received bad Host header.' )
return

body = ToBytes( request.body.read() )
if not RequestAuthenticated( request.method, request.path, body,
self._hmac_secret ):
self._logger.info( 'Dropping request with bad HMAC.' )
abort( http.client.UNAUTHORIZED, 'Unauthorized, received bad HMAC.' )
abort( requests.codes.unauthorized, 'Unauthorized, received bad HMAC.' )
return
body = callback( *args, **kwargs )
SetHmacHeader( body, self._hmac_secret )
Expand Down
29 changes: 14 additions & 15 deletions ycmd/tests/clang/get_completions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
from builtins import * # noqa

import json

import requests
from nose.tools import eq_
from hamcrest import ( assert_that, contains, contains_inanyorder, empty,
has_item, has_items, has_entry, has_entries,
contains_string )
import http.client

from ycmd.completers.cpp.clang_completer import NO_COMPLETIONS_MESSAGE
from ycmd.responses import UnknownExtraConf, NoExtraConfDetected
Expand All @@ -57,7 +56,7 @@ def RunTest( app, test ):
test is a dictionary containing:
'request': kwargs for BuildRequest
'expect': {
'response': server response code (e.g. httplib.OK)
'response': server response code (e.g. requests.codes.ok)
'data': matcher for the server response json
}
'extra_conf': [ optional list of path items to extra conf file ]
Expand Down Expand Up @@ -119,7 +118,7 @@ def GetCompletions_ForcedWithNoTrigger_test( app ):
'force_semantic': True,
},
'expect': {
'response': http.client.OK,
'response': requests.codes.ok,
'data': has_entries( {
'completions': contains(
CompletionEntryMatcher( 'DO_SOMETHING_TO', 'void' ),
Expand All @@ -145,7 +144,7 @@ def GetCompletions_Fallback_NoSuggestions_test( app ):
'force_semantic': False,
},
'expect': {
'response': http.client.OK,
'response': requests.codes.ok,
'data': has_entries( {
'completions': empty(),
'errors': has_item( NO_COMPLETIONS_ERROR ),
Expand All @@ -170,7 +169,7 @@ def GetCompletions_Fallback_NoSuggestions_MinimumCharaceters_test( app ):
'force_semantic': False,
},
'expect': {
'response': http.client.OK,
'response': requests.codes.ok,
'data': has_entries( {
'completions': empty(),
'errors': has_item( NO_COMPLETIONS_ERROR ),
Expand All @@ -193,7 +192,7 @@ def GetCompletions_Fallback_Suggestions_test( app ):
'force_semantic': False,
},
'expect': {
'response': http.client.OK,
'response': requests.codes.ok,
'data': has_entries( {
'completions': has_item( CompletionEntryMatcher( 'a_parameter',
'[ID]' ) ),
Expand All @@ -218,7 +217,7 @@ def GetCompletions_Fallback_Exception_test( app ):
'force_semantic': False,
},
'expect': {
'response': http.client.OK,
'response': requests.codes.ok,
'data': has_entries( {
'completions': contains(
CompletionEntryMatcher( 'a_parameter', '[ID]' ),
Expand All @@ -244,7 +243,7 @@ def GetCompletions_Forced_NoFallback_test( app ):
'force_semantic': True,
},
'expect': {
'response': http.client.INTERNAL_SERVER_ERROR,
'response': requests.codes.internal_server_error,
'data': NO_COMPLETIONS_ERROR,
},
} )
Expand All @@ -269,7 +268,7 @@ def GetCompletions_FilteredNoResults_Fallback_test( app ):
'force_semantic': False,
},
'expect': {
'response': http.client.OK,
'response': requests.codes.ok,
'data': has_entries( {
'completions': contains_inanyorder(
# do_ is an identifier because it is already in the file when we
Expand Down Expand Up @@ -364,7 +363,7 @@ def GetCompletions_UnknownExtraConfException_test( app ):
completion_data,
expect_errors = True )

eq_( response.status_code, http.client.INTERNAL_SERVER_ERROR )
eq_( response.status_code, requests.codes.internal_server_error )
assert_that( response.json,
has_entry( 'exception',
has_entry( 'TYPE', UnknownExtraConf.__name__ ) ) )
Expand All @@ -377,7 +376,7 @@ def GetCompletions_UnknownExtraConfException_test( app ):
completion_data,
expect_errors = True )

eq_( response.status_code, http.client.INTERNAL_SERVER_ERROR )
eq_( response.status_code, requests.codes.internal_server_error )
assert_that( response.json,
has_entry( 'exception',
has_entry( 'TYPE',
Expand Down Expand Up @@ -423,7 +422,7 @@ def GetCompletions_ExceptionWhenNoFlagsFromExtraConf_test( app ):
response = app.post_json( '/completions',
completion_data,
expect_errors = True )
eq_( response.status_code, http.client.INTERNAL_SERVER_ERROR )
eq_( response.status_code, requests.codes.internal_server_error )

assert_that( response.json,
has_entry( 'exception',
Expand Down Expand Up @@ -522,7 +521,7 @@ def GetCompletions_UnicodeInLine_test( app ):
'extra_conf_data': { '&filetype': 'cpp' },
},
'expect': {
'response': http.client.OK,
'response': requests.codes.ok,
'data': has_entries( {
'completion_start_column': 8,
'completions': contains_inanyorder(
Expand Down Expand Up @@ -554,7 +553,7 @@ def GetCompletions_UnicodeInLineFilter_test( app ):
'extra_conf_data': { '&filetype': 'cpp' },
},
'expect': {
'response': http.client.OK,
'response': requests.codes.ok,
'data': has_entries( {
'completion_start_column': 8,
'completions': contains_inanyorder(
Expand Down
10 changes: 5 additions & 5 deletions ycmd/tests/clang/subcommands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from nose.tools import eq_
from pprint import pprint
from webtest import AppError
import http.client
import requests
import os.path

from ycmd.completers.cpp.clang_completer import NO_DOCUMENTATION_MESSAGE
Expand Down Expand Up @@ -841,7 +841,7 @@ def Subcommands_GetDoc_Undocumented_test( app ):
event_data,
expect_errors = True )

eq_( response.status_code, http.client.INTERNAL_SERVER_ERROR )
eq_( response.status_code, requests.codes.internal_server_error )

assert_that( response.json,
ErrorMatcher( ValueError, NO_DOCUMENTATION_MESSAGE ) )
Expand All @@ -865,7 +865,7 @@ def Subcommands_GetDoc_NoCursor_test( app ):
event_data,
expect_errors = True )

eq_( response.status_code, http.client.INTERNAL_SERVER_ERROR )
eq_( response.status_code, requests.codes.internal_server_error )

assert_that( response.json,
ErrorMatcher( ValueError, NO_DOCUMENTATION_MESSAGE ) )
Expand Down Expand Up @@ -1016,7 +1016,7 @@ def Subcommands_GetDocQuick_Undocumented_test( app ):
event_data,
expect_errors = True )

eq_( response.status_code, http.client.INTERNAL_SERVER_ERROR )
eq_( response.status_code, requests.codes.internal_server_error )

assert_that( response.json,
ErrorMatcher( ValueError, NO_DOCUMENTATION_MESSAGE ) )
Expand Down Expand Up @@ -1049,7 +1049,7 @@ def Subcommands_GetDocQuick_NoCursor_test( app ):
event_data,
expect_errors = True )

eq_( response.status_code, http.client.INTERNAL_SERVER_ERROR )
eq_( response.status_code, requests.codes.internal_server_error )

assert_that( response.json,
ErrorMatcher( ValueError, NO_DOCUMENTATION_MESSAGE ) )
Expand Down
4 changes: 2 additions & 2 deletions ycmd/tests/diagnostics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from hamcrest import assert_that
from mock import patch
from nose.tools import eq_
import http.client
import requests

from ycmd.responses import NoDiagnosticSupport, BuildDisplayMessageResponse
from ycmd.tests import SharedYcmd
Expand All @@ -45,7 +45,7 @@ def Diagnostics_DoesntWork_test( app ):
diag_data,
expect_errors = True )

eq_( response.status_code, http.client.INTERNAL_SERVER_ERROR )
eq_( response.status_code, requests.codes.internal_server_error )
assert_that( response.json, ErrorMatcher( NoDiagnosticSupport ) )


Expand Down
8 changes: 4 additions & 4 deletions ycmd/tests/go/subcommands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from hamcrest import assert_that, has_entries
from nose.tools import eq_
from pprint import pformat
import http.client
import requests

from ycmd.tests.go import PathToTestFile, SharedYcmd
from ycmd.tests.test_utils import BuildRequest, ErrorMatcher
Expand Down Expand Up @@ -85,7 +85,7 @@ def Subcommands_GoTo_Basic( app, goto_command ):
'filepath': PathToTestFile( 'goto.go' ),
},
'expect': {
'response': http.client.OK,
'response': requests.codes.ok,
'data': has_entries( {
'filepath': PathToTestFile( 'goto.go' ),
'line_num': 3,
Expand All @@ -111,7 +111,7 @@ def Subcommands_GoTo_Keyword( app, goto_command ):
'filepath': PathToTestFile( 'goto.go' ),
},
'expect': {
'response': http.client.INTERNAL_SERVER_ERROR,
'response': requests.codes.internal_server_error,
'data': ErrorMatcher( RuntimeError, 'Can\'t find a definition.' )
}
} )
Expand All @@ -133,7 +133,7 @@ def Subcommands_GoTo_WindowsNewlines( app, goto_command ):
'filepath': PathToTestFile( 'win.go' ),
},
'expect': {
'response': http.client.OK,
'response': requests.codes.ok,
'data': has_entries( {
'filepath': PathToTestFile( 'win.go' ),
'line_num': 2,
Expand Down
14 changes: 7 additions & 7 deletions ycmd/tests/javascript/event_notification_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from mock import patch
from nose.tools import eq_
from pprint import pformat
import http.client
import requests
import os

from ycmd.tests.test_utils import BuildRequest, ErrorMatcher
Expand All @@ -47,7 +47,7 @@ def EventNotification_OnFileReadyToParse_ProjectFile_cwd_test( app ):
filetype = 'javascript' ),
expect_errors = True)

eq_( response.status_code, http.client.OK )
eq_( response.status_code, requests.codes.ok )
assert_that( response.json, empty() )


Expand All @@ -63,7 +63,7 @@ def EventNotification_OnFileReadyToParse_ProjectFile_parentdir_test( app ):
filetype = 'javascript' ),
expect_errors = True)

eq_( response.status_code, http.client.OK )
eq_( response.status_code, requests.codes.ok )
assert_that( response.json, empty() )


Expand All @@ -86,7 +86,7 @@ def EventNotification_OnFileReadyToParse_NoProjectFile_test( app, *args ):

print( 'event response: {0}'.format( pformat( response.json ) ) )

eq_( response.status_code, http.client.INTERNAL_SERVER_ERROR )
eq_( response.status_code, requests.codes.internal_server_error )

assert_that(
response.json,
Expand All @@ -110,7 +110,7 @@ def EventNotification_OnFileReadyToParse_NoProjectFile_test( app, *args ):

print( 'event response: {0}'.format( pformat( response.json ) ) )

eq_( response.status_code, http.client.OK )
eq_( response.status_code, requests.codes.ok )
assert_that( response.json, empty() )

# Restart the server and check that it raises it again
Expand All @@ -136,7 +136,7 @@ def EventNotification_OnFileReadyToParse_NoProjectFile_test( app, *args ):

print( 'event response: {0}'.format( pformat( response.json ) ) )

eq_( response.status_code, http.client.INTERNAL_SERVER_ERROR )
eq_( response.status_code, requests.codes.internal_server_error )

assert_that(
response.json,
Expand Down Expand Up @@ -165,4 +165,4 @@ def EventNotification_OnFileReadyToParse_UseGlobalConfig_test( app, *args ):

print( 'event response: {0}'.format( pformat( response.json ) ) )

eq_( response.status_code, http.client.OK )
eq_( response.status_code, requests.codes.ok )
Loading

0 comments on commit a62e154

Please sign in to comment.